AbstractLoginModule implements LoginModule { @Nullable protected Root getRoot() { if (root == null && callbackHandler != null) { try { final RepositoryCallback rcb = new RepositoryCallback(); callbackHandler.handle(new Callback[]{rcb}); final ContentRepository repository = rcb.getContentRepository(); if (repository != null) { systemSession = Subject.doAs(SystemSubject.INSTANCE, new PrivilegedExceptionAction<ContentSession>() { @Override public ContentSession run() throws LoginException, NoSuchWorkspaceException { return repository.login(null, rcb.getWorkspaceName()); } }); root = systemSession.getLatestRoot(); } else { log.error("Unable to retrieve the Root via RepositoryCallback; ContentRepository not available."); } } catch (IOException | UnsupportedCallbackException | PrivilegedActionException e) { onError(); log.error(e.getMessage(), e); } } return root; }  @Override void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options); @Override boolean logout(); @Override boolean abort(); static final String SHARED_KEY_CREDENTIALS; static final String SHARED_KEY_LOGIN_NAME; static final String SHARED_KEY_ATTRIBUTES; static final String SHARED_KEY_PRE_AUTH_LOGIN; }
@Test public void testGetRoot() throws Exception { AbstractLoginModule loginModule = initLoginModule(new TestCallbackHandler(mockContentRepository(null), null)); Root root = loginModule.getRoot(); assertNotNull(root); assertSame(root, loginModule.getRoot()); }
@Test public void testGetRootIOException() { LoginModuleStats stats = newLoginModuleStats(); AbstractLoginModule lm = initLoginModule(new ThrowingCallbackHandler(true), stats); assertNull(lm.getRoot()); assertEquals(1, stats.getLoginErrors()); }
@Test public void testGetRootUnsupportedCallbackException() { LoginModuleStats stats = newLoginModuleStats(); AbstractLoginModule lm = initLoginModule(new ThrowingCallbackHandler(false), stats); assertNull(lm.getRoot()); assertEquals(1, stats.getLoginErrors()); }
@Test public void testGetRootMissingCallbackHandler() { AbstractLoginModule loginModule = initLoginModule((CallbackHandler) null); assertNull(loginModule.getRoot()); }
@Test public void testGetSecurityProviderUnsupportedCallbackException() { AbstractLoginModule loginModule = initLoginModule(new ThrowingCallbackHandler(false)); assertNull(loginModule.getRoot()); }