-
Notifications
You must be signed in to change notification settings - Fork 0
/
Processor.php
executable file
·105 lines (86 loc) · 2.71 KB
/
Processor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
* Acl_Processor
*
* @category Addon
* @package addon.acl
* @author Ebine Yutaka <[email protected]>
* @copyright 2004-2008 Mori Reo <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*/
class Acl_Processor extends Sabel_Bus_Processor
{
/**
* @var Acl_User
*/
protected $aclUser = null;
public function execute(Sabel_Bus $bus)
{
if (($session = $bus->get("session")) === null) {
return $bus->getProcessorList()->remove("acl");
}
$request = $bus->get("request");
$response = $bus->get("response");
if (!$request || !$response) {
return;
}
$this->aclUser = $aclUser = new Acl_User($session);
$_lu = $aclUser->get(Acl_User::LOGIN_URI_KEY, Acl_User::DEFAULT_SCOPE);
if ($_lu !== null && $request->isGet() && $_lu !== $request->getUri()) {
$aclUser->remove(Acl_User::LOGIN_URI_KEY, Acl_User::DEFAULT_SCOPE);
$aclUser->remove(Acl_User::BACK_URI_KEY, Acl_User::DEFAULT_SCOPE);
}
if ($controller = $bus->get("controller")) {
$controller->setAttribute("aclUser", $aclUser);
}
if ($response->isFailure() || $response->isRedirected()) {
return;
}
$configs = $this->getConfig();
$destination = $bus->get("destination");
list ($modName, $ctrlName, $actName) = $destination->toArray();
if (!isset($configs[$modName])) return;
$loginUri = null;
$modConfig = $configs[$modName];
$ctrlConfig = $modConfig->getController($ctrlName);
if ($ctrlConfig !== null && ($scope = $ctrlConfig->scope()) !== null) {
$aclUser->setScope($scope);
} else {
$aclUser->setScope($modConfig->scope());
}
if ($ctrlConfig === null) {
if ($this->isAllow($modConfig)) return;
$loginUri = $modConfig->authUri();
} else {
if ($this->isAllow($ctrlConfig)) return;
if (($loginUri = $ctrlConfig->authUri()) === null) {
$loginUri = $modConfig->authUri();
}
}
l("ACL: access denied.", SBL_LOG_DEBUG);
if ($loginUri === null || !$request->isGet()) {
$response->getStatus()->setCode(Sabel_Response::FORBIDDEN);
} else {
$aclUser->enter($loginUri, "/" . $request->getUri(true));
}
}
public function shutdown(Sabel_Bus $bus)
{
$this->aclUser->save();
}
protected function isAllow($config)
{
if ($config->isPublic()) {
return true;
} elseif ($this->aclUser->isAuthenticated()) {
return $config->isAllow($this->aclUser->getRoles());
} else {
return false;
}
}
protected function getConfig()
{
$config = new Acl_Config();
return $config->configure();
}
}