Search in sources :

Example 11 with TokenProvider

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

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

the class TokenProviderImplTest method testValidTokenCredentialsWithConflict.

/**
     *@see <a href="https://issues.apache.org/jira/browse/OAK-1697">OAK-1697</a>
     */
@Test
public void testValidTokenCredentialsWithConflict() throws Exception {
    ExecutorService pool = Executors.newFixedThreadPool(10);
    List<ContentSession> sessions = new ArrayList<ContentSession>();
    try {
        TokenConfiguration tc = getSecurityProvider().getConfiguration(TokenConfiguration.class);
        SimpleCredentials sc = (SimpleCredentials) getAdminCredentials();
        List<TokenProvider> tokenProviders = new ArrayList<TokenProvider>();
        for (int i = 0; i < 10; i++) {
            ContentSession session = login(getAdminCredentials());
            Root r = session.getLatestRoot();
            tokenProviders.add(tc.getTokenProvider(r));
            sessions.add(session);
        }
        ArrayList<DataFuture> list = new ArrayList<DataFuture>();
        for (TokenProvider tokenProvider : tokenProviders) {
            list.add(createDataFuture(pool, tokenProvider, sc.getUserID(), Collections.<String, Object>emptyMap()));
        }
        for (DataFuture df : list) {
            assertNotNull(df.future.get());
        }
    } finally {
        for (ContentSession session : sessions) {
            if (session != null) {
                session.close();
            }
        }
        if (pool != null) {
            pool.shutdown();
        }
    }
}
Also used : Root(org.apache.jackrabbit.oak.api.Root) ArrayList(java.util.ArrayList) TokenConfiguration(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration) SimpleCredentials(javax.jcr.SimpleCredentials) TokenProvider(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider) ExecutorService(java.util.concurrent.ExecutorService) ContentSession(org.apache.jackrabbit.oak.api.ContentSession) Test(org.junit.Test)

Example 13 with TokenProvider

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

the class TokenProviderImplTest method testTokenValidationIsCaseInsensitive.

/**
     * @see <a href="https://issues.apache.org/jira/browse/OAK-1985">OAK-1985</a>
     */
@Test
public void testTokenValidationIsCaseInsensitive() throws Exception {
    Root root = adminSession.getLatestRoot();
    TokenConfiguration tokenConfig = getSecurityProvider().getConfiguration(TokenConfiguration.class);
    TokenProvider tp = tokenConfig.getTokenProvider(root);
    String userId = ((SimpleCredentials) getAdminCredentials()).getUserID();
    TokenInfo info = tp.createToken(userId.toUpperCase(), Collections.<String, Object>emptyMap());
    assertTrue(info.matches(new TokenCredentials(info.getToken())));
    assertEquals(userId, info.getUserId());
    info = tp.getTokenInfo(info.getToken());
    assertTrue(info.matches(new TokenCredentials(info.getToken())));
    assertEquals(userId, info.getUserId());
}
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) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) 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