Search in sources :

Example 46 with TokenInfo

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

the class TokenInfoTest method testResetTokenExpirationExpiredToken.

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

Example 47 with TokenInfo

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

the class TokenInfoTest method testGetToken.

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

Example 48 with TokenInfo

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

the class TokenValidatorTest method testCreateTokenWithInvalidNodeType.

@Test
public void testCreateTokenWithInvalidNodeType() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    Tree tokenTree = getTokenTree(info);
    assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
    Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
    NodeUtil node = new NodeUtil(userTree.getChild(TOKENS_NODE_NAME));
    Tree t = null;
    try {
        t = createTokenTree(info, node, JcrConstants.NT_UNSTRUCTURED);
        tokenTree.remove();
        root.commit(CommitMarker.asCommitAttributes());
        fail("The token node must be of type rep:Token.");
    } catch (CommitFailedException e) {
        assertEquals(60, e.getCode());
    } finally {
        if (t != null) {
            t.remove();
            root.commit(CommitMarker.asCommitAttributes());
        }
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) 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 49 with TokenInfo

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

the class TokenProviderImplReadOnlyTest method testRefreshToken.

@Test
public void testRefreshToken() throws Exception {
    TokenInfo readOnlyInfo = readOnlyTp.getTokenInfo(generateToken());
    assertFalse(readOnlyInfo.resetExpiration(System.currentTimeMillis() + TokenProviderImpl.DEFAULT_TOKEN_EXPIRATION - 100));
}
Also used : TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) Test(org.junit.Test)

Example 50 with TokenInfo

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

the class TokenValidatorTest method testManuallyCreateToken.

@Test
public void testManuallyCreateToken() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    Tree tokenTree = getTokenTree(info);
    assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
    NodeUtil tokensNode = new NodeUtil(tokenTree.getParent());
    try {
        // create a valid token node using the test root
        createTokenTree(info, tokensNode, TOKEN_NT_NAME);
        tokenTree.remove();
        root.commit();
        fail("Manually creating a token node must fail.");
    } catch (CommitFailedException e) {
        assertEquals(63, e.getCode());
    } finally {
        root.refresh();
        root.commit();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) 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)

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