diff --git a/src/UnicaenAuth/Authentication/Adapter/Cas.php b/src/UnicaenAuth/Authentication/Adapter/Cas.php index 98d563a6ba7bcdd5dc4055d40e1021118ac46526..4813525080c3c366ff4d66ddd134b7db99cddc78 100644 --- a/src/UnicaenAuth/Authentication/Adapter/Cas.php +++ b/src/UnicaenAuth/Authentication/Adapter/Cas.php @@ -1,9 +1,11 @@ <?php + namespace UnicaenAuth\Authentication\Adapter; use phpCAS; -use UnicaenApp\Exception; +use UnicaenApp\Mapper\Ldap\People as LdapPeopleMapper; use UnicaenAuth\Options\ModuleOptions; +use UnicaenAuth\Service\User; use Zend\Authentication\Exception\UnexpectedValueException; use Zend\Authentication\Result as AuthenticationResult; use Zend\EventManager\EventManager; @@ -48,6 +50,11 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event */ protected $casClient; + /** + * @var LdapPeopleMapper + */ + protected $ldapPeopleMapper; + /** * Réalise l'authentification. * @@ -94,7 +101,12 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event $e->setCode(AuthenticationResult::SUCCESS) ->setMessages(['Authentication successful.']); - $this->getEventManager()->trigger('userAuthenticated', $e); + // recherche de l'individu dans l'annuaire LDAP (il existe forcément puisque l'auth CAS a réussi) + $ldapPeople = $this->getLdapPeopleMapper()->findOneByUsername($identity); + + /* @var $userService User */ + $userService = $this->getServiceManager()->get('unicaen-auth_user_service'); + $userService->userAuthenticated($ldapPeople); } /** @@ -188,6 +200,31 @@ class Cas extends AbstractAdapter implements ServiceManagerAwareInterface, Event return $this->options; } + /** + * get ldap people mapper + * + * @return LdapPeopleMapper + */ + public function getLdapPeopleMapper() + { + if (null === $this->ldapPeopleMapper) { + $this->ldapPeopleMapper = $this->getServiceManager()->get('ldap_people_mapper'); + } + return $this->ldapPeopleMapper; + } + + /** + * set ldap people mapper + * + * @param LdapPeopleMapper $mapper + * @return self + */ + public function setLdapPeopleMapper(LdapPeopleMapper $mapper) + { + $this->ldapPeopleMapper = $mapper; + return $this; + } + /** * Get service manager *