Search in sources :

Example 1 with TokenConfiguration

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

the class Jackrabbit2ConfigurationTest method testValidTokenCredentials.

@Test
public void testValidTokenCredentials() throws Exception {
    Root root = adminSession.getLatestRoot();
    TokenConfiguration tc = getSecurityProvider().getConfiguration(TokenConfiguration.class);
    TokenProvider tp = tc.getTokenProvider(root);
    SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
    TokenInfo info = tp.createToken(sc.getUserID(), Collections.<String, Object>emptyMap());
    ContentSession cs = login(new TokenCredentials(info.getToken()));
    try {
        assertEquals(sc.getUserID(), cs.getAuthInfo().getUserID());
    } finally {
        cs.close();
    }
}
Also used : TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) SimpleCredentials(javax.jcr.SimpleCredentials) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with TokenConfiguration

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

the class SecurityProviderRegistrationTest method testBindUnbindTokenConfiguration.

@Test
public void testBindUnbindTokenConfiguration() throws Exception {
    Field f = registration.getClass().getDeclaredField("tokenConfiguration");
    f.setAccessible(true);
    assertTrue(f.get(registration) instanceof CompositeTokenConfiguration);
    TokenConfiguration tc = mockConfiguration(TokenConfiguration.class);
    registration.bindTokenConfiguration(tc, PROPS);
    CompositeTokenConfiguration composite = (CompositeTokenConfiguration) f.get(registration);
    assertEquals(1, composite.getConfigurations().size());
    assertTrue(composite.getConfigurations().contains(tc));
    registration.unbindTokenConfiguration(tc, PROPS);
    composite = (CompositeTokenConfiguration) f.get(registration);
    assertTrue(composite.getConfigurations().isEmpty());
}
Also used : CompositeTokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.CompositeTokenConfiguration) TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) Field(java.lang.reflect.Field) CompositeTokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.CompositeTokenConfiguration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with TokenConfiguration

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

the class TokenLoginModuleTest method testValidTokenCredentials.

@Test
public void testValidTokenCredentials() throws Exception {
    Root root = adminSession.getLatestRoot();
    TokenConfiguration tokenConfig = getSecurityProvider().getConfiguration(TokenConfiguration.class);
    TokenProvider tp = tokenConfig.getTokenProvider(root);
    SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
    TokenInfo info = tp.createToken(sc.getUserID(), Collections.<String, Object>emptyMap());
    ContentSession cs = login(new TokenCredentials(info.getToken()));
    try {
        assertEquals(sc.getUserID(), cs.getAuthInfo().getUserID());
    } finally {
        cs.close();
    }
}
Also used : TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) SimpleCredentials(javax.jcr.SimpleCredentials) Root(org.apache.jackrabbit.oak.api.Root) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with TokenConfiguration

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

the class InternalSecurityProviderTest method testSetTokenConfiguration.

@Test
public void testSetTokenConfiguration() {
    TokenConfiguration tc = Mockito.mock(TokenConfiguration.class);
    when(tc.getParameters()).thenReturn(PARAMS);
    securityProvider.setTokenConfiguration(tc);
    assertSame(tc, securityProvider.getConfiguration(TokenConfiguration.class));
    for (SecurityConfiguration sc : securityProvider.getConfigurations()) {
        if (sc instanceof TokenConfiguration) {
            assertSame(tc, sc);
        }
    }
    assertEquals(PARAMS, securityProvider.getParameters(TokenConfiguration.NAME));
}
Also used : TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) SecurityConfiguration(org.apache.jackrabbit.oak.spi.security.SecurityConfiguration) Test(org.junit.Test)

Example 5 with TokenConfiguration

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

the class TokenLoginModule method getTokenProvider.

// ------------------------------------------------------------< private >---
/**
 * Retrieve the token provider
 * @return the token provider or {@code null}.
 */
@CheckForNull
private TokenProvider getTokenProvider() {
    TokenProvider provider = null;
    SecurityProvider securityProvider = getSecurityProvider();
    Root root = getRoot();
    if (root != null && securityProvider != null) {
        TokenConfiguration tokenConfig = securityProvider.getConfiguration(TokenConfiguration.class);
        provider = tokenConfig.getTokenProvider(root);
    }
    if (provider == null && callbackHandler != null) {
        try {
            TokenProviderCallback tcCallback = new TokenProviderCallback();
            callbackHandler.handle(new Callback[] { tcCallback });
            provider = tcCallback.getTokenProvider();
        } catch (IOException e) {
            log.warn(e.getMessage());
        } catch (UnsupportedCallbackException e) {
            log.warn(e.getMessage());
        }
    }
    return provider;
}
Also used : TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) Root(org.apache.jackrabbit.oak.api.Root) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) TokenProviderCallback(org.apache.jackrabbit.oak.spi.security.authentication.callback.TokenProviderCallback) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) CheckForNull(javax.annotation.CheckForNull)

Aggregations

TokenConfiguration (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration)9 Test (org.junit.Test)8 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)5 Root (org.apache.jackrabbit.oak.api.Root)5 TokenProvider (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider)5 SimpleCredentials (javax.jcr.SimpleCredentials)4 Field (java.lang.reflect.Field)3 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)3 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)3 SecurityProvider (org.apache.jackrabbit.oak.spi.security.SecurityProvider)3 CompositeTokenConfiguration (org.apache.jackrabbit.oak.spi.security.authentication.token.CompositeTokenConfiguration)3 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExecutorService (java.util.concurrent.ExecutorService)1 CheckForNull (javax.annotation.CheckForNull)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 SecurityConfiguration (org.apache.jackrabbit.oak.spi.security.SecurityConfiguration)1 TokenProviderCallback (org.apache.jackrabbit.oak.spi.security.authentication.callback.TokenProviderCallback)1