Search in sources :

Example 6 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.

the class TokenAuthenticationTest method testGetUserPrincipal.

@Test
public void testGetUserPrincipal() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    assertTrue(authentication.authenticate(new TokenCredentials(info.getToken())));
    assertEquals(getTestUser().getPrincipal(), authentication.getUserPrincipal());
}
Also used : 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 7 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials 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 8 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials 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 9 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.

the class TokenLoginModuleCredentialsSupportTest method testCustomCredentials.

@Test
public void testCustomCredentials() throws Exception {
    TestCredentialsSupport.Creds credentials = new TestCredentialsSupport.Creds();
    ContentSession cs = login(credentials);
    try {
        assertEquals(userId, cs.getAuthInfo().getUserID());
        Map<String, ?> attributes = credentialsSupport.getAttributes(credentials);
        String token = attributes.get(TokenConstants.TOKEN_ATTRIBUTE).toString();
        assertFalse(token.isEmpty());
        cs.close();
        cs = login(new TokenCredentials(token));
        assertEquals(userId, cs.getAuthInfo().getUserID());
    } finally {
        cs.close();
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 10 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.

the class TokenLoginModule method login.

// --------------------------------------------------------< LoginModule >---
@Override
public boolean login() throws LoginException {
    tokenProvider = getTokenProvider();
    if (tokenProvider == null) {
        return false;
    }
    Credentials credentials = getCredentials();
    if (credentials instanceof TokenCredentials) {
        TokenCredentials tc = (TokenCredentials) credentials;
        TokenAuthentication authentication = new TokenAuthentication(tokenProvider);
        if (authentication.authenticate(tc)) {
            tokenCredentials = tc;
            tokenInfo = authentication.getTokenInfo();
            userId = authentication.getUserId();
            principal = authentication.getUserPrincipal();
            log.debug("Login: adding login name to shared state.");
            sharedState.put(SHARED_KEY_LOGIN_NAME, userId);
            return true;
        }
    }
    return false;
}
Also used : TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Credentials(javax.jcr.Credentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)

Aggregations

TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)38 Test (org.junit.Test)23 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)17 SimpleCredentials (javax.jcr.SimpleCredentials)16 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)12 LoginException (javax.security.auth.login.LoginException)9 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)9 Credentials (javax.jcr.Credentials)7 RepositoryException (javax.jcr.RepositoryException)6 Session (javax.jcr.Session)6 ArrayList (java.util.ArrayList)5 LoginException (javax.jcr.LoginException)5 GuestCredentials (javax.jcr.GuestCredentials)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 Root (org.apache.jackrabbit.oak.api.Root)4 TokenProvider (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider)4 Subject (javax.security.auth.Subject)3 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)3 TokenConfiguration (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration)3 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)3