Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Nov 19, 2019
1 parent 2def355 commit 0c5b492
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 76 deletions.
107 changes: 79 additions & 28 deletions src/Security/Core/User/EuloginUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,33 @@ public function __construct(array $data)
/**
* {@inheritdoc}
*/
public function get(string $key, $default = null)
public function eraseCredentials(): void
{
return $this->user->get($key, $default);
// null
}

/**
* {@inheritdoc}
*/
public function getAttribute(string $key, $default = null)
public function get(string $key, $default = null)
{
return $this->user->getAttribute($key, $default);
return $this->user->get($key, $default);
}

/**
* {@inheritdoc}
*/
public function eraseCredentials(): void
public function getAssuranceLevel(): ?string
{
// null
return $this->user->getAttribute('assuranceLevel');
}

public function getAssuranceLevel()
/**
* {@inheritdoc}
*/
public function getAttribute(string $key, $default = null)
{
return $this->user->getAttribute('assuranceLevel');
return $this->user->getAttribute($key, $default);
}

/**
Expand All @@ -63,62 +66,92 @@ public function getAttributes(): array
return $this->user->getAttributes();
}

public function getDepartmentNumber()
/**
* {@inheritdoc}
*/
public function getDepartmentNumber(): ?string
{
return $this->user->getAttribute('departmentNumber');
}

public function getDomain()
/**
* {@inheritdoc}
*/
public function getDomain(): ?string
{
return $this->user->getAttribute('domain');
}

public function getDomainUsername()
/**
* {@inheritdoc}
*/
public function getDomainUsername(): ?string
{
return $this->user->getAttribute('domainUsername');
}

public function getEmail()
public function getEmail(): ?string
{
return $this->user->getAttribute('email');
}

public function getEmployeeNumber()
/**
* {@inheritdoc}
*/
public function getEmployeeNumber(): ?string
{
return $this->user->getAttribute('employeeNumber');
}

public function getEmployeeType()
/**
* {@inheritdoc}
*/
public function getEmployeeType(): ?string
{
return $this->user->getAttribute('employeeType');
}

public function getFirstName()
public function getFirstName(): ?string
{
return $this->user->getAttribute('firstName');
}

public function getGroups()
/**
* {@inheritdoc}
*/
public function getGroups(): array
{
return $this->user->getAttribute('groups');
return $this->user->getAttribute('groups', []);
}

public function getLastName()
/**
* {@inheritdoc}
*/
public function getLastName(): ?string
{
return $this->user->getAttribute('lastName');
}

public function getLocale()
/**
* {@inheritdoc}
*/
public function getLocale(): ?string
{
return $this->user->getAttribute('locale');
}

public function getLoginDate()
/**
* {@inheritdoc}
*/
public function getLoginDate(): ?string
{
return $this->user->getAttribute('loginDate');
}

public function getOrgId()
/**
* {@inheritdoc}
*/
public function getOrgId(): ?string
{
return $this->user->getAttribute('orgId');
}
Expand Down Expand Up @@ -161,32 +194,50 @@ public function getSalt()
{
}

public function getSso()
/**
* {@inheritdoc}
*/
public function getSso(): ?string
{
return $this->user->getAttribute('sso');
}

public function getStrengths()
/**
* {@inheritdoc}
*/
public function getStrengths(): array
{
return $this->user->getAttribute('strengths');
return $this->user->getAttribute('strengths', []);
}

public function getTelephoneNumber()
/**
* {@inheritdoc}
*/
public function getTelephoneNumber(): ?string
{
return $this->user->getAttribute('telephoneNumber');
}

public function getTeleworkingPriority()
/**
* {@inheritdoc}
*/
public function getTeleworkingPriority(): ?string
{
return $this->user->getAttribute('teleworkingPriority');
}

public function getTicketType()
/**
* {@inheritdoc}
*/
public function getTicketType(): ?string
{
return $this->user->getAttribute('ticketType');
}

public function getUid()
/**
* {@inheritdoc}
*/
public function getUid(): ?string
{
return $this->user->getAttribute('uid');
}
Expand Down
140 changes: 97 additions & 43 deletions src/Security/Core/User/EuloginUserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,103 @@

use drupol\CasBundle\Security\Core\User\CasUserInterface;

/**
* Interface EuloginUserInterface.
*/
interface EuloginUserInterface extends CasUserInterface
{
public function getAssuranceLevel();

public function getAttributes(): array;

public function getDepartmentNumber();

public function getDomain();

public function getDomainUsername();

public function getEmail();

public function getEmployeeNumber();

public function getEmployeeType();

public function getFirstName();

public function getGroups();

public function getLastName();

public function getLocale();

public function getLoginDate();

public function getOrgId();

public function getPgt(): ?string;

public function getSso();

public function getStrengths();

public function getTelephoneNumber();

public function getTeleworkingPriority();

public function getTicketType();

public function getUid();

public function getUser(): string;
/**
* @return string|null
*/
public function getAssuranceLevel(): ?string;

/**
* @return string|null
*/
public function getDepartmentNumber(): ?string;

/**
* @return string|null
*/
public function getDomain(): ?string;

/**
* @return string|null
*/
public function getDomainUsername(): ?string;

/**
* @return string|null
*/
public function getEmail(): ?string;

/**
* @return string|null
*/
public function getEmployeeNumber(): ?string;

/**
* @return string|null
*/
public function getEmployeeType(): ?string;

/**
* @return string|null
*/
public function getFirstName(): ?string;

/**
* @return array
*/
public function getGroups(): array;

/**
* @return string|null
*/
public function getLastName(): ?string;

/**
* @return string|null
*/
public function getLocale(): ?string;

/**
* @return string|null
*/
public function getLoginDate(): ?string;

/**
* @return string|null
*/
public function getOrgId(): ?string;

/**
* @return string|null
*/
public function getSso(): ?string;

/**
* @return array
*/
public function getStrengths(): array;

/**
* @return string|null
*/
public function getTelephoneNumber(): ?string;

/**
* @return string|null
*/
public function getTeleworkingPriority(): ?string;

/**
* @return string|null
*/
public function getTicketType(): ?string;

/**
* @return string|null
*/
public function getUid(): ?string;
}
12 changes: 7 additions & 5 deletions src/Security/Core/User/EuloginUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
namespace drupol\EuloginBundle\Security\Core\User;

use drupol\CasBundle\Security\Core\User\CasUserInterface;
use drupol\psrcas\Introspection\Introspector;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\UserInterface;

use function get_class;

/**
* Class EuloginUserProvider.
*/
class EuloginUserProvider implements EuloginUserProviderInterface
{
/**
* {@inheritdoc}
*/
public function loadUserByResponse(ResponseInterface $response): CasUserInterface
{
if (false === $user = json_decode((string) $response->getBody(), true)) {
throw new AuthenticationException('Unable to load user from response.');
}
/** @var \drupol\psrcas\Introspection\Contract\ServiceValidate $introspect */
$introspect = Introspector::detect($response);

return new EuloginUser($user['serviceResponse']['authenticationSuccess']);
return new EuloginUser($introspect->getParsedResponse()['serviceResponse']['authenticationSuccess']);
}

/**
Expand Down

0 comments on commit 0c5b492

Please sign in to comment.