Skip to content

Commit 353c29a

Browse files
committed
Fix #30071: support YAML arrays in groups setting
1 parent 6ce41c8 commit 353c29a

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/main/java/eu/openanalytics/containerproxy/auth/impl/SimpleAuthenticationBackend.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
*/
2121
package eu.openanalytics.containerproxy.auth.impl;
2222

23+
import java.util.ArrayList;
2324
import java.util.Arrays;
25+
import java.util.List;
2426

2527
import javax.inject.Inject;
2628

@@ -73,13 +75,23 @@ private SimpleUser loadUser(int index) {
7375
String userName = environment.getProperty(String.format("proxy.users[%d].name", index));
7476
if (userName == null) return null;
7577
String password = environment.getProperty(String.format("proxy.users[%d].password", index));
76-
String[] roles = environment.getProperty(String.format("proxy.users[%d].groups", index), String[].class);
77-
if (roles == null) {
78-
roles = new String[0];
78+
79+
// method 1: single property with comma seperated groups
80+
String[] groups = environment.getProperty(String.format("proxy.users[%d].groups", index), String[].class);
81+
if (groups != null) {
82+
return new SimpleUser(userName, password, groups);
7983
} else {
80-
roles = Arrays.stream(roles).map(s -> s.toUpperCase()).toArray(i -> new String[i]);
84+
// method 2: YAML array
85+
List<String> groupsList = new ArrayList<>();
86+
int groupIndex = 0;
87+
String group = environment.getProperty(String.format("proxy.users[%d].groups[%d]", index, groupIndex));
88+
while (group != null) {
89+
groupsList.add(group);
90+
groupIndex++;
91+
group = environment.getProperty(String.format("proxy.users[%d].groups[%d]", index, groupIndex));
92+
}
93+
return new SimpleUser(userName, password, groupsList.toArray(new String[0]));
8194
}
82-
return new SimpleUser(userName, password, roles);
8395
}
8496

8597
private static class SimpleUser {

0 commit comments

Comments
 (0)