Skip to content

Commit 474bf4d

Browse files
committed
Add support for admin user group
1 parent 5bb309e commit 474bf4d

File tree

7 files changed

+43
-3
lines changed

7 files changed

+43
-3
lines changed

components/app/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ namespaces: /path/to/namespaces.json
5151

5252
```yaml
5353
auth:
54+
adminUsers: []
5455
webac:
5556
enabled: true
5657
anon:
@@ -66,6 +67,7 @@ auth:
6667

6768
| Name | Default | Description |
6869
| ---- | ------- | ----------- |
70+
| adminUsers | (none) | A list of webIDs that should be given admin access for the purpose of authorization |
6971
| webac / enabled | true | Whether WebAC authorization is enabled |
7072
| anon / enabled | false | Whether anonymous authentication is enabled |
7173
| jwt / enabled | true | Whether jwt authentication is enabled |

components/app/src/main/java/org/trellisldp/app/AbstractTrellisApplication.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ public void run(final T config, final Environment environment) throws Exception
117117
getMultipartUploadService().ifPresent(uploader -> environment.jersey()
118118
.register(new MultipartUploader(getResourceService(), uploader, config.getBaseUrl())));
119119

120+
// Authentication
121+
final AgentAuthorizationFilter agentFilter = new AgentAuthorizationFilter(agentService);
122+
agentFilter.setAdminUsers(config.getAuth().getAdminUsers());
123+
120124
// Filters
121-
environment.jersey().register(new AgentAuthorizationFilter(agentService));
125+
environment.jersey().register(agentFilter);
122126
environment.jersey().register(new CacheControlFilter(config.getCache().getMaxAge(),
123127
config.getCache().getMustRevalidate(), config.getCache().getNoCache()));
124128

components/app/src/main/java/org/trellisldp/app/config/AuthConfiguration.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
import com.fasterxml.jackson.annotation.JsonProperty;
1717

18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
import javax.validation.constraints.NotNull;
22+
1823
/**
1924
* Configuration for authN/authZ.
2025
*/
@@ -24,6 +29,27 @@ public class AuthConfiguration {
2429
private WebacConfiguration webac = new WebacConfiguration();
2530
private AnonAuthConfiguration anon = new AnonAuthConfiguration();
2631

32+
@NotNull
33+
private List<String> adminUsers = new ArrayList<>();
34+
35+
/**
36+
* Set the admin users.
37+
* @param adminUsers the admin users
38+
*/
39+
@JsonProperty
40+
public void setAdminUsers(final List<String> adminUsers) {
41+
this.adminUsers = adminUsers;
42+
}
43+
44+
/**
45+
* Get the admin users.
46+
* @return the admin users
47+
*/
48+
@JsonProperty
49+
public List<String> getAdminUsers() {
50+
return adminUsers;
51+
}
52+
2753
/**
2854
* Set the basic auth configuration.
2955
* @param basic the basic auth config

components/app/src/test/java/org/trellisldp/app/config/TrellisConfigurationTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public void testConfigurationGeneral1() throws Exception {
4949
assertTrue(config.getJsonld().getContextDomainWhitelist().isEmpty());
5050
assertTrue(config.getJsonld().getContextWhitelist().contains("http://example.org/context.json"));
5151
assertNull(config.getResources());
52+
assertTrue(config.getAuth().getAdminUsers().contains("daiyu"));
53+
assertTrue(config.getAuth().getAdminUsers().contains("baoyu"));
5254
assertEquals("http://hub.example.com/", config.getHubUrl());
5355
assertEquals((Integer) 2, config.getBinaryHierarchyLevels());
5456
assertEquals((Integer) 1, config.getBinaryHierarchyLength());

components/app/src/test/resources/config1.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ hubUrl: http://hub.example.com/
2020
namespaces: /tmp/trellisData/namespaces.json
2121

2222
auth:
23+
adminUsers:
24+
- baoyu
25+
- daiyu
2326
webac:
2427
enabled: true
2528
cacheSize: 100

platform/linux/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ namespaces: /path/to/namespaces.json
120120

121121
```yaml
122122
auth:
123+
adminUsers: []
123124
webac:
124125
enabled: true
125126
anon:
@@ -135,6 +136,7 @@ auth:
135136

136137
| Name | Default | Description |
137138
| ---- | ------- | ----------- |
139+
| adminUsers | (none) | A list of webIDs that should be given admin access for the purpose of authorization |
138140
| webac / enabled | true | Whether WebAC authorization is enabled |
139141
| anon / enabled | false | Whether anonymous authentication is enabled |
140142
| jwt / enabled | true | Whether jwt authentication is enabled |

platform/linux/src/dist/etc/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ baseUrl:
4141
hubUrl:
4242

4343
auth:
44+
adminUsers: []
4445
webac:
4546
enabled: true
4647
anon:
4748
enabled: true
4849
jwt:
49-
enabled: true
50+
enabled: false
5051
base64Encoded: false
51-
key: secret
52+
key: changeme
5253
basic:
5354
enabled: true
5455
usersFile: /opt/trellis/etc/users.auth

0 commit comments

Comments
 (0)