當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Acl\Acl類代碼示例

本文整理匯總了PHP中Zend\Permissions\Acl\Acl的典型用法代碼示例。如果您正苦於以下問題:PHP Acl類的具體用法?PHP Acl怎麽用?PHP Acl使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Acl類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _checkAcl

 /**
  * Checks if the current user has the priviledge to do something.
  *
  * @param string $priviledge
  * @return AccessProhibitedException
  **/
 protected function _checkAcl($priviledge)
 {
     $service = new UserService($this->_em);
     if (!$this->_acl->isAllowed($service->getCurrentRole(), $this, $priviledge)) {
         throw new AccessProhibitedException('Access is prohibited.');
     }
 }
開發者ID:rkeplin,項目名稱:zf2-d2-blog,代碼行數:13,代碼來源:AclController.php

示例2: roleAcl

 /**
  * @return Acl
  */
 protected function roleAcl()
 {
     if (!$this->roleAcl) {
         $id = $this->objId();
         $this->roleAcl = new Acl();
         $this->roleAcl->addRole(new Role($id));
         $this->roleAcl->addResource(new Resource('admin'));
         $q = '
         select
             `denied`,
             `allowed`,
             `superuser`
         from
             `charcoal_admin_acl_roles`
         where
             ident = :id';
         $db = \Charcoal\App\App::instance()->getContainer()->get('database');
         $sth = $db->prepare($q);
         $sth->bindParam(':id', $id);
         $sth->execute();
         $permissions = $sth->fetch(\PDO::FETCH_ASSOC);
         $this->roleAllowed = explode(',', trim($permissions['allowed']));
         $this->roleDenied = explode(',', trim($permissions['denied']));
         foreach ($this->roleAllowed as $allowed) {
             $this->roleAcl->allow($id, 'admin', $allowed);
         }
         foreach ($this->roleDenied as $denied) {
             $this->roleAcl->deny($id, 'admin', $denied);
         }
     }
     return $this->roleAcl;
 }
開發者ID:locomotivemtl,項目名稱:charcoal-admin,代碼行數:35,代碼來源:AclPermissions.php

示例3: addAllowAndDeny

 private function addAllowAndDeny(Acl $acl)
 {
     foreach ($this->config as $roleName => $roleConfig) {
         $allowList = isset($roleConfig['allow']) ? $roleConfig['allow'] : [];
         foreach ($allowList as $resource => $privilegeList) {
             if (empty($privilegeList)) {
                 $acl->allow($roleName, strtolower($resource));
             } else {
                 foreach ((array) $privilegeList as $privilege) {
                     $acl->allow($roleName, strtolower($resource), strtolower($privilege));
                 }
             }
         }
         $denyList = isset($roleConfig['deny']) ? $roleConfig['deny'] : [];
         foreach ($denyList as $resource => $privilegeList) {
             if (empty($privilegeList)) {
                 $acl->deny($roleName, strtolower($resource));
             } else {
                 foreach ((array) $privilegeList as $privilege) {
                     $acl->deny($roleName, strtolower($resource), strtolower($privilege));
                 }
             }
         }
     }
 }
開發者ID:omusico,項目名稱:zf2-demo,代碼行數:25,代碼來源:AclFactory.php

示例4: autenticaAction

 /**
  * autentica o usuário
  */
 public function autenticaAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->adapter->setOptions(array('object_manager' => Conn::getConn(), 'identity_class' => 'MyClasses\\Entities\\AclUsuario', 'identity_property' => 'login', 'credential_property' => 'senha'));
         $this->adapter->setIdentityValue($this->getRequest()->getPost('login'));
         $this->adapter->setCredentialValue(sha1($this->getRequest()->getPost('senha')));
         $result = $this->auth->authenticate($this->adapter);
         if ($result->isValid()) {
             $equipes = $result->getIdentity()->getEquipes();
             $acl = new Acl();
             $acl->addRole(new Role($equipes[0]->getPerfil()));
             $recursos = $equipes[0]->getRecursos();
             foreach ($recursos as $recurso) {
                 if (!$acl->hasResource($recurso->getRecurso())) {
                     /* echo "add recurso: ".
                        $perfil->getPerfil().", ".
                        $recurso->getRecurso()->getRecurso().", ".
                        $recurso->getPermissao(); */
                     $acl->addResource(new Resource($recurso->getRecurso()));
                     $acl->allow($equipes[0]->getPerfil(), $recurso->getRecurso());
                 }
             }
             $this->auth->getStorage()->write(array($result->getIdentity(), $equipes[0]->getPerfil(), $acl));
             $this->layout()->id = $result->getIdentity()->getId();
             $this->layout()->nome = $result->getIdentity()->getNome();
             return new ViewModel(array('nome' => $result->getIdentity()->getNome()));
         } else {
             return new ViewModel(array('erro' => array_pop($result->getMessages())));
         }
     }
 }
