3
3
namespace Ubiquity \security \acl \controllers ;
4
4
5
5
use Ubiquity \security \acl \AclManager ;
6
+ use Ubiquity \exceptions \AclException ;
7
+ use Ubiquity \log \Logger ;
6
8
7
9
/**
8
10
* To use with a controller with acls.
@@ -17,24 +19,39 @@ trait AclControllerTrait {
17
19
public abstract function _getRole ();
18
20
19
21
/**
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.
22
23
*
23
24
* @param string $action
25
+ * @param string $role
24
26
* @return boolean
25
27
*/
26
- public function isValid ($ action ) {
28
+ protected function isValidRole ($ action, $ role ) {
27
29
$ controller = \get_class ( $ this );
28
30
$ resourceController = AclManager::getPermissionMap ()->getRessourcePermission ( $ controller , $ action );
29
31
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 ]);
32
39
}
33
40
}
34
41
if ($ action !== '* ' ) {
35
- return $ this ->isValid ( '* ' );
42
+ return $ this ->isValidRole ( '* ' , $ role );
36
43
}
37
44
return false ;
38
45
}
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
+ }
39
56
}
40
57
0 commit comments