diff --git a/Module.php b/Module.php index 2856efbd10d48e3a51cae28034468f18ba53d6f3..5ef0f95a44d31192d49a53d38b27cd327ac2570e 100644 --- a/Module.php +++ b/Module.php @@ -187,7 +187,12 @@ class Module implements ConfigProviderInterface, ViewHelperProviderInterface, Se // ->setDbStorage($sm->get('UnicaenAuth\Authentication\Storage\Db')); // return $storage; // }, - 'ZfcUser\Authentication\Adapter\AdapterChain' => 'UnicaenAuth\Authentication\Adapter\AdapterChainServiceFactory', +// 'ZfcUser\Authentication\Adapter\AdapterChain' => 'UnicaenAuth\Authentication\Adapter\AdapterChainServiceFactory', + 'UnicaenAuth\Provider\Identity\LdapPeople' => function($sm) { + $authService = $sm->get('zfcuser_auth_service'); + $provider = new \UnicaenAuth\Provider\Identity\LdapPeople($authService); + return $provider; + }, ), ); } diff --git a/config/module.config.php b/config/module.config.php index 7adb67e66331174089066b33ec8510a5d7a2dee4..6417843a7c7e2f690b67c899390f1377280ebd0c 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -54,8 +54,8 @@ $zfcuserSettings = array( 'auth_adapters' => array( // 100 => 'UnicaenAuth\Authentication\Service\StrategyService', 300 => 'UnicaenAuth\Authentication\Adapter\Ldap', // notifié en 1er - 200 => 'UnicaenAuth\Authentication\Adapter\Db', // 2e (si échec d'authentification Ldap) - 100 => 'UnicaenAuth\Authentication\Adapter\Cas', // 3e (si échec d'authentification Db) + 200 => 'UnicaenAuth\Authentication\Adapter\Db', // ensuite (si échec d'authentification Ldap) + 100 => 'UnicaenAuth\Authentication\Adapter\Cas', // ensuite (si échec d'authentification Db) ), ); diff --git a/src/UnicaenAuth/Provider/Identity/LdapPeople.php b/src/UnicaenAuth/Provider/Identity/LdapPeople.php new file mode 100644 index 0000000000000000000000000000000000000000..8115c3a40fb426f12520cfe3f381a430cb812346 --- /dev/null +++ b/src/UnicaenAuth/Provider/Identity/LdapPeople.php @@ -0,0 +1,117 @@ +<?php +namespace UnicaenAuth\Provider\Identity; + +use BjyAuthorize\Exception\InvalidRoleException; +use BjyAuthorize\Provider\Identity\ProviderInterface; +use Zend\Authentication\AuthenticationService; +use Zend\Permissions\Acl\Role\RoleInterface; +use Zend\ServiceManager\ServiceLocatorAwareInterface; +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * Description of LdapGroupProviderInterface + * + * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr> + */ +class LdapPeople implements ProviderInterface, ServiceLocatorAwareInterface +{ + /** + * @var ServiceLocatorAwareInterface + */ + protected $serviceLocator; + + /** + * @var AuthenticationService + */ + protected $authService; + + /** + * @var string|RoleInterface + */ + protected $defaultRole = 'guest'; + + /** + * @param AuthenticationService $authService + */ + public function __construct(AuthenticationService $authService) + { + $this->authService = $authService; + } + + /** + * Retrieve roles for the current identity + * + * @return string[]|RoleInterface[] + */ + public function getIdentityRoles() + { + $roles = array(); + + $identity = $this->authService->getIdentity(); + + if ($identity instanceof \UnicaenApp\Entity\Ldap\People) { + /* @var $identity \UnicaenApp\Entity\Ldap\People */ + $authorizeService = $this->getServiceLocator()->get('BjyAuthorize\Service\Authorize'); + /* @var $authorizeService \BjyAuthorize\Service\Authorize */ + foreach ($identity->getMemberOf() as $group) { + if ($authorizeService->getAcl()->hasRole($group)) { + $roles[] = $group; + } + } + } + + if (!$roles) { + $roles = array($this->getDefaultRole()); + } + +// var_dump($roles); + return $roles; + } + + /** + * Get the rule that's used if you're not authenticated + * + * @return string|RoleInterface + */ + public function getDefaultRole() + { + return $this->defaultRole; + } + + /** + * Set the rule that's used if you're not authenticated + * + * @param $defaultRole + * + * @throws \BjyAuthorize\Exception\InvalidRoleException + */ + public function setDefaultRole($defaultRole) + { + if ( ! ($defaultRole instanceof RoleInterface || is_string($defaultRole))) { + throw InvalidRoleException::invalidRoleInstance($defaultRole); + } + + $this->defaultRole = $defaultRole; + } + + /** + * Set service locator + * + * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator + */ + public function setServiceLocator(ServiceLocatorInterface $serviceLocator) + { + $this->serviceLocator = $serviceLocator; + return $this; + } + + /** + * Get service locator + * + * @return \Zend\ServiceManager\ServiceLocatorInterface + */ + public function getServiceLocator() + { + return $this->serviceLocator; + } +} diff --git a/src/UnicaenAuth/View/Helper/UserCurrent.php b/src/UnicaenAuth/View/Helper/UserCurrent.php index dcbcec9058ef76a032e3589110adb8b8e1278b81..61fde9208d43afc4354827c076e66c07a08fab1a 100644 --- a/src/UnicaenAuth/View/Helper/UserCurrent.php +++ b/src/UnicaenAuth/View/Helper/UserCurrent.php @@ -55,7 +55,7 @@ EOS; $out .= <<<EOS <script type="text/javascript"> $(function() { - $("#$id").popover({ html: true }); + $("#$id").popover({ html: true, container: 'body' }); }); </script> EOS; diff --git a/src/UnicaenAuth/View/Helper/UserInfo.php b/src/UnicaenAuth/View/Helper/UserInfo.php index 7b6130905bae489efebdcd52ebe76388df7a0cf3..b25c44dd8092a20bcabad019d846915e01427e49 100644 --- a/src/UnicaenAuth/View/Helper/UserInfo.php +++ b/src/UnicaenAuth/View/Helper/UserInfo.php @@ -22,18 +22,17 @@ class UserInfo extends UserAbstract /** * @var bool */ - protected $affectationFineSiDispo = false; + protected $affectationPrincipale = false; /** * Point d'entrée. * - * @param boolean $affectationFineSiDispo Indique s'il faut prendre en compte l'affectation - * plus fine (ucbnSousStructure) si elle existe, à la place de l'affectation standard (niveau 2) + * @param boolean $affectationPrincipale Indique s'il ne faut prendre en compte que l'affectation principale * @return UserInfo */ - public function __invoke($affectationFineSiDispo = false) + public function __invoke($affectationPrincipale = false) { - $this->setAffectationFineSiDispo($affectationFineSiDispo); + $this->setAffectationPrincipale($affectationPrincipale); return $this; } @@ -58,9 +57,9 @@ class UserInfo extends UserAbstract if ($authIdentity instanceof People) { // affectations admin - $affectations = $authIdentity->getAffectationsAdmin($this->getAffectationFineSiDispo()); + $affectations = $authIdentity->getAffectationsAdmin($this->getServiceStructure()->getMapper(), $this->getAffectationPrincipale()); if ($affectations) { - $affectations = (array)$this->getServiceStructure()->getMapper()->findChemin(array_keys($affectations)); +// $affectations = (array)$this->getServiceStructure()->getMapper()->findChemin(array_keys($affectations)); if (empty($affectations)) $affectations[] = $this->getView()->translate("Aucune affectation trouvée."); ksort($affectations); @@ -100,7 +99,7 @@ class UserInfo extends UserAbstract // && $authIdentity->getLdapIdentityData() instanceof Unicaen_Model_LdapPeople) { // // // affectations admin -// $affectations = $authIdentity->getLdapIdentityData()->getAffectationsAdmin($this->getAffectationFineSiDispo()); +// $affectations = $authIdentity->getLdapIdentityData()->getAffectationsAdmin($this->getAffectationPrincipale()); // if ($affectations) { // $affectations = (array)$this->getServiceStructure()->findChemin(array_keys($affectations)); // if (empty($affectations)) @@ -163,23 +162,23 @@ class UserInfo extends UserAbstract } /** - * Indique si l'affichage de l'affectation fine éventuelle est activé ou non. + * Indique si l'affichage de l'affectation princiaple seulement est activé ou non. * @return bool */ - public function getAffectationFineSiDispo() + public function getAffectationPrincipale() { - return $this->affectationFineSiDispo; + return $this->affectationPrincipale; } /** - * Active ou non l'affichage de l'affectation fine éventuelle. + * Active ou non l'affichage de l'affectation principale seulement. * - * @param bool $affectationFineSiDispo + * @param bool $affectationPrincipale * @return UserInfo */ - public function setAffectationFineSiDispo($affectationFineSiDispo = true) + public function setAffectationPrincipale($affectationPrincipale = true) { - $this->affectationFineSiDispo = $affectationFineSiDispo; + $this->affectationPrincipale = $affectationPrincipale; return $this; }