Skip to content

Commit 0d3d149

Browse files
committed
Reserve admin webid for internal use
1 parent 2bccfa7 commit 0d3d149

File tree

7 files changed

+38
-6
lines changed

7 files changed

+38
-6
lines changed

components/app-triplestore/src/test/java/org/trellisldp/app/triplestore/TrellisApplicationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ public String getUser2Credentials() {
239239
return "user:password";
240240
}
241241

242+
@Override
243+
public String getAdminWebId() {
244+
return "http://admin.example.com/#me";
245+
}
246+
242247
@Override
243248
public String getJwtSecret() {
244249
return TrellisApplicationTest.this.JWT_KEY;

components/app-triplestore/src/test/resources/trellis-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ baseUrl:
2727
hubUrl:
2828

2929
auth:
30+
adminUsers: ["http://admin.example.com/#me"]
3031
webac:
3132
enabled: true
3233
jwt:

components/test/src/main/java/org/trellisldp/test/AbstractApplicationAuthTests.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.junit.jupiter.api.Nested;
3838
import org.junit.jupiter.api.TestInstance;
3939
import org.trellisldp.vocabulary.LDP;
40-
import org.trellisldp.vocabulary.Trellis;
4140

4241
/**
4342
* A convenience class for running the Auth tests.
@@ -74,15 +73,20 @@ public abstract class AbstractApplicationAuthTests {
7473
*/
7574
public abstract String getUser2Credentials();
7675

76+
/**
77+
* Get the WebID for an admin-level user.
78+
* @return the admin webid
79+
*/
80+
public abstract String getAdminWebId();
81+
7782
@Nested
7883
@DisplayName("Administrator JWT Auth tests")
7984
@TestInstance(PER_CLASS)
8085
public class AdministratorTests extends BasicTests implements AuthAdministratorTests {
8186

8287
@Override
8388
public String getAuthorizationHeader() {
84-
return buildJwt(Trellis.AdministratorAgent.getIRIString(),
85-
AbstractApplicationAuthTests.this.getJwtSecret());
89+
return buildJwt(getAdminWebId(), AbstractApplicationAuthTests.this.getJwtSecret());
8690
}
8791
}
8892

@@ -258,8 +262,7 @@ private void setGroupContainerChild(final String location) {
258262
protected void setUp() {
259263
final String acl = "acl";
260264
final String prefixAcl = "PREFIX acl: <http://www.w3.org/ns/auth/acl#>\n\n";
261-
final String jwt = buildJwt(Trellis.AdministratorAgent.getIRIString(),
262-
AbstractApplicationAuthTests.this.getJwtSecret());
265+
final String jwt = buildJwt(getAdminWebId(), AbstractApplicationAuthTests.this.getJwtSecret());
263266

264267
final String containerContent = getResourceAsString("/basicContainer.ttl");
265268
final String container;

core/http/src/main/java/org/trellisldp/http/AgentAuthorizationFilter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import javax.ws.rs.core.SecurityContext;
3434
import javax.ws.rs.ext.Provider;
3535

36+
import org.apache.commons.rdf.api.IRI;
3637
import org.slf4j.Logger;
3738
import org.trellisldp.api.AgentService;
3839
import org.trellisldp.http.impl.HttpSession;
@@ -91,7 +92,13 @@ public void filter(final ContainerRequestContext ctx) throws IOException {
9192
if (adminUsers.contains(name)) {
9293
ctx.setProperty(SESSION_PROPERTY, new HttpSession(AdministratorAgent));
9394
} else {
94-
ctx.setProperty(SESSION_PROPERTY, new HttpSession(agentService.asAgent(name)));
95+
final IRI webid = agentService.asAgent(name);
96+
// don't permit admin agent to be generated from the agent service
97+
if (AdministratorAgent.equals(webid)) {
98+
ctx.setProperty(SESSION_PROPERTY, new HttpSession());
99+
} else {
100+
ctx.setProperty(SESSION_PROPERTY, new HttpSession(webid));
101+
}
95102
}
96103
}
97104

core/http/src/test/java/org/trellisldp/http/AgentAuthorizationFilterTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,14 @@ public void testFilterMissingAgent() throws Exception {
7171
verify(mockContext).setProperty(eq(SESSION_PROPERTY), sessionArgument.capture());
7272
assertEquals(Trellis.AnonymousAgent, sessionArgument.getValue().getAgent(), "Unexpected agent IRI!");
7373
}
74+
75+
@Test
76+
public void testFilterAdminAgent() throws Exception {
77+
when(mockPrincipal.getName()).thenReturn("admin");
78+
when(mockAgentService.asAgent(any())).thenReturn(Trellis.AdministratorAgent);
79+
final AgentAuthorizationFilter filter = new AgentAuthorizationFilter(mockAgentService);
80+
filter.filter(mockContext);
81+
verify(mockContext).setProperty(eq(SESSION_PROPERTY), sessionArgument.capture());
82+
assertEquals(Trellis.AnonymousAgent, sessionArgument.getValue().getAgent(), "Unexpected agent IRI!");
83+
}
7484
}

platform/webapp/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ test {
5757
systemProperty 'trellis.namespaces.path', "$buildDir/namespaces.json"
5858
systemProperty 'trellis.io.jsonld.profiles', 'http://www.w3.org/ns/anno.jsonld'
5959
systemProperty 'trellis.triplestore.rdf.location', "$buildDir/data/rdf-" + new Random().nextInt(1000)
60+
systemProperty 'trellis.http.agent.adminusers', 'http://admin.example.com/#me'
6061
}

platform/webapp/src/test/java/org/trellisldp/webapp/TrellisApplicationTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public String getUser2Credentials() {
118118
public String getJwtSecret() {
119119
return "EEPPbd/7llN/chRwY2UgbdcyjFdaGjlzaupd3AIyjcu8hMnmMCViWoPUBb5FphGLxBlUlT/G5WMx0WcDq/iNKA==";
120120
}
121+
122+
@Override
123+
public String getAdminWebId() {
124+
return "http://admin.example.com/#me";
125+
}
121126
}
122127

123128
@Nested

0 commit comments

Comments
 (0)