Search in sources :

Example 6 with TokenConfiguration

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

the class SecurityProviderRegistrationTest method testBindOptionalCandidate.

@Test
public void testBindOptionalCandidate() throws Exception {
    registration.activate(context.bundleContext(), configWithRequiredServiceIds("serviceId"));
    Field f = registration.getClass().getDeclaredField("preconditions");
    f.setAccessible(true);
    TokenConfiguration tc = mockConfiguration(TokenConfiguration.class);
    registration.bindTokenConfiguration(tc, ImmutableMap.of(Constants.SERVICE_PID, "otherServiceId"));
    Preconditions preconditions = (Preconditions) f.get(registration);
    assertFalse(preconditions.areSatisfied());
    assertNull(context.getService(SecurityProvider.class));
}
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) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 7 with TokenConfiguration

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

the class SecurityProviderRegistrationTest method testBindMandatoryCandidate.

@Test
public void testBindMandatoryCandidate() throws Exception {
    registration.activate(context.bundleContext(), configWithRequiredServiceIds("serviceId"));
    Field f = registration.getClass().getDeclaredField("preconditions");
    f.setAccessible(true);
    TokenConfiguration tc = mockConfiguration(TokenConfiguration.class);
    registration.bindTokenConfiguration(tc, ImmutableMap.of(Constants.SERVICE_PID, "serviceId"));
    Preconditions preconditions = (Preconditions) f.get(registration);
    assertTrue(preconditions.areSatisfied());
    assertNotNull(context.getService(SecurityProvider.class));
}
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) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 8 with TokenConfiguration

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

Example 9 with TokenConfiguration

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

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