[API] Best way to get all inherited parent groups
Closed this issue ยท 2 comments
hey,
what's the best way to get all inherited parent groups from a user performance wise?
I'm trying to check if a user has the group xyz
in any way (temporary, parent of inherited group...).
I tried user.data().contains(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME)
and collecting them all
Collection<String> groups = user.getNodes().stream()
.filter(NodeType.INHERITANCE::matches)
.map(NodeType.INHERITANCE::cast)
.map(InheritanceNode::getGroupName)
.collect(Collectors.toSet());
but I only get the groups which are directly assigned to the user.
I could loop over each group the user is assigned and then loop over that groups parent groups again but this is most likely not the best way to do it.
Oh, I found what I was looking for. Using user.resolveInheritedNodes()
instead of user.getNodes()
works.