Skip to content

Commit 9e394d0

Browse files
author
Lucianos Lionakis
committed
add support for making users admin
1 parent 7bc9b2c commit 9e394d0

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/service/UserService.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ public String[] getAdminGroups() {
103103

104104
return adminGroups.toArray(new String[adminGroups.size()]);
105105
}
106+
107+
public String[] getAdminUsers() {
108+
Set<String> adminUsers = new HashSet<>();
109+
110+
// Support for old, non-array notation
111+
String singleUser = environment.getProperty("proxy.admin-users");
112+
if (singleUser != null && !singleUser.isEmpty()) adminUsers.add(singleUser);
113+
114+
for (int i=0 ;; i++) {
115+
String userName = environment.getProperty(String.format("proxy.admin-users[%s]", i));
116+
if (userName == null || userName.isEmpty()) break;
117+
adminUsers.add(userName);
118+
}
119+
120+
return adminUsers.toArray(new String[adminUsers.size()]);
121+
}
106122

107123
public String[] getGroups() {
108124
return getGroups(getCurrentAuth());
@@ -125,9 +141,18 @@ public boolean isAdmin() {
125141
}
126142

127143
public boolean isAdmin(Authentication auth) {
144+
if (!authBackend.hasAuthorization()) {
145+
return false;
146+
}
147+
128148
for (String adminGroup: getAdminGroups()) {
129149
if (isMember(auth, adminGroup)) return true;
130150
}
151+
152+
String userName = getUserId(auth);
153+
for (String adminUser: getAdminUsers()) {
154+
if (userName != null && userName.equals(adminUser)) return true;
155+
}
131156
return false;
132157
}
133158

0 commit comments

Comments
 (0)