開發者ID:Jorgeley,項目名稱:Real-State,代碼行數:34,代碼來源:IndexController.php

示例5: __invoke

 public function __invoke($serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $this->acl = $serviceLocator->get('MultiRoleAclBase\\Service\\MultiRolesAcl');
     if (get_class($this->acl) == 'MultiRoleAclBase\\Service\\MultiRolesAcl' || is_subclass_of($this->acl, 'MultiRoleAclBase\\Service\\MultiRolesAcl')) {
         $this->acl->setAllowAccessWhenResourceUnknown(false);
     }
     $this->roleBuilder = $serviceLocator->get('MultiRoleAclBase\\Acl\\Builder\\RoleBuilder');
     $this->resourceBuilder = $serviceLocator->get('MultiRoleAclBase\\Acl\\Builder\\ResourceBuilder');
     $this->ruleBuilder = $serviceLocator->get('MultiRoleAclBase\\Acl\\Builder\\RuleBuilder');
     // Get all Roles from RoleBuilder
     $roles = $this->roleBuilder->buildRoles($this->acl, $serviceLocator);
     if (is_array($roles)) {
         foreach ($roles as $role) {
             $this->acl->addRole($role);
         }
     }
     // Get all Resources from ResourceBuilder
     $resources = $this->resourceBuilder->buildResources($this->acl, $serviceLocator);
     if (is_array($resources)) {
         foreach ($resources as $resource) {
             $this->acl->addResource($resource);
         }
     }
     // Build all the rules
     $this->ruleBuilder->buildRules($this->acl, $serviceLocator);
     return $this->acl;
 }
開發者ID:stevenbuehner,項目名稱:multi-role-acl-base,代碼行數:28,代碼來源:AclServiceFactory.php

示例6: assert

 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     if (!$resource instanceof User) {
         return false;
     }
     return $acl->isAdminRole($resource->getRole());
 }
開發者ID:patrova,項目名稱:omeka-s,代碼行數:7,代碼來源:UserIsAdminAssertion.php

示例7: isAllowed

 /**
  * Check the acl
  *
  * @param string $resource
  * @param string $privilege
  * @return boolean
  */
 public function isAllowed($resource = null, $privilege = null)
 {
     if (null === $this->acl) {
         $this->getAcl();
     }
     return $this->acl->isAllowed($this->getIdentity()->getRoleId(), $resource, $privilege);
 }
開發者ID:butkimtinh,項目名稱:uthando-user,代碼行數:14,代碼來源:IsAllowed.php

示例8: addAclResource

 /**
  * @param Acl $acl
  * @param $resource
  */
 protected function addAclResource(ZendAcl $acl, AclResource $resource)
 {
     if (!$acl->hasResource($resource->getResource())) {
         $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource->getResource()));
     }
     return $this;
 }
開發者ID:fousheezy,項目名稱:auth,代碼行數:11,代碼來源:Acl.php

示例9: getAcl

 /**
  * Set and get Zend\Permissions\Acl\Acl
  *
  * @see \Contentinum\Service\AclAwareInterface::getAcl()
  * @return Zend\Permissions\Acl\Acl
  */
 public function getAcl($settings)
 {
     if (null === $this->acl) {
         $acl = new Acl();
         // start to set first roles ...
         foreach ($settings['roles'] as $role) {
             $parents = null;
             if (isset($settings['parent'][$role])) {
                 $parents = array($settings['parent'][$role]);
             }
             $acl->addRole($role, $parents);
         }
         $role = null;
         // ... then resoures ...
         foreach ($settings['resources'] as $resource) {
             $acl->addResource($resource);
         }
         // ... and now the rules
         foreach ($settings['rules'] as $access => $rule) {
             foreach ($rule as $role => $restrictions) {
                 foreach ($restrictions as $resource => $restriction) {
                     if ('all' == $restriction) {
                         $acl->{$access}($role, $resource);
                     } else {
                         $acl->{$access}($role, $resource, $restriction);
                     }
                 }
             }
         }
         $this->setAcl($acl);
     }
     return $this->acl;
 }
開發者ID:jochum-mediaservices,項目名稱:contentinum5.5,代碼行數:39,代碼來源:AclServiceFactory.php

