Exemple #1
0
 public function testDummyAclAdapter()
 {
     $options = array('cache' => array('storage' => '???', 'options' => array('ttl' => 300)));
     $acl = Acl::getInstance('dummy', $options);
     $this->assertNotNull($acl);
     $this->assertTrue($acl->isAllowed(array('test' => 'test')));
 }
Exemple #2
0
 /**
  * @param null|AdapterOptions $adapterName
  * @param array $options
  * @throws Exception\RuntimeException
  * @return Acl
  */
 public static function getInstance($adapterName = null, $options = array())
 {
     if (static::$instance === null) {
         static::$logger = Logger::getLogger(__CLASS__);
         if ($adapterName instanceof AdapterInterface) {
             $adapter = $adapterName;
         } else {
             $adapter = static::getAdapterManager()->get($adapterName);
         }
         if ($options) {
             $adapter->setOptions($options);
         }
         static::$instance = new self($adapter);
     } elseif ($adapterName !== null && static::$instance->getOptions()->getThrowRuntimeExceptions()) {
         static::$logger->error("Acl cannot be initialized twice.");
         throw new RuntimeException("Acl cannot be initialized twice.");
     }
     return static::$instance;
 }
Exemple #3
0
 /**
  * @param $controller
  * @param $action
  * @return bool
  * @throws \Acl\AclException
  */
 public function auth($controller, $action)
 {
     $acl = new Acl();
     $user = new User();
     if ($this->session->token) {
         $user_id = A::find(['token' => $this->session->token])[0]->user_id;
         if (!$user_id) {
             $this->reset();
             $user->role_id = 3;
         } else {
             $user = User::find(['id' => $user_id])[0];
         }
     } else {
         $user->role_id = 3;
     }
     $role = Role::find(['id' => $user->role_id])[0]->name;
     if ($acl->isAllowed($role, $controller, $action)) {
         return true;
     } else {
         return false;
     }
 }
Exemple #4
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $serviceLocator
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $options = $serviceLocator->get('Configuration');
     $options = $options['dao-acl'];
     $adapter = $options['adapter'];
     $options = $options['options'];
     if ($adapter === 'doctrine') {
         if (is_string($options['entity_manager'])) {
             $options['entity_manager'] = $serviceLocator->get($options['entity_manager']);
         }
     }
     try {
         $acl = \Acl\Acl::getInstance($adapter, $options);
         return $acl;
     } catch (RuntimeException $re) {
         $acl = \Acl\Acl::getInstance();
         return $acl;
     }
 }
Exemple #5
0
 /**
  * Check if role can access to this resource
  * @param Acl\Role $role The role to check
  * @return boolean Allow or deny
  */
 public function isAllowed(Role $role)
 {
     $acl = Acl::getInstance();
     return $acl->isAllowed($role, $this);
 }
Exemple #6
0
 /**
  * Check if this role can access to the resource
  * @param Acl\Resource|string $resource The resource or his name
  * @return boolean Allow or deny
  */
 public function isAllowed($resource)
 {
     $acl = Acl::getInstance();
     return $acl->isAllowed($this, $resource);
 }
Exemple #7
0
 public function testConfig()
 {
     $acl = new Acl($this->config);
     var_dump($acl->getResources());
     $acl->getRoles();
 }