Skip to content

Commit feb1051

Browse files
committed
Test fix
1 parent 7661a2e commit feb1051

2 files changed

Lines changed: 36 additions & 44 deletions

File tree

http-tests/document-hierarchy/PUT-no-slash-308.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ add-agent-to-group.sh \
1515
--agent "$AGENT_URI" \
1616
"${ADMIN_BASE_URL}acl/groups/writers/"
1717

18-
# create test container
19-
20-
container=$(create-container.sh \
21-
-f "$AGENT_CERT_FILE" \
22-
-p "$AGENT_CERT_PWD" \
23-
-b "$END_USER_BASE_URL" \
24-
--title "Test Container" \
25-
--slug "test-container" \
26-
--parent "$END_USER_BASE_URL")
27-
2818
# add an explicit read/write authorization for the parent since the child document will inherit it
2919

3020
create-authorization.sh \
@@ -33,13 +23,13 @@ create-authorization.sh \
3323
-p "$OWNER_CERT_PWD" \
3424
--label "Write base" \
3525
--agent "$AGENT_URI" \
36-
--to "$container" \
26+
--to "$END_USER_BASE_URL" \
3727
--read \
3828
--write
3929

4030
# check URI without trailing slash gets redirected
4131

42-
invalid_item="${container}no-slash"
32+
invalid_item="${END_USER_BASE_URL}no-slash"
4333

4434
(
4535
curl -k -w "%{http_code}\n" -o /dev/null -s \

src/main/java/com/atomgraph/linkeddatahub/server/filter/request/AuthorizationFilter.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -167,49 +167,51 @@ public Model authorize(ContainerRequestContext request, Resource agent, Resource
167167
createOwnerAuthorization(authorizations, accessTo, agent);
168168
}
169169

170-
// special case for PUT requests to non-existing document: allow if the agent has acl:Write acess to the *parent* URI
171-
if (request.getMethod().equals(HttpMethod.PUT) && accessMode.equals(ACL.Write))
170+
QuerySolutionMap thisQsm = new QuerySolutionMap();
171+
thisQsm.add(SPIN.THIS_VAR_NAME, accessTo);
172+
ResultSetRewindable docTypesResult = loadResultSet(getApplication().get().getService(), getDocumentTypeQuery(), thisQsm);
173+
try
172174
{
173-
// Use Jena's IRIx for RFC 3986-compliant resolution - java.net.URI.resolve("..") is non-compliant
174-
// (RFC 3986 section 5.2.4 step 2D requires ".." to be removed, but java.net.URI leaves it literal)
175-
IRIx parentURI = IRIx.create(accessTo.getURI()).resolve("..");
176-
Resource parent = ResourceFactory.createResource(parentURI.toString());
177-
log.debug("Requested document <{}> not found, falling back to parent URI <{}>", parent, parentURI);
178-
179-
QuerySolutionMap parentQsm = new QuerySolutionMap();
180-
parentQsm.add(SPIN.THIS_VAR_NAME, parent);
181-
ResultSetRewindable docTypesResult = loadResultSet(getApplication().get().getService(), getDocumentTypeQuery(), parentQsm);
182-
try
175+
// special case for PUT requests: if the document does not exist, check acl:Write access on the *parent* URI instead
176+
if (!docTypesResult.hasNext() && request.getMethod().equals(HttpMethod.PUT) && accessMode.equals(ACL.Write))
183177
{
184-
Set<Resource> parentTypes = new HashSet<>();
185-
docTypesResult.forEachRemaining(qs -> parentTypes.add(qs.getResource("Type")));
178+
// Use Jena's IRIx for RFC 3986-compliant resolution - java.net.URI.resolve("..") is non-compliant
179+
// (RFC 3986 section 5.2.4 step 2D requires ".." to be removed, but java.net.URI leaves it literal)
180+
IRIx parentURI = IRIx.create(accessTo.getURI()).resolve("..");
181+
Resource parent = ResourceFactory.createResource(parentURI.toString());
182+
log.debug("Requested document <{}> not found, falling back to parent URI <{}>", parent, parentURI);
186183

187-
// only root and containers allow child documents. This needs to be checked before checking ownership
188-
if (Collections.disjoint(parentTypes, Set.of(Default.Root, DH.Container))) return null;
184+
QuerySolutionMap parentQsm = new QuerySolutionMap();
185+
parentQsm.add(SPIN.THIS_VAR_NAME, parent);
186+
ResultSetRewindable parentTypesResult = loadResultSet(getApplication().get().getService(), getDocumentTypeQuery(), parentQsm);
187+
try
188+
{
189+
Set<Resource> parentTypes = new HashSet<>();
190+
parentTypesResult.forEachRemaining(qs -> parentTypes.add(qs.getResource("Type")));
191+
192+
// only root and containers allow child documents. This needs to be checked before checking ownership
193+
if (Collections.disjoint(parentTypes, Set.of(Default.Root, DH.Container))) return null;
189194

190-
// the agent is the owner of the requested document - automatically grant acl:Read/acl:Append/acl:Write access
191-
if (agent != null && isOwner(parent, agent))
195+
// the agent is the owner of the requested document - automatically grant acl:Read/acl:Append/acl:Write access
196+
if (agent != null && isOwner(parent, agent))
197+
{
198+
log.debug("Agent <{}> is the owner of <{}>, granting acl:Read/acl:Append/acl:Write access", agent, parent);
199+
createOwnerAuthorization(authorizations, parent, agent);
200+
}
201+
202+
accessTo = parent; // redirect ACL query to parent URI since the document does not exist yet
203+
}
204+
finally
192205
{
193-
log.debug("Agent <{}> is the owner of <{}>, granting acl:Read/acl:Append/acl:Write access", agent, parent);
194-
createOwnerAuthorization(authorizations, parent, agent);
206+
parentTypesResult.close();
195207
}
196208
}
197-
finally
198-
{
199-
docTypesResult.close();
200-
}
201-
}
202-
203-
QuerySolutionMap thisQsm = new QuerySolutionMap();
204-
thisQsm.add(SPIN.THIS_VAR_NAME, accessTo);
205-
ResultSetRewindable docTypesResult = loadResultSet(getApplication().get().getService(), getDocumentTypeQuery(), thisQsm);
206-
try
207-
{
209+
208210
ParameterizedSparqlString pss = getApplication().get().canAs(EndUserApplication.class) ? getACLQuery() : getOwnerACLQuery();
209211
if (docTypesResult.hasNext())
210212
{
211213
Query query = new SetResultSetValues().apply(pss.asQuery(), docTypesResult);
212-
pss = new ParameterizedSparqlString(query.toString()); // make sure VALUES are now part of the query string
214+
pss = new ParameterizedSparqlString(query.toString()); // make sure type VALUES are now part of the query string
213215
assert pss.toString().contains("VALUES");
214216
}
215217

0 commit comments

Comments
 (0)