示例10: createService

 /**
  * Create the service using the configuration from the modules config-file
  *
  * @param ServiceLocator $services The ServiceLocator
  *
  * @see \Zend\ServiceManager\FactoryInterface::createService()
  * @return Hybrid_Auth
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('config');
     $config = $config['acl'];
     if (!isset($config['roles']) || !isset($config['resources'])) {
         throw new \Exception('Invalid ACL Config found');
     }
     $roles = $config['roles'];
     if (!isset($roles[self::DEFAULT_ROLE])) {
         $roles[self::DEFAULT_ROLE] = '';
     }
     $this->admins = $config['admins'];
     if (!isset($this->admins)) {
         throw new \UnexpectedValueException('No admin-user set');
     }
     $acl = new Acl();
     foreach ($roles as $name => $parent) {
         if (!$acl->hasRole($name)) {
             if (empty($parent)) {
                 $parent = array();
             } else {
                 $parent = explode(',', $parent);
             }
             $acl->addRole(new Role($name), $parent);
         }
     }
     foreach ($config['resources'] as $permission => $controllers) {
         foreach ($controllers as $controller => $actions) {
             if ($controller == 'all') {
                 $controller = null;
             } else {
                 if (!$acl->hasResource($controller)) {
                     $acl->addResource(new Resource($controller));
                 }
             }
             foreach ($actions as $action => $role) {
                 if ($action == 'all') {
                     $action = null;
                 }
                 $assert = null;
                 if (is_array($role)) {
                     $assert = $serviceLocator->get($role['assert']);
                     $role = $role['role'];
                 }
                 $role = explode(',', $role);
                 foreach ($role as $roleItem) {
                     if ($permission == 'allow') {
                         $acl->allow($roleItem, $controller, $action, $assert);
                     } elseif ($permission == 'deny') {
                         $acl->deny($roleItem, $controller, $action, $assert);
                     } else {
                         continue;
                     }
                 }
             }
         }
     }
     return $acl;
 }
開發者ID:krsreenatha,項目名稱:php.ug,代碼行數:67,代碼來源:AclFactory.php

示例11: testBuildItemWillAddRulesToAcl

 public function testBuildItemWillAddRulesToAcl()
 {
     $this->assertFalse($this->acl->isAllowed('guest', 'login'));
     $this->assertFalse($this->acl->isAllowed('user', null, 'GET'));
     $this->assertTrue($this->object->buildItem());
     $this->assertTrue($this->acl->isAllowed('guest', 'login'));
     $this->assertTrue($this->acl->isAllowed('user', null, 'GET'));
 }
開發者ID:chippyash,項目名稱:zend-acl-xml-builder,代碼行數:8,代碼來源:RuleBuilderTest.php

示例12: can

 /**
  * @param \Zend\Permissions\Acl\Resource\ResourceInterface|string $resource
  * @param string $action
  * @return bool
  */
 public function can($resource, $action)
 {
     foreach ($this->roles as $role) {
         if ($this->acl->isAllowed($role, $resource, $action)) {
             return true;
         }
     }
     return false;
 }
開發者ID:kivagant,項目名稱:staticus-core,代碼行數:14,代碼來源:User.php

示例13: testBuildCanAcceptXMLAsString

 public function testBuildCanAcceptXMLAsString()
 {
     $content = file_get_contents(__DIR__ . '/fixtures/test.xml');
     $this->object = new AclBuilder(new StringType($content), $this->acl);
     $this->assertTrue($this->object->build());
     $this->assertTrue($this->acl->hasRole('guest'));
     $this->assertTrue($this->acl->hasResource('logout'));
     $this->assertTrue($this->acl->isAllowed('guest', 'login'));
     $this->assertTrue($this->acl->isAllowed('user', null, 'GET'));
 }
開發者ID:chippyash,項目名稱:zend-acl-xml-builder,代碼行數:10,代碼來源:AclBuilderTest.php

示例14: getPermissosAclRecursoDesprotegidos

 public function getPermissosAclRecursoDesprotegidos(\Zend\Permissions\Acl\Acl $acl, \Doctrine\ORM\EntityManager $em)
 {
     $repo = $em->getRepository('Security\\Entity\\Grupo');
     foreach ($repo->fetchPairs() as $grupo) {
         foreach ($this->getRecursosDesprotegidos() as $recurso) {
             $acl->allow($grupo, $recurso);
         }
     }
     return $acl;
 }
開發者ID:ericoautocad,項目名稱:module-security-zf2,代碼行數:10,代碼來源:ACL.php

示例15: testIsAuthorizedNegative

 public function testIsAuthorizedNegative()
 {
     $acl = new Acl();
     $acl->addRole('administrator');
     $acl->addRole('foo', 'administrator');
     $acl->addRole('bar');
     $access = new AclInheritRoleAccess();
     $access->setAcl($acl);
     $access->setUser('bar');
     $this->assertFalse($access->isAuthorized());
 }
開發者ID:sporkcode,項目名稱:sporktools,代碼行數:11,代碼來源:AclInheritRoleAccessTest.php


注:本文中的Zend\Permissions\Acl\Acl類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。