Skip to content

Commit f74fdce

Browse files
authored
JCL-360: Add acl property to Metadata class in solid module (#471)
1 parent 90710df commit f74fdce

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

solid/src/main/java/com/inrupt/client/solid/Metadata.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
public class Metadata {
3434

35+
private final URI acl;
3536
private final URI storage;
3637
private final Set<URI> type = new HashSet<>();
3738
private final Map<String, Set<String>> wacAllow = new HashMap<>();
@@ -71,6 +72,15 @@ public Map<String, Set<String>> getWacAllow() {
7172
return wacAllow;
7273
}
7374

75+
/**
76+
* The access control resource location.
77+
*
78+
* @return the access control resource location, if present
79+
*/
80+
public Optional<URI> getAcl() {
81+
return Optional.ofNullable(acl);
82+
}
83+
7484
/**
7585
* The supported HTTP methods for the associated resource.
7686
*
@@ -133,9 +143,23 @@ public String getContentType() {
133143
*
134144
* @param storage the Solid storage in which this resource is managed
135145
* @param contentType the content type of the respective Solid resource
146+
* @deprecated as of Beta3, please use the 3-parameter constructor
136147
*/
148+
@Deprecated
137149
protected Metadata(final URI storage, final String contentType) {
150+
this(storage, null, contentType);
151+
}
152+
153+
/**
154+
* Create a new Metadata object.
155+
*
156+
* @param storage the Solid storage in which this resource is managed
157+
* @param acl the ACL location for this resource
158+
* @param contentType the content type of the respective Solid resource
159+
*/
160+
protected Metadata(final URI storage, final URI acl, final String contentType) {
138161
this.storage = storage;
162+
this.acl = acl;
139163
this.contentType = contentType;
140164
}
141165

@@ -153,6 +177,7 @@ public static Builder newBuilder() {
153177
*/
154178
public static final class Builder {
155179

180+
private URI builderAcl;
156181
private URI builderStorage;
157182
private Set<URI> builderType = new HashSet<>();
158183
private Map<String, Set<String>> builderWacAllow = new HashMap<>();
@@ -195,6 +220,17 @@ public Builder wacAllow(final Map.Entry<String, Set<String>> accessParam) {
195220
return this;
196221
}
197222

223+
/**
224+
* Add an acl property.
225+
*
226+
* @param acl the acl location
227+
* @return this builder
228+
*/
229+
public Builder acl(final URI acl) {
230+
builderAcl = acl;
231+
return this;
232+
}
233+
198234
/**
199235
* Add an allowedMethod property.
200236
*
@@ -256,7 +292,7 @@ public Builder contentType(final String type) {
256292
* @return the resource Metadata object
257293
*/
258294
public Metadata build() {
259-
final Metadata metadata = new Metadata(builderStorage, builderContentType);
295+
final Metadata metadata = new Metadata(builderStorage, builderAcl, builderContentType);
260296
metadata.wacAllow.putAll(builderWacAllow);
261297
metadata.type.addAll(builderType);
262298
metadata.allowedMethods.addAll(builderAllowedMethods);

solid/src/main/java/com/inrupt/client/solid/SolidResourceHandlers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ static Metadata buildMetadata(final URI uri, final Headers headers) {
101101
metadata.storage(uri);
102102
}
103103
metadata.type(link.getUri());
104+
} else if (link.getParameter("rel").contains("acl")) {
105+
metadata.acl(link.getUri());
104106
} else if (link.getParameter("rel").contains(PIM.storage.toString())) {
105107
metadata.storage(link.getUri());
106108
}

solid/src/test/java/com/inrupt/client/solid/SolidMockHttpService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private void setupMocks() {
5454
.withStatus(200)
5555
.withHeader("Content-Type", "text/turtle")
5656
.withHeader("Link", Link.of(LDP.BasicContainer, "type").toString())
57+
.withHeader("Link", Link.of(URI.create("http://acl.example/"), "acl").toString())
5758
.withHeader("Link", Link.of(
5859
URI.create(PIM.getNamespace() + "Storage"),
5960
"type").toString())
@@ -66,6 +67,7 @@ private void setupMocks() {
6667
.withStatus(200)
6768
.withHeader("Content-Type", "text/turtle")
6869
.withHeader("Link", Link.of(LDP.BasicContainer, "type").toString())
70+
.withHeader("Link", Link.of(URI.create("http://acl.example/solid/"), "acl").toString())
6971
.withHeader("Link", Link.of(URI.create("http://storage.example/"),
7072
PIM.storage).toString())
7173
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
@@ -84,6 +86,7 @@ private void setupMocks() {
8486
.withStatus(200)
8587
.withHeader("Content-Type", "text/turtle")
8688
.withHeader("Link", Link.of(LDP.RDFSource, "type").toString())
89+
.withHeader("Link", Link.of(URI.create("http://acl.example/recipe"), "acl").toString())
8790
.withHeader("Link", Link.of(URI.create("http://storage.example/"),
8891
PIM.storage).toString())
8992
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
@@ -103,6 +106,7 @@ private void setupMocks() {
103106
.withHeader("Content-Type", "text/turtle")
104107
.withHeader("Link", Link.of(LDP.RDFSource, "type").toString())
105108
.withHeader("Link", Link.of(URI.create("http://storage.example/"), PIM.storage).toString())
109+
.withHeader("Link", Link.of(URI.create("http://acl.example/custom-agent"), "acl").toString())
106110
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
107111
.withHeader("WAC-Allow", "user=\"read write\",public=\"read\"")
108112
.withHeader("Allow", "POST, PUT, PATCH")
@@ -136,6 +140,7 @@ private void setupMocks() {
136140
.withHeader("Link", Link.of(URI.create("http://storage.example/"),
137141
PIM.storage).toString())
138142
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
143+
.withHeader("Link", Link.of(URI.create("http://acl.example/playlist"), "acl").toString())
139144
.withHeader("WAC-Allow", "user=\"read write\",public=\"read\"")
140145
.withHeader("Allow", "POST, PUT, PATCH")
141146
.withHeader("Accept-Post", "application/ld+json, text/turtle")
@@ -171,6 +176,7 @@ private void setupMocks() {
171176
.willReturn(aResponse()
172177
.withStatus(200)
173178
.withHeader("Content-Type", "text/plain")
179+
.withHeader("Link", Link.of(URI.create("http://acl.example/binary"), "acl").toString())
174180
.withBody("This is a plain text document.")));
175181

176182
wireMockServer.stubFor(put(urlEqualTo("/binary"))
@@ -191,6 +197,7 @@ private void setupMocks() {
191197
.willReturn(aResponse()
192198
.withStatus(200)
193199
.withHeader("Content-Type", "text/turtle")
200+
.withHeader("Link", Link.of(URI.create("http://acl.example/nonRDF"), "acl").toString())
194201
.withBody("This isn't valid turtle.")));
195202

196203
wireMockServer.stubFor(get(urlEqualTo("/missing"))

solid/src/test/java/com/inrupt/client/solid/SolidRDFSourceTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void testGetOfSolidRDFSource() throws IOException, InterruptedException {
7676
try (final SolidRDFSource resource = response.body()) {
7777
assertEquals(uri, resource.getIdentifier());
7878
assertTrue(resource.getMetadata().getType().contains(LDP.BasicContainer));
79+
assertEquals(Optional.of(URI.create("http://acl.example/solid/")),
80+
resource.getMetadata().getAcl());
7981
assertEquals(Optional.of(URI.create("http://storage.example/")),
8082
resource.getMetadata().getStorage());
8183
assertTrue(resource.getMetadata().getWacAllow().get("user")
@@ -114,6 +116,8 @@ void testCheckRootOfSolidRDFSource() throws IOException, InterruptedException {
114116
try (final SolidRDFSource resource = response.body()) {
115117
assertEquals(uri, resource.getIdentifier());
116118
assertTrue(resource.getMetadata().getType().contains(LDP.BasicContainer));
119+
assertEquals(Optional.of(URI.create("http://acl.example/")),
120+
resource.getMetadata().getAcl());
117121
assertEquals(Optional.of(uri), resource.getMetadata().getStorage());
118122
}
119123
}
@@ -157,6 +161,7 @@ void testEmptyResourceBuilder() {
157161
final URI id = URI.create("https://resource.example/");
158162
try (final SolidRDFSource res = new SolidRDFSource(id, null, null)) {
159163
assertFalse(res.getMetadata().getStorage().isPresent());
164+
assertFalse(res.getMetadata().getAcl().isPresent());
160165
assertTrue(res.getMetadata().getAllowedPatchSyntaxes().isEmpty());
161166
assertEquals(0, res.size());
162167
assertEquals(id, res.getIdentifier());
@@ -168,6 +173,7 @@ void testEmptyContainerBuilder() {
168173
final URI id = URI.create("https://resource.example/");
169174
try (final SolidContainer res = new SolidContainer(id, null, null)) {
170175
assertFalse(res.getMetadata().getStorage().isPresent());
176+
assertFalse(res.getMetadata().getAcl().isPresent());
171177
assertTrue(res.getMetadata().getAllowedPatchSyntaxes().isEmpty());
172178
assertEquals(0, res.size());
173179
assertEquals(id, res.getIdentifier());

0 commit comments

Comments
 (0)