Search in sources :

Example 6 with TokenProvider

use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider 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)

Example 7 with TokenProvider

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

the class TokenConfigurationImplOSGiTest method testDefaultCredentialsSupport.

@Test
public void testDefaultCredentialsSupport() throws Exception {
    TokenProvider tp = tokenConfiguration.getTokenProvider(root);
    assertTrue(tp.doCreateToken(sc));
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 8 with TokenProvider

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

the class TokenConfigurationImplOSGiTest method testUnbindCredentialsSupport.

@Test
public void testUnbindCredentialsSupport() {
    CredentialsSupport testSupport = new TestCredentialsSupport(sc.getUserID());
    ServiceRegistration registration = context.bundleContext().registerService(CredentialsSupport.class.getName(), testSupport, new Hashtable());
    TokenProvider tp = tokenConfiguration.getTokenProvider(root);
    assertFalse(tp.doCreateToken(sc));
    assertTrue(tp.doCreateToken(new TestCredentialsSupport.Creds()));
    registration.unregister();
    tp = tokenConfiguration.getTokenProvider(root);
    assertTrue(tp.doCreateToken(sc));
    assertFalse(tp.doCreateToken(new TestCredentialsSupport.Creds()));
}
Also used : CredentialsSupport(org.apache.jackrabbit.oak.spi.security.authentication.credentials.CredentialsSupport) TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 9 with TokenProvider

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

the class TokenConfigurationImplOSGiTest method testBindCredentialsSupport.

@Test
public void testBindCredentialsSupport() {
    context.registerService(CredentialsSupport.class, new TestCredentialsSupport(sc.getUserID()));
    TokenProvider tp = tokenConfiguration.getTokenProvider(root);
    assertFalse(tp.doCreateToken(sc));
    assertTrue(tp.doCreateToken(new TestCredentialsSupport.Creds()));
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 10 with TokenProvider

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

the class TokenLoginModuleTest method testTokenProviderCallback.

@Test
public void testTokenProviderCallback() throws Exception {
    TokenProvider tp = new TokenProviderImpl(root, ConfigurationParameters.EMPTY, getUserConfiguration());
    TokenLoginModule lm = new TokenLoginModule();
    lm.initialize(new Subject(), new TestCallbackHandler(tp), ImmutableMap.<String, Object>of(), ImmutableMap.<String, Object>of());
    assertFalse(lm.login());
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) Subject(javax.security.auth.Subject) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

TokenProvider (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider)13 Test (org.junit.Test)12 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)9 SimpleCredentials (javax.jcr.SimpleCredentials)5 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)5 Root (org.apache.jackrabbit.oak.api.Root)5 TokenConfiguration (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration)5 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)4 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)3 Subject (javax.security.auth.Subject)2 LoginException (javax.security.auth.login.LoginException)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 CheckForNull (javax.annotation.CheckForNull)1 Nonnull (javax.annotation.Nonnull)1 Credentials (javax.jcr.Credentials)1