diff --git a/src/UnicaenAuthentification/Entity/Ldap/People.php b/src/UnicaenAuthentification/Entity/Ldap/People.php index 4f07eac29d2d1bd663945c9cbaa5eb60da419011..cfc8e73928b572e32942af3bcba58e96fd6215b0 100644 --- a/src/UnicaenAuthentification/Entity/Ldap/People.php +++ b/src/UnicaenAuthentification/Entity/Ldap/People.php @@ -63,8 +63,10 @@ class People extends BasePeople implements UserInterface, ProviderInterface /** * {@inheritDoc} */ - public function getUsername() + public function getUsername(?string $attribut = "supannAliasLogin") { + if ($attribut === 'supannAliasLogin') return $this->supannaliaslogin; + if ($attribut === 'uid') return $this->uid; return $this->supannaliaslogin; } diff --git a/src/UnicaenAuthentification/Provider/Identity/Ldap.php b/src/UnicaenAuthentification/Provider/Identity/Ldap.php index bdbd3122db0ae74d187f8581b7c999c7ff1fc2a9..51e8e382af6147509b4ad27bce800e020933d019 100644 --- a/src/UnicaenAuthentification/Provider/Identity/Ldap.php +++ b/src/UnicaenAuthentification/Provider/Identity/Ldap.php @@ -18,6 +18,12 @@ use ZfcUser\Entity\UserInterface; */ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider { + protected $usernamefield; + + public function setUsernamefield(?string $value = null) + { + $this->usernamefield=$value; + } /** * {@inheritDoc} */ @@ -50,7 +56,7 @@ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider } if ($identity instanceof UserInterface) { - $roles[] = $identity->getUsername(); + $roles[] = $identity->getUsername($this->usernamefield); } return $roles; diff --git a/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php b/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php index f387f55aee801312e3c7b5177d140e209f9ce337..a5defb14a59363da74aaf0b5409daec3a9bd5eaa 100644 --- a/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php +++ b/src/UnicaenAuthentification/Provider/Identity/LdapServiceFactory.php @@ -30,6 +30,8 @@ class LdapServiceFactory implements FactoryInterface $simpleIdentityProvider->setDefaultRole($config['default_role']); $simpleIdentityProvider->setAuthenticatedRole($config['authenticated_role']); + $usernamefield = $config['unicaen-auth']['local']['ldap']['username']; + $simpleIdentityProvider->setUsernamefield($usernamefield); return $simpleIdentityProvider; } diff --git a/src/UnicaenAuthentification/Service/UserContext.php b/src/UnicaenAuthentification/Service/UserContext.php index cc7e05fdbebaf1910ca29a05bcd070d736704e29..59dce654422805e83c0eb302c8525004a5fc73ae 100644 --- a/src/UnicaenAuthentification/Service/UserContext.php +++ b/src/UnicaenAuthentification/Service/UserContext.php @@ -44,6 +44,12 @@ class UserContext extends AbstractService implements EventManagerAwareInterface */ protected $identityRoles; + private $usernamefield; + + public function setUsernamefield(?string $value = null) + { + $this->usernamefield = $value; + } /** * @var AuthenticationService */ @@ -132,7 +138,7 @@ class UserContext extends AbstractService implements EventManagerAwareInterface return $user->getUsername(); } if ($user = $this->getLdapUser()) { - return $user->getUsername(); + return $user->getUsername($this->usenamefield); } if ($user = $this->getDbUser()) { return $user->getUsername(); diff --git a/src/UnicaenAuthentification/Service/UserContextFactory.php b/src/UnicaenAuthentification/Service/UserContextFactory.php index 5f3427cff7c77aa07414098ca57d49e322c1e118..5f857a17b4f11778cb2b9f69cb125c73a33c263f 100644 --- a/src/UnicaenAuthentification/Service/UserContextFactory.php +++ b/src/UnicaenAuthentification/Service/UserContextFactory.php @@ -32,7 +32,8 @@ class UserContextFactory // mais c'est impossible pour l'instant car il y a un cycle dans les dépendances entre services qui // provoque une boucle infinie. // - + $usernamefield = $config['unicaen-auth']['local']['ldap']['username']; + $service->setUsernamefield($usernamefield); return $service; } } \ No newline at end of file