forked from wingman007/fmi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
970cf03
commit a7e52b2
Showing
22 changed files
with
1,818 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
// http://p0l0.binware.org/index.php/2012/02/18/zend-framework-2-authentication-acl-using-eventmanager/ | ||
// First I created an extra config for ACL (could be also in module.config.php, but I prefer to have it in a separated file) | ||
return array( | ||
'acl' => array( | ||
'roles' => array( | ||
'guest' => null, | ||
'member' => 'guest' | ||
), | ||
'resources' => array( | ||
'allow' => array( | ||
//- 'user' => array( | ||
//- 'login' => 'guest', | ||
//- 'all' => 'member' | ||
//- ) | ||
'CsnUser\Controller\UserDoctrineSimpleAuthorizationAcl' => array( | ||
// 'all' => 'guest', | ||
'index' => 'guest', | ||
'create' => 'member' | ||
), | ||
'CsnUser\Controller\UserDoctrinePureAcl' => array( | ||
'all' => 'member', | ||
), | ||
'Application\Controller\Index' => array( | ||
'all' => 'guest' | ||
), | ||
'Auth\Controller\Index' => array( | ||
// 'index' => 'guest', | ||
// 'all' => 'member', | ||
'all' => 'guest' | ||
), | ||
'zfcuser' => array( // zg-commoms ZfcUser | ||
// 'index' => 'guest', | ||
// 'all' => 'member', | ||
'all' => 'guest' | ||
), | ||
'Auth\Controller\Hello' => array( | ||
'all' => 'guest' | ||
), | ||
'Auth\Controller\FormTests' => array( | ||
'all' => 'guest' | ||
), | ||
'AuthDoctrine\Controller\Index' => array( | ||
'all' => 'guest' | ||
// 'all' => 'member', | ||
), | ||
) | ||
) | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
-- | ||
-- Table structure for table `user_roles` | ||
-- | ||
|
||
DROP TABLE IF EXISTS `user_roles`; | ||
/*!40101 SET @saved_cs_client = @@character_set_client */; | ||
/*!40101 SET character_set_client = utf8 */; | ||
CREATE TABLE `user_roles` ( | ||
`usrl_id` int(11) NOT NULL AUTO_INCREMENT, | ||
`usrl_name` varchar(50) NOT NULL, | ||
PRIMARY KEY (`usrl_id`) | ||
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='The System Roles. Who can see and do what'; | ||
/*!40101 SET character_set_client = @saved_cs_client */; | ||
|
||
-- | ||
-- Dumping data for table `user_roles` | ||
-- | ||
|
||
LOCK TABLES `user_roles` WRITE; | ||
/*!40000 ALTER TABLE `user_roles` DISABLE KEYS */; | ||
INSERT INTO `user_roles` VALUES (1,'Public'),(2,'Prospect'),(3,'Member'),(4,'Admin'); | ||
/*!40000 ALTER TABLE `user_roles` ENABLE KEYS */; | ||
UNLOCK TABLES; | ||
|
||
-- | ||
-- Table structure for table `user_tree_type_values` | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
/** | ||
* File for Acl Class | ||
* | ||
* @category User | ||
* @package User_Acl | ||
* @author Marco Neumann <webcoder_at_binware_dot_org> | ||
* @copyright Copyright (c) 2011, Marco Neumann | ||
* @license http://binware.org/license/index/type:new-bsd New BSD License | ||
* http://p0l0.binware.org/index.php/2012/02/18/zend-framework-2-authentication-acl-using-eventmanager/ | ||
*/ | ||
|
||
/** | ||
* @namespace | ||
*/ | ||
namespace CsnUser\Acl; | ||
// namespace User\Acl; | ||
|
||
/** | ||
* @uses Zend\Acl\Acl | ||
* @uses Zend\Acl\Role\GenericRole | ||
* @uses Zend\Acl\Resource\GenericResource | ||
*/ | ||
use Zend\Permissions\Acl\Acl as ZendAcl, | ||
Zend\Permissions\Acl\Role\GenericRole as Role, | ||
Zend\Permissions\Acl\Resource\GenericResource as Resource; | ||
// use Zend\Acl\Acl as ZendAcl, | ||
// Zend\Acl\Role\GenericRole as Role, | ||
// Zend\Acl\Resource\GenericResource as Resource; | ||
|
||
/** | ||
* Class to handle Acl | ||
* | ||
* This class is for loading ACL defined in a config | ||
* | ||
* @category User | ||
* @package User_Acl | ||
* @copyright Copyright (c) 2011, Marco Neumann | ||
* @license http://binware.org/license/index/type:new-bsd New BSD License | ||
*/ | ||
class Acl extends ZendAcl { | ||
/** | ||
* Default Role | ||
*/ | ||
const DEFAULT_ROLE = 'guest'; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param array $config | ||
* @return void | ||
* @throws \Exception | ||
*/ | ||
public function __construct($config) | ||
{ | ||
if (!isset($config['acl']['roles']) || !isset($config['acl']['resources'])) { | ||
throw new \Exception('Invalid ACL Config found'); | ||
} | ||
|
||
$roles = $config['acl']['roles']; | ||
if (!isset($roles[self::DEFAULT_ROLE])) { | ||
$roles[self::DEFAULT_ROLE] = ''; | ||
} | ||
|
||
$this->_addRoles($roles) | ||
->_addResources($config['acl']['resources']); | ||
} | ||
|
||
/** | ||
* Adds Roles to ACL | ||
* | ||
* @param array $roles | ||
* @return User\Acl | ||
*/ | ||
protected function _addRoles($roles) | ||
{ | ||
foreach ($roles as $name => $parent) { | ||
if (!$this->hasRole($name)) { | ||
if (empty($parent)) { | ||
$parent = array(); | ||
} else { | ||
$parent = explode(',', $parent); | ||
} | ||
|
||
$this->addRole(new Role($name), $parent); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Adds Resources to ACL | ||
* | ||
* @param $resources | ||
* @return User\Acl | ||
* @throws \Exception | ||
*/ | ||
protected function _addResources($resources) | ||
{ | ||
foreach ($resources as $permission => $controllers) { | ||
foreach ($controllers as $controller => $actions) { | ||
if ($controller == 'all') { | ||
$controller = null; | ||
} else { | ||
if (!$this->hasResource($controller)) { | ||
$this->addResource(new Resource($controller)); | ||
} | ||
} | ||
|
||
foreach ($actions as $action => $role) { | ||
if ($action == 'all') { | ||
$action = null; | ||
} | ||
|
||
if ($permission == 'allow') { | ||
$this->allow($role, $controller, $action); | ||
} elseif ($permission == 'deny') { | ||
$this->deny($role, $controller, $action); | ||
} else { | ||
throw new \Exception('No valid permission defined: ' . $permission); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.