Example #1
0
 public function testRole()
 {
     $role = new Role();
     $this->assertEmpty($role->getId());
     $this->assertEmpty($role->getRole());
     $role->setRole('foo');
     $this->assertStringStartsWith('ROLE_FOO', $role->getRole());
     $this->assertEquals(Role::PREFIX_ROLE, $role->getPrefix());
 }
Example #2
0
 /**
  * Test prePersist role that to generate new value of "role" field
  */
 public function testPrePersistValid()
 {
     $role = new Role();
     $this->assertEmpty($role->getId());
     $this->assertEmpty($role->getRole());
     $this->listener->prePersist($this->getPrePersistEvent($role));
     $this->assertNotEmpty($role->getRole());
 }
 /**
  * Load the ACL per role
  *
  * @param Role $role
  */
 protected function loadAcls(Role $role)
 {
     if (User::ROLE_ANONYMOUS === $role->getRole()) {
         return;
     }
     $sid = $this->aclManager->getSid($role);
     foreach ($this->aclManager->getAllExtensions() as $extension) {
         $rootOid = $this->aclManager->getRootOid($extension->getExtensionKey());
         foreach ($extension->getAllMaskBuilders() as $maskBuilder) {
             $fullAccessMask = $maskBuilder->hasConst('GROUP_SYSTEM') ? $maskBuilder->getConst('GROUP_SYSTEM') : $maskBuilder->getConst('GROUP_ALL');
             $this->aclManager->setPermission($sid, $rootOid, $fullAccessMask, true);
         }
     }
 }
Example #4
0
 /**
  * Never use this to check if this user has access to anything!
  * Use the SecurityContext, or an implementation of AccessDecisionManager
  * instead, e.g.
  *
  *         $securityContext->isGranted('ROLE_USER');
  *
  * @param  Role|string $role
  *
  * @return boolean
  * @throws \InvalidArgumentException
  */
 public function hasRole($role)
 {
     if ($role instanceof Role) {
         $roleName = $role->getRole();
     } elseif (is_string($role)) {
         $roleName = $role;
     } else {
         throw new \InvalidArgumentException('$role must be an instance of Oro\\Bundle\\UserBundle\\Entity\\Role or a string');
     }
     return (bool) $this->getRole($roleName);
 }
 /**
  * {@inheritDoc}
  */
 public function getRole()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getRole', array());
     return parent::getRole();
 }