Skip to content

Commit 98df1b6

Browse files
committed
add AclException for non existing role when checking (log)
1 parent cc0eef6 commit 98df1b6

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/Ubiquity/security/acl/controllers/AclControllerTrait.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Ubiquity\security\acl\controllers;
44

55
use Ubiquity\security\acl\AclManager;
6+
use Ubiquity\exceptions\AclException;
7+
use Ubiquity\log\Logger;
68

79
/**
810
* To use with a controller with acls.
@@ -17,24 +19,39 @@ trait AclControllerTrait {
1719
public abstract function _getRole();
1820

1921
/**
20-
* Returns True if access to the controller is allowed for the role returned by _getRole method.
21-
* To be override in sub classes
22+
* Returns True if access to the controller is allowed for $role.
2223
*
2324
* @param string $action
25+
* @param string $role
2426
* @return boolean
2527
*/
26-
public function isValid($action) {
28+
protected function isValidRole($action,$role) {
2729
$controller = \get_class ( $this );
2830
$resourceController = AclManager::getPermissionMap ()->getRessourcePermission ( $controller, $action );
2931
if (isset ( $resourceController )) {
30-
if (AclManager::isAllowed ( $this->_getRole (), $resourceController ['resource'], $resourceController ['permission'] )) {
31-
return true;
32+
try{
33+
if (AclManager::isAllowed ( $role, $resourceController ['resource'], $resourceController ['permission'] )) {
34+
return true;
35+
}
36+
}
37+
catch(AclException $e){
38+
Logger::alert('Router', $role.' is not allowed for this resource','Acls',[$controller,$action]);
3239
}
3340
}
3441
if ($action !== '*') {
35-
return $this->isValid ( '*' );
42+
return $this->isValidRole( '*',$role );
3643
}
3744
return false;
3845
}
46+
/**
47+
* Returns True if access to the controller is allowed for the role returned by _getRole method.
48+
* To be override in sub classes
49+
*
50+
* @param string $action
51+
* @return boolean
52+
*/
53+
public function isValid($action) {
54+
return $this->isValidRole($action, $this->_getRole());
55+
}
3956
}
4057

0 commit comments

Comments
 (0)