|
20 | 20 | */ |
21 | 21 | package eu.openanalytics.containerproxy.auth.impl; |
22 | 22 |
|
| 23 | +import java.util.ArrayList; |
23 | 24 | import java.util.Arrays; |
| 25 | +import java.util.List; |
24 | 26 |
|
25 | 27 | import javax.inject.Inject; |
26 | 28 |
|
@@ -73,13 +75,23 @@ private SimpleUser loadUser(int index) { |
73 | 75 | String userName = environment.getProperty(String.format("proxy.users[%d].name", index)); |
74 | 76 | if (userName == null) return null; |
75 | 77 | 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); |
79 | 83 | } 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])); |
81 | 94 | } |
82 | | - return new SimpleUser(userName, password, roles); |
83 | 95 | } |
84 | 96 |
|
85 | 97 | private static class SimpleUser { |
|
0 commit comments