Skip to content

Commit 0f3c32c

Browse files
committed
remove slash in rego rule not mapper
1 parent 1b31fbd commit 0f3c32c

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

src/main/java/tech/stackable/hadoop/StackableGroupMapper.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Objects;
1515
import org.apache.hadoop.conf.Configuration;
1616
import org.apache.hadoop.security.GroupMappingServiceProvider;
17-
import org.apache.hadoop.util.Lists;
1817
import org.slf4j.Logger;
1918
import org.slf4j.LoggerFactory;
2019

@@ -114,32 +113,17 @@ public List<String> getGroups(String user) throws IOException {
114113

115114
String responseBody = response.body();
116115
LOG.debug("Response body [{}]", responseBody);
117-
List<String> groups = Lists.newArrayList();
118116

119117
@SuppressWarnings("unchecked")
120118
Map<String, Object> result =
121119
(Map<String, Object>) json.readValue(responseBody, HashMap.class).get(OPA_RESULT_FIELD);
122-
List<String> rawGroups = (List<String>) result.get(this.mappingGroupName);
123-
124-
for (String rawGroup : rawGroups) {
125-
groups.add(stripSlashes(rawGroup));
126-
}
120+
List<String> groups = (List<String>) result.get(this.mappingGroupName);
127121

128122
LOG.info("Groups for [{}]: [{}]", user, groups);
129123

130124
return groups;
131125
}
132126

133-
private static String stripSlashes(String s) {
134-
if (s.startsWith("/")) {
135-
s = s.substring(1);
136-
}
137-
if (s.endsWith("/")) {
138-
s = s.substring(0, s.length() - 1);
139-
}
140-
return s;
141-
}
142-
143127
/** Caches groups, no need to do that for this provider */
144128
@Override
145129
public void cacheGroupsRefresh() {

src/test/java/tech/stackable/hadoop/StackableGroupMapperTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public void testJsonMapper() throws JsonProcessingException {
1919
"{\n"
2020
+ " \"result\": {\n"
2121
+ " \"groups\": [\n"
22-
+ " \"/admin\",\n"
23-
+ " \"/superuser\"\n"
22+
+ " \"admin\",\n"
23+
+ " \"superuser\"\n"
2424
+ " ]\n"
2525
+ " ,\n"
2626
+ " \"users_by_name\": {\n"
@@ -61,7 +61,7 @@ public void testJsonMapper() throws JsonProcessingException {
6161
Map<String, List<String>> result =
6262
(Map<String, List<String>>) json.readValue(input, HashMap.class).get("result");
6363
List<String> groups = result.get("groups");
64-
Assert.assertEquals("/admin", groups.get(0));
65-
Assert.assertEquals("/superuser", groups.get(1));
64+
Assert.assertEquals("admin", groups.get(0));
65+
Assert.assertEquals("superuser", groups.get(1));
6666
}
6767
}

test/stack/05-opa.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ data:
1212
# this will return the group data in this form:
1313
# "result": {
1414
# "groups": [
15-
# "/admin",
16-
# "/superuser"
15+
# "admin",
16+
# "superuser"
1717
# ]
1818
# ...
19-
groups := users_by_name[input.username].groups
19+
groups := {g |
20+
raw = users_by_name[input.username].groups[_]
21+
g := trim(raw, "/")
22+
}
2023
2124
# returning data in the form presented by the UIF
2225
users_by_name := {

0 commit comments

Comments
 (0)