Search in sources :

Example 36 with TokenInfo

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

the class TokenAuthenticationTest method testAuthenticate.

@Test
public void testAuthenticate() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    assertTrue(authentication.authenticate(new TokenCredentials(info.getToken())));
}
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 37 with TokenInfo

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

the class TokenAuthenticationTest method testAuthenticateNotMatchingToken.

@Test
public void testAuthenticateNotMatchingToken() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, ImmutableMap.of(TokenConstants.TOKEN_ATTRIBUTE + "_mandatory", "val"));
    try {
        authentication.authenticate(new TokenCredentials(info.getToken()));
        fail("LoginException expected");
    } catch (LoginException e) {
    // success
    }
}
Also used : 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 38 with TokenInfo

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

the class TokenNoRefreshTest method testNotReset.

@Test
public void testNotReset() {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    assertNotNull(info);
    assertFalse(info.resetExpiration(new Date().getTime()));
    long loginTime = new Date().getTime() + 3600000;
    assertFalse(info.resetExpiration(loginTime));
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) Date(java.util.Date) Test(org.junit.Test)

Example 39 with TokenInfo

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

the class TokenProviderImplTest method testCreateTokenFromCredentials.

@Test
public void testCreateTokenFromCredentials() throws Exception {
    SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
    List<Credentials> valid = new ArrayList<Credentials>();
    valid.add(sc);
    valid.add(new ImpersonationCredentials(sc, null));
    for (Credentials creds : valid) {
        TokenInfo info = tokenProvider.createToken(creds);
        assertTokenInfo(info, userId);
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ArrayList(java.util.ArrayList) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) SimpleCredentials(javax.jcr.SimpleCredentials) Credentials(javax.jcr.Credentials) Test(org.junit.Test)

Example 40 with TokenInfo

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

the class TokenProviderImplTest method testGetTokenInfoFromDisabledUser.

@Test
public void testGetTokenInfoFromDisabledUser() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    getTestUser().disable("disabled");
    assertNull(tokenProvider.getTokenInfo(info.getToken()));
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) Test(org.junit.Test)

Aggregations

TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)51 Test (org.junit.Test)47 Tree (org.apache.jackrabbit.oak.api.Tree)15 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)14 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)13 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)10 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)8 Date (java.util.Date)7 SimpleCredentials (javax.jcr.SimpleCredentials)5 Root (org.apache.jackrabbit.oak.api.Root)4 TokenProvider (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider)4 HashMap (java.util.HashMap)3 Credentials (javax.jcr.Credentials)3 LoginException (javax.security.auth.login.LoginException)3 TokenConfiguration (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration)3 ArrayList (java.util.ArrayList)2 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)2 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1