use of org.apache.jackrabbit.oak.spi.security.authentication.LoginContext in project jackrabbit-oak by apache.
the class LoginContextProviderImplTest method testGetLoginContextWithInvalidProviderConfig.
@Test
public void testGetLoginContextWithInvalidProviderConfig() throws Exception {
ConfigurationParameters params = ConfigurationParameters.of(AuthenticationConfiguration.PARAM_CONFIG_SPI_NAME, "invalid");
LoginContextProvider provider = new LoginContextProviderImpl(AuthenticationConfiguration.DEFAULT_APP_NAME, params, getContentRepository(), getSecurityProvider(), new DefaultWhiteboard());
// invalid configuration falls back to default configuration
LoginContext ctx = provider.getLoginContext(new SimpleCredentials(getTestUser().getID(), getTestUser().getID().toCharArray()), null);
ctx.login();
}
use of org.apache.jackrabbit.oak.spi.security.authentication.LoginContext in project jackrabbit-oak by apache.
the class LoginContextProviderImplTest method getLoginContextWithoutCredentials.
@Test
public void getLoginContextWithoutCredentials() throws Exception {
LoginContext ctx = lcProvider.getLoginContext(null, root.getContentSession().getWorkspaceName());
assertNotNull(ctx);
assertTrue(ctx instanceof JaasLoginContext);
}
use of org.apache.jackrabbit.oak.spi.security.authentication.LoginContext in project jackrabbit-oak by apache.
the class ContentRepositoryImpl method login.
@Nonnull
@Override
public ContentSession login(Credentials credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException {
if (workspaceName == null) {
workspaceName = defaultWorkspaceName;
}
// TODO: support multiple workspaces. See OAK-118
if (!defaultWorkspaceName.equals(workspaceName)) {
throw new NoSuchWorkspaceException(workspaceName);
}
LoginContextProvider lcProvider = securityProvider.getConfiguration(AuthenticationConfiguration.class).getLoginContextProvider(this);
LoginContext loginContext = lcProvider.getLoginContext(credentials, workspaceName);
loginContext.login();
return new ContentSessionImpl(loginContext, securityProvider, workspaceName, nodeStore, commitHook, queryEngineSettings, indexProvider);
}
use of org.apache.jackrabbit.oak.spi.security.authentication.LoginContext in project jackrabbit-oak by apache.
the class LoginContextProviderImplTest method testGetLoginContextTwice.
@Test
public void testGetLoginContextTwice() throws Exception {
Configuration.setConfiguration(new Configuration() {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String applicationName) {
return new AppConfigurationEntry[] { new AppConfigurationEntry(GuestLoginModule.class.getName(), AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL, new HashMap()) };
}
});
LoginContextProvider provider = new LoginContextProviderImpl(AuthenticationConfiguration.DEFAULT_APP_NAME, ConfigurationParameters.EMPTY, getContentRepository(), getSecurityProvider(), new DefaultWhiteboard());
provider.getLoginContext(null, null);
LoginContext ctx = provider.getLoginContext(null, null);
ctx.login();
assertFalse(ctx.getSubject().getPublicCredentials(GuestCredentials.class).isEmpty());
}
use of org.apache.jackrabbit.oak.spi.security.authentication.LoginContext in project jackrabbit-oak by apache.
the class LoginContextProviderImplTest method testGetPreAuthLoginContext.
@Test
public void testGetPreAuthLoginContext() {
Subject subject = new Subject(true, ImmutableSet.<Principal>of(), ImmutableSet.of(), ImmutableSet.of());
LoginContext ctx = Subject.doAs(subject, new PrivilegedAction<LoginContext>() {
@Override
public LoginContext run() {
try {
return lcProvider.getLoginContext(null, null);
} catch (LoginException e) {
throw new RuntimeException();
}
}
});
assertTrue(ctx instanceof PreAuthContext);
assertSame(subject, ctx.getSubject());
}
Aggregations