You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by "Amoratinos (via GitHub)" <gi...@apache.org> on 2025/06/25 10:53:51 UTC
[PR] OAK-11498: Added getPrincipals default implementation [jackrabbit-oak]
Amoratinos opened a new pull request, #2356:
URL: https://github.com/apache/jackrabbit-oak/pull/2356
(no comment)
--
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-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11498: Added getPrincipals default implementation [jackrabbit-oak]
Posted by "kwin (via GitHub)" <gi...@apache.org>.
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-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11498: Added getPrincipals default implementation [jackrabbit-oak]
Posted by "Amoratinos (via GitHub)" <gi...@apache.org>.
Amoratinos commented on PR #2356:
URL: https://github.com/apache/jackrabbit-oak/pull/2356#issuecomment-3005027441
If I'm not mistaken, adding log sentences need to introduce a new dependency that, at the moment, it's not. I'm a bit against it but I'm open to do if needed.
--
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-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OAK-11498: Added getPrincipals default implementation [jackrabbit-oak]
Posted by "Amoratinos (via GitHub)" <gi...@apache.org>.
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: oak-dev-unsubscribe@jackrabbit.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org