LoginContextProviderImpl implements LoginContextProvider { @Override @NotNull public LoginContext getLoginContext(Credentials credentials, String workspaceName) throws LoginException { Subject subject = getSubject(); if (subject != null && credentials == null) { log.debug("Found pre-authenticated subject: No further login actions required."); return new PreAuthContext(subject); } if (subject == null) { subject = new Subject(); } CallbackHandler handler = getCallbackHandler(credentials, workspaceName); return new JaasLoginContext(appName, subject, handler, getConfiguration()); } LoginContextProviderImpl(String appName, ConfigurationParameters params,
                             ContentRepository contentRepository,
                             SecurityProvider securityProvider,
                             Whiteboard whiteboard,
                             LoginModuleMonitor loginModuleMonitor); @Override @NotNull LoginContext getLoginContext(Credentials credentials, String workspaceName);  }
@Test public void testGetLoginContext() throws Exception { LoginContext ctx = lcProvider.getLoginContext(new SimpleCredentials(getTestUser().getID(), getTestUser().getID().toCharArray()), root.getContentSession().getWorkspaceName()); Subject subject = ctx.getSubject(); assertNotNull(subject); assertFalse(subject.isReadOnly()); assertTrue(subject.getPrincipals().isEmpty()); }
@Test public void getLoginContextWithoutCredentials() throws Exception { LoginContext ctx = lcProvider.getLoginContext(null, root.getContentSession().getWorkspaceName()); assertNotNull(ctx); assertTrue(ctx instanceof JaasLoginContext); }
@Test public void testGetLoginContextWithInvalidProviderConfig() throws Exception { ConfigurationParameters params = ConfigurationParameters.of(AuthenticationConfiguration.PARAM_CONFIG_SPI_NAME, "invalid"); LoginContextProvider provider = newLoginContextProviderImpl(params); LoginContext ctx = provider.getLoginContext(new SimpleCredentials(getTestUser().getID(), getTestUser().getID().toCharArray()), null); ctx.login(); }
@Test(expected = LoginException.class) public void testGetLoginContextWithIncompleteProvider() throws Exception { String providerName = addProvider(false); ConfigurationParameters params = ConfigurationParameters.of(AuthenticationConfiguration.PARAM_CONFIG_SPI_NAME, providerName); LoginContextProvider provider = newLoginContextProviderImpl(params); LoginContext ctx = provider.getLoginContext(new SimpleCredentials(getTestUser().getID(), getTestUser().getID().toCharArray()), null); ctx.login(); }
@Test public void testGetLoginContextWithCompleteProvider() throws Exception { String providerName = addProvider(true); ConfigurationParameters params = ConfigurationParameters.of(AuthenticationConfiguration.PARAM_CONFIG_SPI_NAME, providerName); LoginContextProvider lcp = newLoginContextProviderImpl(params); LoginContext ctx = lcp.getLoginContext(null, adminSession.getWorkspaceName()); ctx.login(); }