Search in sources :

Example 11 with TokenInfo

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

the class TokenProviderImplTest method testCreateTokenFromInvalidUserId.

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

Example 12 with TokenInfo

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

the class TokenProviderImplTest method testGetTokenInfo.

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

Example 13 with TokenInfo

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

the class TokenValidatorTest method testManuallyModifyExpirationDate.

@Test
public void testManuallyModifyExpirationDate() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    NodeUtil tokenTree = new NodeUtil(getTokenTree(info));
    try {
        tokenTree.setDate(TOKEN_ATTRIBUTE_EXPIRY, new Date().getTime());
        root.commit();
        fail("The token expiry must not manually be changed");
    } catch (CommitFailedException e) {
        assertEquals(63, e.getCode());
    }
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Date(java.util.Date) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 14 with TokenInfo

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

the class TokenValidatorTest method testPlaintextTokenKey.

@Test
public void testPlaintextTokenKey() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    NodeUtil tokenTree = new NodeUtil(getTokenTree(info));
    try {
        tokenTree.setString(TOKEN_ATTRIBUTE_KEY, "anotherValue");
        root.commit(CommitMarker.asCommitAttributes());
        fail("The token key must not be plaintext.");
    } catch (CommitFailedException e) {
        assertEquals(66, e.getCode());
    }
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 15 with TokenInfo

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

the class TokenValidatorTest method testRemoveTokenNode.

@Test
public void testRemoveTokenNode() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    getTokenTree(info).remove();
    root.commit();
}
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