Skip to content

Commit 275d4bc

Browse files
authored
Merge pull request #13 from pdsinterop/base-url
Set the base url to the url where the acl file was found
2 parents b734645 + 01c41e1 commit 275d4bc

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

src/WAC.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ private function isUserGranted($requestedGrants, $uri, $webId) {
7575
$path = str_replace($this->basePath, '', $path);
7676
}
7777

78-
//error_log("REQUESTED GRANT: " . join(" or ", $requestedGrants) . " on $uri");
78+
// error_log("REQUESTED GRANT: " . join(" or ", $requestedGrants) . " on $uri");
7979
$grants = $this->getUserGrants($path, $webId);
80-
//error_log("GRANTED GRANTS for $webId: " . json_encode($grants));
80+
// error_log("GRANTED GRANTS for $webId: " . json_encode($grants));
8181
if (is_array($grants)) {
8282
foreach ($requestedGrants as $requestedGrant) {
8383
if ($grants['accessTo'] && $grants['accessTo'][$requestedGrant] && $this->arePathsEqual($grants['accessTo'][$requestedGrant], $uri)) {
@@ -132,7 +132,7 @@ private function getUserGrants($resourcePath, $webId) {
132132
$acl = $this->filesystem->read($aclPath);
133133

134134
$graph = new \EasyRdf_Graph();
135-
$graph->parse($acl, Format::TURTLE, $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME']);
135+
$graph->parse($acl, Format::TURTLE, $this->getAclBase($aclPath));
136136

137137
// error_log("GET GRANTS for $webId");
138138

@@ -172,7 +172,7 @@ private function getOriginGrants($resourcePath, $origin) {
172172
$acl = $this->filesystem->read($aclPath);
173173

174174
$graph = new \EasyRdf_Graph();
175-
$graph->parse($acl, Format::TURTLE, $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME']);
175+
$graph->parse($acl, Format::TURTLE, $this->getAclBase($aclPath));
176176

177177
// error_log("GET GRANTS for $origin");
178178

@@ -205,17 +205,18 @@ private function getOriginGrants($resourcePath, $origin) {
205205
}
206206

207207
private function getAclPath($path) {
208+
$path = $this->normalizePath($path);
208209
// get the filename from the request
209210
$filename = basename($path);
210211
$path = dirname($path);
211212

212-
//error_log("REQUESTED PATH: $path");
213-
//error_log("REQUESTED FILE: $filename");
213+
error_log("REQUESTED PATH: $path");
214+
error_log("REQUESTED FILE: $filename");
214215

215216
$aclOptions = array(
216-
$path.'/'.$filename.'.acl',
217-
$path.'/'.$filename.'/.acl',
218-
$path.'/.acl'
217+
$this->normalizePath($path.'/'.$filename.'.acl'),
218+
$this->normalizePath($path.'/'.$filename.'/.acl'),
219+
$this->normalizePath($path.'/.acl'),
219220
);
220221

221222
foreach ($aclOptions as $aclPath) {
@@ -231,7 +232,9 @@ private function getAclPath($path) {
231232
// check for acl:default predicate, if not found, continue searching up the directory tree
232233
return $this->getParentAcl($path);
233234
}
234-
235+
private function normalizePath($path) {
236+
return preg_replace("|//|", "/", $path);
237+
}
235238
private function getParentAcl($path) {
236239
//error_log("GET PARENT ACL $path");
237240
if ($this->filesystem->has($path.'/.acl')) {
@@ -375,6 +378,9 @@ private function grantToWac($grant) {
375378
return strtolower(explode("#", $grant)[1]); // http://www.w3.org/ns/auth/acl#Read => read
376379
}
377380

381+
private function getAclBase($aclPath) {
382+
return $this->baseUrl . $this->normalizePath(dirname($aclPath) . "/");
383+
}
378384
private function getPublicGrants($resourcePath) {
379385
$aclPath = $this->getAclPath($resourcePath);
380386
if (!$aclPath) {
@@ -384,7 +390,9 @@ private function getPublicGrants($resourcePath) {
384390
$acl = $this->filesystem->read($aclPath);
385391

386392
$graph = new \EasyRdf_Graph();
387-
$graph->parse($acl, Format::TURTLE, $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME']);
393+
394+
error_log("PARSE ACL from $aclPath with base " . $this->getAclBase($aclPath));
395+
$graph->parse($acl, Format::TURTLE, $this->getAclBase($aclPath));
388396

389397
$grants = array();
390398

0 commit comments

Comments
 (0)