|
6 | 6 |
|
7 | 7 | class WAC { |
8 | 8 | private $filesystem; |
9 | | - |
| 9 | + private $baseUrl; |
| 10 | + private $basePath; |
| 11 | + |
10 | 12 | public function __construct($filesystem) { |
11 | 13 | $this->filesystem = $filesystem; |
| 14 | + $this->baseUrl = ''; |
| 15 | + $this->basePath = ''; |
12 | 16 | } |
13 | 17 |
|
| 18 | + public function setBaseUrl($url) { |
| 19 | + $this->baseUrl = $url; |
| 20 | + $serverRequest = new \Laminas\Diactoros\ServerRequest(array(),array(), $url); |
| 21 | + $this->basePath = $serverRequest->getUri()->getPath(); |
| 22 | + } |
| 23 | + |
14 | 24 | public function addWACHeaders($request, $response, $webId) { |
15 | | - $userGrants = $this->getWACGrants($this->getUserGrants($request->getUri()->getPath(), $webId), $request->getUri()); |
16 | | - $publicGrants = $this->getWACGrants($this->getPublicGrants($request->getUri()->getPath()), $request->getUri()); |
| 25 | + $path = $request->getUri()->getPath(); |
| 26 | + if ($this->basePath) { |
| 27 | + $path = str_replace($this->basePath, '', $path); |
| 28 | + } |
| 29 | + $userGrants = $this->getWACGrants($this->getUserGrants($path, $webId), $request->getUri()); |
| 30 | + $publicGrants = $this->getWACGrants($this->getPublicGrants($path), $request->getUri()); |
17 | 31 |
|
18 | 32 | $wacHeaders = array(); |
19 | 33 | if ($userGrants) { |
@@ -53,9 +67,14 @@ private function isGranted($requestedGrants, $uri, $webId) { |
53 | 67 | return true; |
54 | 68 | } |
55 | 69 |
|
56 | | - // error_log("REQUESTED GRANT: " . join(" or ", $requestedGrants) . " on $uri"); |
57 | | - $grants = $this->getUserGrants($uri->getPath(), $webId); |
58 | | - // error_log("GRANTED GRANTS for $webId: " . json_encode($grants)); |
| 70 | + $path = $uri->getPath(); |
| 71 | + if ($this->basePath) { |
| 72 | + $path = str_replace($this->basePath, '', $path); |
| 73 | + } |
| 74 | + |
| 75 | + //error_log("REQUESTED GRANT: " . join(" or ", $requestedGrants) . " on $uri"); |
| 76 | + $grants = $this->getUserGrants($path, $webId); |
| 77 | + //error_log("GRANTED GRANTS for $webId: " . json_encode($grants)); |
59 | 78 | if (is_array($grants)) { |
60 | 79 | foreach ($requestedGrants as $requestedGrant) { |
61 | 80 | if ($grants['accessTo'] && $grants['accessTo'][$requestedGrant] && $this->arePathsEqual($grants['accessTo'][$requestedGrant], $uri)) { |
@@ -156,6 +175,9 @@ private function getParentAcl($path) { |
156 | 175 | public function getRequestedGrants($request) { |
157 | 176 | $method = strtoupper($request->getMethod()); |
158 | 177 | $path = $request->getUri()->getPath(); |
| 178 | + if ($this->basePath) { |
| 179 | + $path = str_replace($this->basePath, '', $path); |
| 180 | + } |
159 | 181 |
|
160 | 182 | switch ($method) { |
161 | 183 | case "GET": |
@@ -244,7 +266,7 @@ private function getParentUri($uri) { |
244 | 266 | } |
245 | 267 |
|
246 | 268 | $parentPath = dirname($path) . '/'; |
247 | | - if ($this->filesystem->has($parentPath)) { |
| 269 | + if ($this->filesystem->has(str_replace($this->basePath, '', $parentPath))) { |
248 | 270 | return $uri->withPath($parentPath); |
249 | 271 | } else { |
250 | 272 | return $this->getParentUri($uri->withPath($parentPath)); |
|
0 commit comments