Amoratinos commented on code in PR #2356:
URL: https://github.com/apache/jackrabbit-oak/pull/2356#discussion_r2166512496
##########
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:
I tried but PrincipalIterator is a raw iterator so it cannot use
`principals::add` without doing an explicit cast to principal
--
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]