kwin commented on code in PR #2356: URL: https://github.com/apache/jackrabbit-oak/pull/2356#discussion_r2166439935
########## oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api/JackrabbitSession.java: ########## @@ -284,9 +287,33 @@ default Node getParentOrNull(@NotNull Item item) throws RepositoryException { * Returns the set of principals associated with this session. * @return the set of principals associated with this session. * @throws RepositoryException in case principal information cannot be retrieved. + * @throws IllegalStateException if user information is not available or if the user is a system user. * @since 1.81 */ - @NotNull Set<Principal> getPrincipals() throws RepositoryException; + @NotNull default Set<Principal> getPrincipals() throws RepositoryException { + String userId = getUserID(); + if (userId == null) { + throw new IllegalStateException("No user ID associated with this session."); + } + + Authorizable authorizable = getUserManager().getAuthorizable(userId); + if (authorizable == null) { + throw new IllegalStateException("No authorizable found for user ID: " + userId); + } + + if (!authorizable.isGroup() && ((User) authorizable).isSystemUser()) { + throw new IllegalStateException("Unable to calculate effective set of principals for system user " + userId); + } + + Principal userPrincipal = authorizable.getPrincipal(); + Set<Principal> principals = new java.util.HashSet<>(); + principals.add(userPrincipal); + PrincipalIterator iterator = getPrincipalManager().getGroupMembership(userPrincipal); Review Comment: maybe use `.forEachRemaining(principals::add)` -- 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: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org