Search in sources :

Example 1 with PreAuthContext

use of org.apache.jackrabbit.oak.spi.security.authentication.PreAuthContext in project jackrabbit-oak by apache.

the class LoginContextProviderImpl method getLoginContext.

@Override
@Nonnull
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());
}
Also used : CallbackHandler(javax.security.auth.callback.CallbackHandler) JaasLoginContext(org.apache.jackrabbit.oak.spi.security.authentication.JaasLoginContext) PreAuthContext(org.apache.jackrabbit.oak.spi.security.authentication.PreAuthContext) Subject(javax.security.auth.Subject) Nonnull(javax.annotation.Nonnull)

Example 2 with PreAuthContext

use of org.apache.jackrabbit.oak.spi.security.authentication.PreAuthContext 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());
}
Also used : JaasLoginContext(org.apache.jackrabbit.oak.spi.security.authentication.JaasLoginContext) LoginContext(org.apache.jackrabbit.oak.spi.security.authentication.LoginContext) PreAuthContext(org.apache.jackrabbit.oak.spi.security.authentication.PreAuthContext) LoginException(javax.security.auth.login.LoginException) Subject(javax.security.auth.Subject) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

Subject (javax.security.auth.Subject)2 JaasLoginContext (org.apache.jackrabbit.oak.spi.security.authentication.JaasLoginContext)2 PreAuthContext (org.apache.jackrabbit.oak.spi.security.authentication.PreAuthContext)2 Nonnull (javax.annotation.Nonnull)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 LoginException (javax.security.auth.login.LoginException)1 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)1 LoginContext (org.apache.jackrabbit.oak.spi.security.authentication.LoginContext)1 Test (org.junit.Test)1