Search in sources :

Example 1 with TokenProvider

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

the class TokenLoginModuleTest method testCreateTokenFailed.

@Test
public void testCreateTokenFailed() throws Exception {
    TokenProvider tp = new TokenProvider() {

        @Override
        public boolean doCreateToken(@Nonnull Credentials credentials) {
            return true;
        }

        @CheckForNull
        @Override
        public TokenInfo createToken(@Nonnull Credentials credentials) {
            return null;
        }

        @CheckForNull
        @Override
        public TokenInfo createToken(@Nonnull String userId, @Nonnull Map<String, ?> attributes) {
            return null;
        }

        @CheckForNull
        @Override
        public TokenInfo getTokenInfo(@Nonnull String token) {
            return null;
        }
    };
    TokenLoginModule lm = new TokenLoginModule();
    lm.initialize(new Subject(), new TestCallbackHandler(tp), ImmutableMap.<String, Object>of(AbstractLoginModule.SHARED_KEY_CREDENTIALS, new Credentials() {
    }), ImmutableMap.<String, Object>of());
    lm.login();
    try {
        lm.commit();
        fail("LoginException expected");
    } catch (LoginException e) {
    // success
    }
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) Nonnull(javax.annotation.Nonnull) LoginException(javax.security.auth.login.LoginException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Subject(javax.security.auth.Subject) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with TokenProvider

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

the class TokenConfigurationImplTest method testGetTokenProvider.

@Test
public void testGetTokenProvider() {
    TokenProvider tp = tc.getTokenProvider(root);
    assertTrue(tp instanceof TokenProviderImpl);
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with TokenProvider

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

the class TokenAuthenticationTest method testAuthenticateExpiredToken.

@Test
public void testAuthenticateExpiredToken() throws Exception {
    TokenProvider tp = new TokenProviderImpl(root, ConfigurationParameters.of(TokenProvider.PARAM_TOKEN_EXPIRATION, 1), getUserConfiguration());
    TokenInfo info = tp.createToken(userId, Collections.<String, Object>emptyMap());
    waitUntilExpired(info);
    try {
        new TokenAuthentication(tp).authenticate(new TokenCredentials(info.getToken()));
        fail("LoginException expected");
    } catch (LoginException e) {
    // success
    }
    // expired token must have been removed
    assertNull(tp.getTokenInfo(info.getToken()));
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) LoginException(javax.security.auth.login.LoginException) 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 TokenProvider

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

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

the class TokenProviderCallbackTest method testCallback.

@Test
public void testCallback() {
    TokenProviderCallback cb = new TokenProviderCallback();
    TokenProvider tp = Mockito.mock(TokenProvider.class);
    cb.setTokenProvider(tp);
    assertSame(tp, cb.getTokenProvider());
}
Also used : TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) 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