public function initialAclRole($e, $serviceAdministratorConfigManager, $authenticationServiceStorage) { $oAcl = new Acl(); $oAcl->deny(); $oAcl->addRole(new Role('staff_1')); $oAcl->addRole(new Role('staff_2')); $oAcl->addRole(new Role('administrator')); $oAcl->addResource('administrator'); $oAcl->addResource('api'); $oAcl->allow('staff_1', 'administrator', 'index:index'); $oAcl->allow('staff_1', 'administrator', 'user:profile'); $oAcl->allow('staff_1', 'administrator', 'user:list'); $oAcl->allow('staff_1', 'administrator', 'menu:list'); $controllerClass = get_class($e->getTarget()); $moduleName = strtolower(substr($controllerClass, 0, strpos($controllerClass, '\\'))); $routeMatch = $e->getRouteMatch(); $aName = strtolower($routeMatch->getParam('action', 'not-found')); $cName = strtolower($routeMatch->getParam('__CONTROLLER__', 'not-found')); /* if (!$oAcl->isAllowed("staff_1",$moduleName, "{$cName}:{$aName}")) { $response = $e->getResponse(); $response->setStatusCode(302); $response->getHeaders()->addHeaderLine('Location', $e->getRouter()->assemble($serviceAdministratorConfigManager['options']['constraints'], array('name' => $_SERVER['HTTP_HOST']. '/'. 'default'))); $e->stopPropagation(); } */ }
/** * @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; }
/** * AccessControl constructor. * @param $config * @param $entityManager * @param $userMapper * @param $roleMapper * @param $resourceMapper */ public function __construct($config, $entityManager, $userMapper, $roleMapper, $resourceMapper) { $this->setConfig($config); $this->setEntityManager($entityManager); $this->setUserMapper($userMapper); $this->setRoleMapper($roleMapper); $this->setResourceMapper($resourceMapper); $this->modules = $this->getConfig()['mfcc_admin']['modules']; $this->acl = new Acl(); foreach ($this->getRoleMapper()->getAll() as $index => $role) { /* @var $role RoleEntity */ $this->acl->addRole(new Role($role->getName())); } foreach ($this->modules as $index => $module) { $this->acl->addResource(new GenericResource($module['module_name'])); } $this->acl->addResource(new GenericResource('Users')); $this->acl->addResource(new GenericResource('Roles')); foreach ($this->getResourceMapper()->getAll() as $index => $resource) { /* @var $resource ResourceEntity */ $this->acl->allow($resource->getRole()->getName(), $resource->getResource(), $resource->getPermission()); if ($resource->getPermission() == self::WRITE) { $this->acl->allow($resource->getRole()->getName(), $resource->getResource(), self::READ); } } }
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; }
public function doAuthorization($e) { return; //setting ACL... $acl = new Acl(); //add role .. $acl->addRole(new Role('anonymous')); $acl->addRole(new Role('user'), 'anonymous'); $acl->addRole(new Role('admin'), 'user'); $acl->addResource(new Resource('Stick')); $acl->addResource(new Resource('Auth')); $acl->deny('anonymous', 'Stick', 'list'); $acl->allow('anonymous', 'Auth', 'login'); $acl->allow('anonymous', 'Auth', 'signup'); $acl->allow('user', 'Stick', 'add'); $acl->allow('user', 'Auth', 'logout'); //admin is child of user, can publish, edit, and view too ! $acl->allow('admin', 'Stick'); $controller = $e->getTarget(); $controllerClass = get_class($controller); $namespace = substr($controllerClass, strrpos($controllerClass, '\\') + 1); $role = !$this->getSessContainer()->role ? 'anonymous' : $this->getSessContainer()->role; echo $role; exit; if (!$acl->isAllowed($role, $namespace, 'view')) { $router = $e->getRouter(); $url = $router->assemble(array(), array('name' => 'Login/auth')); $response = $e->getResponse(); $response->setStatusCode(302); //redirect to login route... $response->getHeaders()->addHeaderLine('Location', $url); } }
/** * Constructor * * @param array $roles * @param array $resources */ public function __construct($roles, $resources) { //Create brand new Acl object $this->acl = new Acl(); //Add each resources foreach ($resources as $resource) { //Add the resource $this->acl->addResource(new Resource($resource)); } //Add each roles foreach ($roles as $role => $resources) { //Add the role $this->acl->addRole(new Role($role)); //If we want to grant all privileges on all resources if ($resources === true) { //Allow all privileges $this->acl->allow($role); //Else if we have specific privileges for the role } elseif (is_array($resources)) { //Create each resource permissions foreach ($resources as $resource => $permissions) { //Add resource permissions of the role $this->acl->allow($role, $resource, $permissions); } } } }
public function doAuthorization($e) { //setting ACL... $acl = new Acl(); //add role .. $acl->addRole(new Role('anonymous')); $acl->addRole(new Role('user'), 'anonymous'); $acl->addRole(new Role('admin'), 'user'); $acl->addResource(new Resource('Application')); $acl->addResource(new Resource('Login')); $acl->addResource(new Resource('ZfcAdmin')); $acl->deny('anonymous', 'Application', 'view'); $acl->allow('anonymous', 'Login', 'view'); $acl->allow('user', array('Application'), array('view')); //admin is child of user, can publish, edit, and view too ! $acl->allow('admin', array('Application'), array('publish', 'edit')); $controller = $e->getTarget(); $controllerClass = get_class($controller); //echo "<pre>";print_r($controllerClass);exit; $namespace = substr($controllerClass, 0, strpos($controllerClass, '\\')); // echo "<pre>";print_r($namespace);exit; $role = !$this->getSessContainer()->role ? 'anonymous' : $this->getSessContainer()->role; if (!isset($_SESSION['admin']['user_id']) && $namespace == 'ZfcAdmin') { $router = $e->getRouter(); $url = $router->assemble(array(), array('name' => 'zfcadmin')); $response = $e->getResponse(); $response->setStatusCode(302); //redirect to login route... /* change with header('location: '.$url); if code below not working */ $response->getHeaders()->addHeaderLine('Location', $url); $e->stopPropagation(); } }
public function createService(ServiceLocatorInterface $serviceLocator) { //print_r('--factoryservicerolecreater'); $config = $serviceLocator->get('config'); $acl = new Acl(); $moduleManager = $serviceLocator->get('ModuleManager'); $modules = $moduleManager->getLoadedModules(); $loadedModules = array_keys($modules); //print_r($loadedModules); if (!empty($loadedModules)) { foreach ($loadedModules as $key) { $acl->addResource(strtolower(trim($key))); } } if (isset($config['ACL_pages'])) { if (!empty($config['ACL_pages'])) { $aclArr = $config['ACL_pages']; foreach ($aclArr as $key => $value) { $parent = null; if (isset($value['parent'])) { $parent = $value['parent']; } if (isset($parent)) { $acl->addRole(new Role($key), $parent); } else { $acl->addRole(new Role($key)); } if (isset($value['action'])) { foreach ($value['action'] as $action => $actArr) { foreach ($actArr as $index) { $acl->allow($key, $action, $index); } } //print_r($value['action']); } //print_r('--key-->'.$key.'--parent-->'.$parent); $parent = null; } } } /*$acl->addRole(new Role('Consultant')) ->addRole(new Role('Supervisor'), 'Consultant') ->addRole(new Role('Admin'), 'Supervisor') ->addRole(new Role('Guest')) ->addRole(new Role('New User'), 'Guest') ->addRole(new Role('Firm User'), 'New User') ->addRole(new Role('Firm Owner'), 'Firm User');*/ /*$acl->addResource('consultant'); $acl->addResource('login'); $acl->addResource('sanalfabrika');*/ /*$acl->allow('consultant', 'sfdm', 'index'); $acl->allow('consultant', 'sfdm', 'registration'); $acl->allow('consultant', 'login', 'index'); */ /*$acl->allow('anonymous', 'album', 'album:add'); $acl->deny('anonymous', 'album', 'album:hello'); $acl->allow('anonymous', 'album', 'album:view'); $acl->allow('anonymous', 'album', 'album:edit'); */ return $acl; }
public function fillRoles(array $rolesConfig) { foreach ($rolesConfig as $role => $options) { $inherit = $this->getOption($options, self::INHERIT); if (null !== $inherit && !is_string($inherit) && !is_array($inherit) && !$inherit instanceof RoleInterface) { throw new Exceptions\RuntimeException('Inherit option must be a string, an array or implement RoleInterface for roles'); } $this->acl->addRole($role, $inherit); } }
public function setRoles(Acl $acl) { $acl->addRole(new Role($this->getConfig()->defaults->guestRoleName)); foreach ($this->getConfig()->defaults->roles as $role => $subRole) { if (is_numeric($role)) { $acl->addRole(new Role($subRole), $this->getConfig()->defaults->guestRoleName); } else { $acl->addRole(new Role($role), new Role($subRole)); } } }
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()); }
private function _load() { if ($this->loaded == false) { // Add roles $config = $this->serviceLocator->get('config'); if (isset($config['acl']['role_providers'])) { $roles = []; foreach ($config['acl']['role_providers'] as $class => $options) { /** @var \Acl\Provider\Role\ProviderInterface $roleProvider */ $roleProvider = $this->serviceLocator->get($class); $roles = $roles + $roleProvider->getRoles(); } foreach ($roles as $role) { /** @var \Acl\Entity\Role $role */ $this->acl->addRole($role, $role->getParents()); } } // Add resources if (isset($config['acl']['resource_providers'])) { foreach ($config['acl']['resource_providers'] as $class => $options) { /** @var \Acl\Provider\Resource\ProviderInterface $resourceProvider */ $resourceProvider = $this->serviceLocator->get($class); $resources = $resourceProvider->getResources(); if ($resources) { foreach ($resources as $r) { if (!$this->acl->hasResource($r)) { $this->acl->addResource($r); } } } } } // Add rules if (isset($config['acl']['rule_providers'])) { $rules = []; foreach ($config['acl']['rule_providers'] as $class => $options) { /** @var \Acl\Provider\Rule\ProviderInterface $ruleProvider */ $ruleProvider = $this->serviceLocator->get($class); $rules = $rules + $ruleProvider->getRules(); } foreach ($rules as $rule) { /** @var \Acl\Entity\Rule $rule */ if ($rule->allow) { $this->acl->allow($rule->obj_id, $rule->resource, $rule->privilege); } else { $this->acl->deny($rule->obj_id, $rule->resource, $rule->privilege); } } } $this->loaded = true; } }
public function getAcl() { if (!$this->acl) { $acl = new Acl(); $roleGuest = new Role('guest'); $acl->addRole($roleGuest); $acl->addRole(new Role('admin'), $roleGuest); $acl->allow($roleGuest, null, 'view'); $acl->allow('admin', null, array('add', 'edit', 'delete')); $this->acl = $acl; } return $this->acl; }
public function onBootstrap(MvcEvent $event) { $app = $event->getApplication(); $sm = $app->getServiceManager(); $em = $app->getEventManager(); $cfg = $sm->get('Config'); if (isset($cfg['deit_authorisation'])) { //get the service config $serviceCfg = $cfg['deit_authorisation']; //construct the Access Control List $acl = new Acl(); if (isset($serviceCfg['acl']['roles'])) { foreach ($serviceCfg['acl']['roles'] as $key => $value) { if (is_string($key)) { $acl->addRole($key, $value); } else { $acl->addRole($value); } } } if (isset($serviceCfg['acl']['resources'])) { foreach ($serviceCfg['acl']['resources'] as $resource) { $acl->addResource($resource); } } if (isset($serviceCfg['acl']['rules']['allow'])) { foreach ($serviceCfg['acl']['rules']['allow'] as $resource => $role) { $acl->allow($role, $resource); } } //create the authorisation service $service = new \DeitAuthorisationModule\Service(); $service->setAcl($acl); if (isset($serviceCfg['default_role'])) { $service->setDefaultRole($serviceCfg['default_role']); } if (isset($serviceCfg['role_resolver'])) { $service->setRoleResolver($serviceCfg['role_resolver']); } //create the authorisation strategy $options = $sm->get('deit_authorisation_options'); $strategy = $sm->get($options->getStrategy()); //attach the service listeners $em->attachAggregate($strategy); $em->attachAggregate($service); //TODO: specify the view } }
public function initAcl(MvcEvent $e) { //Creamos el objeto ACL $acl = new Acl(); //Incluimos la lista de roles y permisos, nos devuelve un array $roles = (require 'config/autoload/acl.roles.php'); foreach ($roles as $role => $resources) { //Indicamos que el rol será genérico $role = new \Zend\Permissions\Acl\Role\GenericRole($role); //Añadimos el rol al ACL $acl->addRole($role); //Recorremos los recursos o rutas permitidas foreach ($resources["allow"] as $resource) { //Si el recurso no existe lo añadimos if (!$acl->hasResource($resource)) { $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource)); } //Permitimos a ese rol ese recurso $acl->allow($role, $resource); } foreach ($resources["deny"] as $resource) { //Si el recurso no existe lo añadimos if (!$acl->hasResource($resource)) { $acl->addResource(new \Zend\Permissions\Acl\Resource\GenericResource($resource)); } //Denegamos a ese rol ese recurso $acl->deny($role, $resource); } } //Establecemos la lista de control de acceso $e->getViewModel()->acl = $acl; }
/** * @param Acl $acl */ protected function initRoles(Acl $acl) { $roles = $this->moduleOptions->getRoles(); foreach ($roles as $role) { $acl->addRole(new RoleRole($role->getId()), is_null($role->getParent()) ? null : new RoleRole($role->getParent())); } }
/** * 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; }
public function build() { $authService = $this->getServiceLocator()->get('user-service-auth'); $role = $authService->getRole(); $repositoryPerfil = $this->getEm('Admin\\Entity\\Perfil'); $repositoryResource = $this->getEm('Admin\\Entity\\Resource'); $repositoryAcl = $this->getEm('Admin\\Entity\\Acl'); $config = $repositoryAcl->listaAcl(); $config['acl']['roles'] = $repositoryPerfil->getRoles(); $config['acl']['roles']['visitante'] = null; $config['acl']['resources'] = $repositoryResource->getResources(); $acl = new ZendAcl(); foreach ($config['acl']['roles'] as $role => $parent) { $acl->addRole(new GenericRole($role), $parent); } foreach ($config['acl']['resources'] as $resouce) { $acl->addResource(new GenericResource($resouce)); } if (isset($config['acl']['previlege'])) { foreach ($config['acl']['previlege'] as $role => $privilege) { if (isset($privilege['allow'])) { foreach ($privilege['allow'] as $permissao) { $acl->allow($role, $permissao); } } if (isset($privilege['deny'])) { foreach ($privilege['deny'] as $permissao) { $acl->deny($role, $permissao); } } } } return $acl; }
public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('config.helper')->get('acl'); $acl = new Acl(); foreach ($config['roles'] as $role => $parents) { if (empty($parents)) { $parents = null; } $role = new GenericRole($role); $acl->addRole($role, $parents); } foreach ($config['resources'] as $permission => $controllers) { foreach ($controllers as $controller => $actions) { if (!$acl->hasResource($controller)) { $acl->addResource(new GenericResource($controller)); } foreach ($actions as $action => $role) { if ($action == '*') { $action = null; } if ($permission == 'allow') { $acl->allow($role, $controller, $action); } elseif ($permission == 'deny') { $acl->deny($role, $controller, $action); } else { throw new Exception('No valid permission defined: ' . $permission); } } } } if (class_exists('Zend\\View\\Helper\\Navigation')) { Navigation::setDefaultAcl($acl); } return $acl; }
/** * Constroi a ACL de acordo com as entities * @see Core\Entity\System\Roles * @todo Inclusao das ACLS no Cache * @return Acl */ public function build() { $em = $this->getServiceManager()->get('Doctrine\\ORM\\EntityManager'); $roles = $em->getRepository('Core\\Entity\\System\\Roles')->findAll(); $resources = $em->getRepository('Core\\Entity\\System\\Resources')->findAll(); $acl = new Acl(); foreach ($roles as $role) { $acl->addRole(new Role($role->getRoleName()), $role->getRoleParent()); } foreach ($resources as $r) { $acl->addResource(new Resource($r->getResourceName())); } foreach ($roles as $role) { $rolename = $role->getRoleName(); $allowed = $em->getRepository('Core\\Entity\\System\\Permissions')->findBy(array('idRole' => $role->getId(), 'permission' => 'allow')); foreach ($allowed as $allow) { $resources = $em->getRepository('Core\\Entity\\System\\Resources')->find($allow->getIdResource()); $acl->allow($rolename, $resources->getResourceName()); } $denyed = $em->getRepository('Core\\Entity\\System\\Permissions')->findBy(array('idRole' => $role->getId(), 'permission' => 'deny')); foreach ($denyed as $deny) { $resources = $em->getRepository('Core\\Entity\\System\\Resources')->find($deny->getIdResource()); $acl->deny($rolename, $resources->getResourceName()); } } return $acl; }
/** * 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()))); } } }
/** * @group 4226 */ public function testAllowNullPermissionAfterResourcesExistShouldAllowAllPermissionsForRole() { $this->_acl->addRole('admin'); $this->_acl->addResource('newsletter'); $this->_acl->allow('admin'); $this->assertTrue($this->_acl->isAllowed('admin')); }
/** * Constroi a ACL * @return Acl */ public function build() { // servico de config (array de configuracao) $config = $this->getServiceManager()->get('Config'); $acl = new Acl(); foreach ($config['acl']['roles'] as $role => $parent) { $acl->addRole(new Role($role), $parent); } foreach ($config['acl']['resources'] as $r) { $acl->addResource(new Resource($r)); } foreach ($config['acl']['privilege'] as $role => $privilege) { if (isset($privilege['allow'])) { foreach ($privilege['allow'] as $p) { $acl->allow($role, $p); } } if (isset($privilege['deny'])) { foreach ($privilege['deny'] as $p) { $acl->deny($role, $p); } } } return $acl; }
/** * 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; }
public function getRolesACL(\Zend\Permissions\Acl\Acl $acl, \Doctrine\ORM\EntityManager $em) { $repo = $em->getRepository('Security\\Entity\\Grupo'); foreach ($repo->fetchPairs() as $grupo) { $acl->addRole($grupo); } return $acl; }
private function addRoles(Acl $acl) { foreach ($this->config as $roleName => $roleConfig) { $parents = isset($roleConfig['parents']) ? $roleConfig['parents'] : []; $parents = array_map('strtolower', $parents); $acl->addRole(new GenericRole(strtolower($roleName)), $parents); } }
public function loginAction() { $authenticationService = new AuthenticationService(); if ($authenticationService->hasIdentity()) { return $this->redirect()->toRoute('dashboard'); } $form = new LoginForm(); $viewModel = new ViewModel(); $this->layout("layout/login"); $viewModel->setVariable("form", $form); $viewModel->setVariable("config", $this->config); $request = $this->getRequest(); if ($request->isPost()) { $login = new Login(); $login->getInputFilter()->get('captcha')->setRequired(false); $form->setInputFilter($login->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $username = $form->get('username')->getValue(); $password = $form->get('password')->getValue(); $authSessionAdapter = $this->getAuthSessionAdapter(); if ($authSessionAdapter->authenticate($username, $password)) { $userObject = $authenticationService->getStorage()->read(); $rol = $userObject->rol; $acl = new Acl(); $acl->addResource(new Resource("dashboard")); $acl->addResource(new Resource("note")); if ($rol == 1) { $resources = $this->config['resources']; foreach ($resources as $module => $resource) { foreach ($resource as $resourceValue) { $acl->addResource(new Resource($resourceValue)); } } } else { $acl->addRole(new Role($rol)); $modules = $this->getModuleRolTable()->fetchAll($rol); foreach ($modules as $module) { $acl->addResource(new Resource($module)); } } $userObject->acl = serialize($acl); return $this->redirect()->toRoute('dashboard'); } else { $form->get('username')->setValue(""); $form->get('password')->setValue(""); if ($authSessionAdapter->getCode() == -5) { $form->get("username")->setMessages(array('username' => $this->config['authentication_codes'][$authSessionAdapter->getCode()])); } else { $form->get("username")->setMessages(array('username' => $this->config['authentication_codes'][-6])); } } } else { $form->get("username")->setMessages(array('username' => $this->config['authentication_codes'][-6])); } } return $viewModel; }
/** * Returns CommentController instance. * * @param ServiceLocatorInterface $serviceLocator * @return CommentController **/ public function createService(ServiceLocatorInterface $serviceLocator) { /* @var $serviceLocator Zend\Mvc\Controller\ControllerManager */ $sm = $serviceLocator->getServiceLocator(); $em = $sm->get('em'); $service = new CommentService($em); $controller = new CommentController(); $controller->setEntityManager($em); $controller->setService($service); $acl = new Acl(); $acl->addRole(new Role(UserService::ROLE_GUEST)); $acl->addRole(new Role(UserService::ROLE_ADMIN)); $acl->addResource($controller); $acl->allow(UserService::ROLE_ADMIN, $controller); $acl->allow(UserService::ROLE_GUEST, $controller, array('add')); $controller->setAcl($acl); return $controller; }
public function setupAcl(MvcEvent $e) { $acl = new Acl(); $rolInvitado = new Role('invitado'); $admin = new Admin(); $rolAdmin = new Role($admin->getRol()); $acl->addRole($rolInvitado); $acl->addRole($rolAdmin, $rolInvitado); //el admin hereda los permisos de invitado $acl->addResource('index_empleado'); $acl->addResource('login'); $acl->deny($rolInvitado, 'index_empleado'); $acl->allow($rolInvitado, 'login'); //$acl->allow($rolAdmin, 'login'); $acl->allow($rolAdmin, 'index_empleado'); $vista = $e->getApplication()->getMvcEvent()->getViewModel(); $vista->acl = $acl; $this->acl = $acl; }
private function getConfiguredAcl() { $acl = new Acl(); $acl->addRole(new Role('guest')); $acl->addRole(new Role('member'), 'guest'); $acl->addRole(new Role('admin')); $acl->addResource('/'); $acl->addResource('/login'); $acl->addResource('/member'); $acl->addResource('/member/photo/:id'); $acl->addResource('/admin'); $acl->allow('guest', '/'); $acl->allow('guest', '/login', array('GET', 'POST')); $acl->deny('guest', '/admin'); $acl->allow('member', '/member'); $acl->allow('member', '/member/photo/:id', 'DELETE'); // admin gets everything $acl->allow('admin'); return $acl; }