File tree Expand file tree Collapse file tree 4 files changed +44
-7
lines changed
oak-jackrabbit-api/src/main/java/org/apache/jackrabbit/api
main/java/org/apache/jackrabbit/oak/jcr/session
test/java/org/apache/jackrabbit/oak/jcr/session Expand file tree Collapse file tree 4 files changed +44
-7
lines changed Original file line number Diff line number Diff line change 1616 */
1717package org .apache .jackrabbit .api ;
1818
19- import org . apache . jackrabbit . api . security .user . UserManager ;
20- import org . apache . jackrabbit . api . security . principal . PrincipalManager ;
19+ import java . security .Principal ;
20+ import java . util . Set ;
2121
22+ import javax .jcr .AccessDeniedException ;
2223import javax .jcr .Item ;
2324import javax .jcr .ItemNotFoundException ;
2425import javax .jcr .Node ;
2526import javax .jcr .Property ;
26- import javax .jcr .Session ;
27- import javax .jcr .AccessDeniedException ;
2827import javax .jcr .RepositoryException ;
28+ import javax .jcr .Session ;
2929import javax .jcr .UnsupportedRepositoryOperationException ;
3030
31+ import org .apache .jackrabbit .api .security .principal .PrincipalManager ;
32+ import org .apache .jackrabbit .api .security .user .UserManager ;
3133import org .jetbrains .annotations .NotNull ;
3234import org .jetbrains .annotations .Nullable ;
3335import org .osgi .annotation .versioning .ProviderType ;
@@ -277,4 +279,12 @@ default Node getParentOrNull(@NotNull Item item) throws RepositoryException {
277279 return null ;
278280 }
279281 }
282+
283+ /**
284+ * Returns the set of principals associated with this session.
285+ * @return the set of principals associated with this session.
286+ * @throws RepositoryException in case principal information cannot be retrieved.
287+ * @since 1.78
288+ */
289+ @ NotNull Set <Principal > getPrincipals () throws RepositoryException ;
280290}
Original file line number Diff line number Diff line change 1818/**
1919 * Jackrabbit extensions for JCR core interfaces
2020 */
21- @ org .osgi .annotation .versioning .Version ("2.9 .0" )
21+ @ org .osgi .annotation .versioning .Version ("2.10 .0" )
2222package org .apache .jackrabbit .api ;
2323
Original file line number Diff line number Diff line change 2424import java .io .InputStream ;
2525import java .io .OutputStream ;
2626import java .security .AccessControlException ;
27+ import java .security .Principal ;
2728import java .util .Collections ;
2829import java .util .Set ;
2930import java .util .TreeSet ;
@@ -845,6 +846,12 @@ public UserManager getUserManager() throws RepositoryException {
845846 return sessionContext .getUserManager ();
846847 }
847848
849+ @ Override
850+ @ NotNull
851+ public Set <Principal > getPrincipals () throws RepositoryException {
852+ return sd .getAuthInfo ().getPrincipals ();
853+ }
854+
848855 @ Override
849856 public String toString () {
850857 if (isLive ()) {
Original file line number Diff line number Diff line change 3030
3131import static org .mockito .Mockito .mock ;
3232
33+ import java .security .Principal ;
34+ import java .util .Set ;
35+
3336public class JackrabbitSessionTest extends AbstractJCRTest {
3437
3538 private JackrabbitSession s ;
@@ -81,6 +84,23 @@ public void testGetParentOrNullImplMismatch() {
8184 // success
8285 }
8386 }
84-
85-
87+
88+ public void testGetPrincipalsForAdminSession () throws RepositoryException {
89+ Set <Principal > principals = s .getPrincipals ();
90+ assertNotNull (principals );
91+ assertTrue ("Admin principal expected" , principals .contains (s .getPrincipalManager ().getPrincipal ("admin" )));
92+ assertTrue ("Everyone principal expected" , principals .contains (s .getPrincipalManager ().getEveryone ()));
93+ }
94+
95+ public void testGetPrincipalsForGuestSession () throws RepositoryException {
96+ JackrabbitSession guest = (JackrabbitSession ) getHelper ().getRepository ().login (new GuestCredentials ());
97+ try {
98+ Set <Principal > principals = guest .getPrincipals ();
99+ assertNotNull (principals );
100+ assertFalse ("Admin principal not expected" , principals .contains (s .getPrincipalManager ().getPrincipal ("admin" )));
101+ assertTrue ("Everyone principal expected" , principals .contains (s .getPrincipalManager ().getEveryone ()));
102+ } finally {
103+ guest .logout ();
104+ }
105+ }
86106}
You can’t perform that action at this time.
0 commit comments