Commit d1041cbe authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Refactorisation.

parent 1a057b13
......@@ -39,7 +39,7 @@ class ChainServiceFactory implements FactoryInterface
foreach ($providers as $priority => $name) {
$provider = $serviceLocator->get($name);
$chain->getEventManager()->attach('getIdentityRoles', array($provider, 'getIdentityRoles'), $priority);
$chain->getEventManager()->attach('getIdentityRoles', array($provider, 'getIdentityRolesTrigger'), $priority);
}
return $chain;
......
......@@ -7,7 +7,7 @@ interface ChainableProvider
/**
* Retrieve roles for the current identity
*
* @return string[]|\Zend\Permissions\Acl\Role\RoleInterface[]
* @param ChainEvent $event
*/
public function getIdentityRoles(ChainEvent $e);
public function getIdentityRolesTrigger(ChainEvent $e);
}
\ No newline at end of file
......@@ -17,11 +17,17 @@ use UnicaenAuth\Entity\Db\User;
class Db extends AuthenticationIdentityProvider implements ChainableProvider
{
/**
* Retrieve roles for the current identity
*
* @return string[]|RoleInterface[]
* {@inheritDoc}
*/
public function getIdentityRoles(ChainEvent $event = null)
public function getIdentityRolesTrigger(ChainEvent $event)
{
$event->addRoles($this->getIdentityRoles());
}
/**
* {@inheritDoc}
*/
public function getIdentityRoles()
{
if (! $identity = $this->authService->getIdentity()) {
return array($this->defaultRole);
......@@ -43,10 +49,6 @@ class Db extends AuthenticationIdentityProvider implements ChainableProvider
$roles = array($this->authenticatedRole);
}
if (null !== $event) {
$event->addRoles($roles);
}
return $roles;
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ namespace UnicaenAuth\Provider\Identity;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Permissions\Acl\Role\RoleInterface;
use UnicaenApp\Entity\Ldap\People as BasePeople;
use UnicaenAuth\Entity\Ldap\People;
use BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider;
......@@ -26,17 +25,22 @@ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider,
protected $serviceLocator;
/**
* Retrieve roles for the current identity
*
* @return string[]|RoleInterface[]
* {@inheritDoc}
*/
public function getIdentityRoles(ChainEvent $event = null)
public function getIdentityRolesTrigger(ChainEvent $event)
{
if (! $identity = $this->authService->getIdentity()) {
$event->addRoles($this->getIdentityRoles());
}
/**
* {@inheritDoc}
*/
public function getIdentityRoles()
{
if (!$identity = $this->authService->getIdentity()) {
return array($this->defaultRole);
}
$identity = $this->authService->getIdentity();
if (is_array($identity) && isset($identity['ldap'])) {
$identity = $identity['ldap'];
}
......@@ -44,9 +48,6 @@ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider,
if ($identity instanceof People) {
$roles = $identity->getRoles();
}
elseif ($identity instanceof BasePeople) {
$roles = $identity->getMemberOf();
}
else {
$roles = array();
}
......@@ -63,10 +64,6 @@ class Ldap extends AuthenticationIdentityProvider implements ChainableProvider,
$roles = array($this->authenticatedRole);
}
if (null !== $event) {
$event->addRoles($roles);
}
return $roles;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment