Esempio n. 1
0
 public function testUserHasNotRole()
 {
     $this->setExpectedException(UnathorizedException::class);
     $user = new User(array(Role::factory('guest')));
     $auth = new Authorized($user, array(Role::factory('user')));
     $auth();
 }
Esempio n. 2
0
 /**
  * @param array $params
  */
 public function __construct($params)
 {
     $this->roles = array();
     foreach ($params['roles'] as $roleName) {
         $this->roles[] = \GonteroAcl\Factory\Role::factory($roleName);
     }
 }
Esempio n. 3
0
 /**
  * {@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.'));
 }
Esempio n. 4
0
 /**
  * @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;
 }
Esempio n. 5
0
 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;
     }
 }
Esempio n. 6
0
 public function getRoles()
 {
     return array(\GonteroAcl\Factory\Role::factory('guest'));
 }