Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fcrepo-2947 - Add ACL links #41

Merged
merged 1 commit into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/org/fcrepo/client/BodyRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.fcrepo.client.FedoraHeaderConstants.IF_MATCH;
import static org.fcrepo.client.FedoraHeaderConstants.IF_UNMODIFIED_SINCE;
import static org.fcrepo.client.FedoraHeaderConstants.LINK;
import static org.fcrepo.client.LinkHeaderConstants.ACL_REL;
import static org.fcrepo.client.LinkHeaderConstants.TYPE_REL;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_HANDLING;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_REL;
Expand Down Expand Up @@ -227,4 +228,20 @@ protected BodyRequestBuilder ifMatch(final String etag) {
}
return this;
}

/**
* Provide the URI to an ACL for this request
*
* @param aclUri URI to the ACL
* @return this builder
*/
protected BodyRequestBuilder linkAcl(final String aclUri) {
if (aclUri != null) {
final FcrepoLink link = FcrepoLink.fromUri(aclUri)
.rel(ACL_REL)
.build();
request.addHeader(LINK, link.toString());
}
return this;
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/fcrepo/client/LinkHeaderConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class LinkHeaderConstants {
// rel identifying the RDF resource describing this resource
public static final String DESCRIBEDBY_REL = "describedby";

// rel identifying the ACL for the resource
public static final String ACL_REL = "acl";

private LinkHeaderConstants() {
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/fcrepo/client/PostBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public PostBuilder addInteractionModel(final String interactionModelUri) {
return (PostBuilder) super.addInteractionModel(interactionModelUri);
}

@Override
protected PostBuilder linkAcl(final String aclUri) {
return (PostBuilder) super.linkAcl(aclUri);
}

/**
* Provide a content disposition header which will be used as the filename
*
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/fcrepo/client/PutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public PutBuilder addInteractionModel(final String interactionModelUri) {
return (PutBuilder) super.addInteractionModel(interactionModelUri);
}

@Override
protected PutBuilder linkAcl(final String aclUri) {
return (PutBuilder) super.linkAcl(aclUri);
}

/**
* Provide a content disposition header which will be used as the filename
*
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/fcrepo/client/PostBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.fcrepo.client.FedoraHeaderConstants.DIGEST;
import static org.fcrepo.client.FedoraHeaderConstants.SLUG;
import static org.fcrepo.client.FedoraTypes.LDP_DIRECT_CONTAINER;
import static org.fcrepo.client.LinkHeaderConstants.ACL_REL;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_HANDLING;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_REL;
import static org.fcrepo.client.LinkHeaderConstants.TYPE_REL;
Expand Down Expand Up @@ -211,4 +212,18 @@ public void testAddInteractionModel() throws Exception {
assertEquals(TYPE_REL, interLink.getRel());
assertEquals(LDP_DIRECT_CONTAINER, interLink.getUri().toString());
}

@Test
public void testLinkAcl() throws Exception {
testBuilder.linkAcl("http://localhost/acl")
.perform();

verify(client).executeRequest(eq(uri), requestCaptor.capture());

final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();

final FcrepoLink aclLink = new FcrepoLink(request.getFirstHeader(LINK).getValue());
assertEquals(ACL_REL, aclLink.getRel());
assertEquals("http://localhost/acl", aclLink.getUri().toString());
}
}
15 changes: 15 additions & 0 deletions src/test/java/org/fcrepo/client/PutBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.fcrepo.client.FedoraTypes.LDP_DIRECT_CONTAINER;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_HANDLING;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_REL;
import static org.fcrepo.client.LinkHeaderConstants.ACL_REL;
import static org.fcrepo.client.LinkHeaderConstants.TYPE_REL;
import static org.fcrepo.client.TestUtils.baseUrl;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -194,4 +195,18 @@ public void testAddInteractionModel() throws Exception {
assertEquals(TYPE_REL, interLink.getRel());
assertEquals(LDP_DIRECT_CONTAINER, interLink.getUri().toString());
}

@Test
public void testLinkAcl() throws Exception {
testBuilder.linkAcl("http://localhost/acl")
.perform();

verify(client).executeRequest(eq(uri), requestCaptor.capture());

final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();

final FcrepoLink aclLink = new FcrepoLink(request.getFirstHeader(LINK).getValue());
assertEquals(ACL_REL, aclLink.getRel());
assertEquals("http://localhost/acl", aclLink.getUri().toString());
}
}