mneethiraj commented on code in PR #671:
URL: https://github.com/apache/ranger/pull/671#discussion_r2353683026
##########
agents-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerRequestScriptEvaluator.java:
##########
@@ -1160,124 +1030,75 @@ private Map<String, String> copyMap(Map<String,
String> obj) {
}
private List<Object> getUgAttr(String attrName) {
- List<Object> ret = new ArrayList<>();
-
- for (String groupName : userGroups) {
- Map<String, String> attrs = groupAttrs.get(groupName);
- Object val = attrs != null ? attrs.get(attrName) :
null;
-
- if (val != null) {
- ret.add(val);
- }
- }
-
- return ret;
+ return userGroups.stream()
+ .map(groupAttrs::get)
+ .filter(Objects::nonNull)
+ .map(attrs -> attrs.get(attrName))
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
}
private List<Object> getTagAttr(String attrName) {
- List<Object> ret = new ArrayList<>();
-
- for (String tagName : tagNames) {
- Map<String, Object> attrs = tags.get(tagName);
- Object val = attrs != null ? attrs.get(attrName) :
null;
-
- if (val != null) {
- ret.add(val);
- }
- }
-
- return ret;
+ return tagNames.stream()
+ .map(tags::get)
+ .filter(Objects::nonNull)
+ .map(attrs -> attrs.get(attrName))
+ .filter(Objects::nonNull)
+ .collect(Collectors.toList());
}
private Collection<String> getUserAttrNames() {
Collection<String> ret = getSorted(userAttrs.keySet());
- if (ret.contains(SCRIPT_FIELD__NAME)) {
+ if (ret.contains(SCRIPT_FIELD__NAME)) { // this is needed to avoid
calling remove() on unmodifiable collection
ret.remove(SCRIPT_FIELD__NAME);
}
Review Comment:
Good point. Addressed this in a subsequent commit in this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]