private Key(AuthInfo authInfo, String revisionId) { this.user = authInfo.getUserID(); this.principals = authInfo.getPrincipals(); this.revisionId = revisionId; }
private Delegatee(@NotNull SyncHandler handler, @NotNull ExternalIdentityProvider idp, @NotNull ContentSession systemSession, @NotNull SecurityProvider securityProvider, int batchSize) { this.handler = handler; this.idp = idp; this.systemSession = systemSession; this.batchSize = batchSize; root = systemSession.getLatestRoot(); userMgr = securityProvider.getConfiguration(UserConfiguration.class).getUserManager(root, NamePathMapper.DEFAULT); context = handler.createContext(idp, userMgr, new ValueFactoryImpl(root, NamePathMapper.DEFAULT)); log.info("Created delegatee for SyncMBean with session: {} {}", systemSession, systemSession.getAuthInfo().getUserID()); }
private static <T> void logOperationDetails(ContentSession session, SessionOperation<T> ops) { if (readOperationLogger.isTraceEnabled() || writeOperationLogger.isTraceEnabled() || auditLogger.isDebugEnabled()) { Logger log = ops.isUpdate() ? writeOperationLogger : readOperationLogger; log.trace("[{}] {}", session, ops); //For a logout operation the auth info is not accessible if (!ops.isLogout() && !ops.isRefresh() && !ops.isSave() && ops.isUpdate()) { auditLogger.debug("[{}] [{}] {}", session.getAuthInfo().getUserID(), session, ops); } } }
private static <T> void logOperationDetails(ContentSession session, SessionOperation<T> ops) { if (readOperationLogger.isTraceEnabled() || writeOperationLogger.isTraceEnabled() || auditLogger.isDebugEnabled()) { Logger log = ops.isUpdate() ? writeOperationLogger : readOperationLogger; log.trace("[{}] {}", session, ops); //For a logout operation the auth info is not accessible if (!ops.isLogout() && !ops.isRefresh() && !ops.isSave() && ops.isUpdate()) { auditLogger.debug("[{}] [{}] {}", session.getAuthInfo().getUserID(), session, ops); } } }
@Test public void testCreateFromSubjectWithPrivateSimpleCredentials() { Subject subject = new Subject(); subject.getPrivateCredentials().add(new SimpleCredentials(USER_ID, new char[0])); AuthInfo info = AuthInfoImpl.createFromSubject(subject); assertNull(info.getUserID()); assertTrue(info.getPrincipals().isEmpty()); assertEquals(0, info.getAttributeNames().length); }
@Test public void testCreateFromSubjectWithPrincipals() { Subject subject = new Subject(); subject.getPrincipals().addAll(PRINCIPALS); AuthInfo info = AuthInfoImpl.createFromSubject(subject); assertNull(info.getUserID()); assertEquals(PRINCIPALS, info.getPrincipals()); assertEquals(0, info.getAttributeNames().length); }
@Test public void testCreateFromSubjectWithAnyCredentials() { Subject subject = new Subject(); subject.getPublicCredentials().add(new Credentials() { }); AuthInfo info = AuthInfoImpl.createFromSubject(subject); assertNull(info.getUserID()); assertTrue(info.getPrincipals().isEmpty()); assertEquals(0, info.getAttributeNames().length); } }
@Test public void testCreateAuthInfoFromEmptySubject() { AuthInfo info = AuthInfoImpl.createFromSubject(new Subject()); assertNull(info.getUserID()); assertEquals(0, info.getAttributeNames().length); assertTrue(info.getPrincipals().isEmpty()); } }
@Test public void testCreateFromSubjectWithSimpleCredentials() { Subject subject = new Subject(); subject.getPublicCredentials().add(new SimpleCredentials(USER_ID, new char[0])); AuthInfo info = AuthInfoImpl.createFromSubject(subject); assertEquals(USER_ID, info.getUserID()); assertTrue(info.getPrincipals().isEmpty()); assertEquals(0, info.getAttributeNames().length); }
@Test public void testGetPrincipals() throws Exception { String adminId = adminSession.getAuthInfo().getUserID(); Set<? extends Principal> principals = principalProvider.getPrincipals(adminId); assertNotNull(principals); assertFalse(principals.isEmpty()); assertTrue(principals.contains(EveryonePrincipal.getInstance())); for (Principal principal : principals) { assertNotNull(principalProvider.getPrincipal(principal.getName())); } }
@Test public void testCreateFromSubjectWithAuthInfo() { Subject subject = new Subject(); subject.getPublicCredentials().add(authInfo); AuthInfo info = AuthInfoImpl.createFromSubject(subject); assertEquals(USER_ID, info.getUserID()); assertEquals(PRINCIPALS, info.getPrincipals()); assertArrayEquals(authInfo.getAttributeNames(), info.getAttributeNames()); }
@Test public void testDifferentAnonymousID() throws Exception { // EXERCISE : use built-in oak configuration settings to have a different anonymous ID -> uncomment the configuration parameters in 'getSecurityConfigParameters' above testSession = login(new GuestCredentials()); String expectedId = null; // EXERCISE: write the expected ID assertEquals(expectedId, testSession.getAuthInfo().getUserID()); } }
@Test public void testLogin() throws LoginException, NoSuchWorkspaceException { String expectedId = null; // EXERCISE define the userID for the login Credentials creds = null; // EXERCISE define credentials that work in your setup. ContentSession s = login(creds); AuthInfo authInfo = s.getAuthInfo(); assertNotSame(AuthInfo.EMPTY, authInfo); assertEquals(expectedId, authInfo.getUserID()); } }
@Test public void testGuest() throws Exception { ContentSession cs = null; try { cs = login(new GuestCredentials()); assertEquals(UserConstants.DEFAULT_ANONYMOUS_ID, cs.getAuthInfo().getUserID()); } finally { if (cs != null) { cs.close(); } } }
@Test public void testGuestAuthInfo() throws LoginException, NoSuchWorkspaceException { contentSession = login(new GuestCredentials()); AuthInfo authInfo = contentSession.getAuthInfo(); String expectedId = null; // EXERCISE : fill in the expected id assertEquals(expectedId, authInfo.getUserID()); // EXERCISE: create the set of expected principals. // EXERCISE: what are the variants you have at hand when using the Jackrabbit API // EXERCISE: what are the variants you have at hand when using public Oak SPI interfaces? Set<Principal> expectedPrincipals = null; assertEquals(expectedPrincipals, authInfo.getPrincipals()); }
@Test public void testGuestLogin() throws Exception { try (ContentSession cs = login(new GuestCredentials())) { AuthInfo authInfo = cs.getAuthInfo(); String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters()); assertEquals(anonymousID, authInfo.getUserID()); } }
@Test public void testNullLogin() throws Exception { ContentSession cs = login(null); try { AuthInfo authInfo = cs.getAuthInfo(); String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters()); assertEquals(anonymousID, authInfo.getUserID()); } finally { cs.close(); } }
@Test public void testNullLogin() throws Exception { ContentSession cs = login(null); try { AuthInfo authInfo = cs.getAuthInfo(); String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters()); assertEquals(anonymousID, authInfo.getUserID()); } finally { cs.close(); } }
@Test public void testLogin() throws Exception { TestCredentials creds = new TestCredentials("testUser"); ContentSession cs = login(creds); try { AuthInfo info = cs.getAuthInfo(); assertEquals("testUser", info.getUserID()); assertAttributes(getCredentialsSupport().getAttributes(creds), info); } finally { cs.close(); } }
@Test public void testGuestLogin() throws Exception { ContentSession cs = login(new GuestCredentials()); try { AuthInfo authInfo = cs.getAuthInfo(); String anonymousID = UserUtil.getAnonymousId(getUserConfiguration().getParameters()); assertEquals(anonymousID, authInfo.getUserID()); } finally { cs.close(); } } }