public function testUserHasNotRole() { $this->setExpectedException(UnathorizedException::class); $user = new User(array(Role::factory('guest'))); $auth = new Authorized($user, array(Role::factory('user'))); $auth(); }
/** * @param array $params */ public function __construct($params) { $this->roles = array(); foreach ($params['roles'] as $roleName) { $this->roles[] = \GonteroAcl\Factory\Role::factory($roleName); } }
/** * {@inheritdoc} */ public function authenticate() { if ($this->getIdentity() == 1) { return new AuthenticationResult(AuthenticationResult::SUCCESS, new \GonteroAclTest\Entity\User(array(Role::factory('admin'))), array('Authentication successful.')); } if ($this->getIdentity() == 2) { return new AuthenticationResult(AuthenticationResult::SUCCESS, new \GonteroAclTest\Entity\User(array(Role::factory('user'))), array('Authentication successful.')); } return new AuthenticationResult(AuthenticationResult::FAILURE_IDENTITY_NOT_FOUND, null, array('Authentication failure.')); }
/** * @return array */ public function getRoles() { $roles = array(RoleFactory::factory('guest')); if ($this->getAnnotations() instanceof AnnotationCollection) { foreach ($this->getAnnotations() as $annotation) { if ($annotation instanceof Role) { $roles = $annotation->getRoles(); } } } return $roles; }
public function __construct(AclUser $user = null, $roles = array()) { if (!$user) { $this->user = new NoUser(); } else { $this->user = $user; } if (empty($roles)) { $this->roles = [Role::factory('guest')]; } else { $this->roles = $roles; } }
public function getRoles() { return array(\GonteroAcl\Factory\Role::factory('guest')); }