Search in sources :

Example 6 with TokenInfo

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

the class TokenProviderImplTest method testGetTokenInfoFromInvalidToken.

@Test
public void testGetTokenInfoFromInvalidToken() throws Exception {
    List<String> invalid = new ArrayList<String>();
    invalid.add("/invalid");
    invalid.add(UUID.randomUUID().toString());
    for (String token : invalid) {
        TokenInfo info = tokenProvider.getTokenInfo(token);
        assertNull(info);
    }
    try {
        assertNull(tokenProvider.getTokenInfo("invalidToken"));
    } catch (Exception e) {
    // success
    }
}
Also used : ArrayList(java.util.ArrayList) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) Test(org.junit.Test)

Example 7 with TokenInfo

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

the class TokenProviderImplTest method testCreateTokenWithExpirationParam.

@Test
public void testCreateTokenWithExpirationParam() throws Exception {
    SimpleCredentials sc = new SimpleCredentials(userId, new char[0]);
    sc.setAttribute(TokenProvider.PARAM_TOKEN_EXPIRATION, 100000);
    TokenInfo info = tokenProvider.createToken(sc);
    assertTokenInfo(info, userId);
    Tree tokenTree = getTokenTree(info);
    assertNotNull(tokenTree);
    assertTrue(tokenTree.exists());
    assertTrue(tokenTree.hasProperty(TokenProvider.PARAM_TOKEN_EXPIRATION));
    assertEquals(100000, tokenTree.getProperty(TokenProvider.PARAM_TOKEN_EXPIRATION).getValue(Type.LONG).longValue());
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Tree(org.apache.jackrabbit.oak.api.Tree) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) Test(org.junit.Test)

Example 8 with TokenInfo

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

the class TokenProviderImplTest method testGetTokenInfoFromInvalidLocation.

@Test
public void testGetTokenInfoFromInvalidLocation() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    Tree tokenTree = getTokenTree(info);
    assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
    NodeUtil node = new NodeUtil(root.getTree("/")).addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
    try {
        createTokenTree(info, node, TOKEN_NT_NAME);
        tokenTree.remove();
        assertNull(tokenProvider.getTokenInfo(info.getToken()));
    } finally {
        node.getTree().remove();
        root.commit(CommitMarker.asCommitAttributes());
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) Test(org.junit.Test)

Example 9 with TokenInfo

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

the class TokenProviderImplTest method testGetTokenInfoFromInvalidLocation4.

@Test
public void testGetTokenInfoFromInvalidLocation4() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    Tree tokenTree = getTokenTree(info);
    assertNotNull(tokenProvider.getTokenInfo(info.getToken()));
    TokenInfo info2 = null;
    try {
        Tree adminTree = root.getTree(getUserManager(root).getAuthorizable(adminSession.getAuthInfo().getUserID()).getPath());
        NodeUtil node = new NodeUtil(adminTree).getOrAddChild(TOKENS_NODE_NAME, JcrConstants.NT_UNSTRUCTURED);
        assertTrue(root.move(tokenTree.getPath(), node.getTree().getPath() + '/' + tokenTree.getName()));
        info2 = tokenProvider.getTokenInfo(info.getToken());
        assertNotNull(info2);
        assertFalse(info2.matches(new TokenCredentials(info.getToken())));
    } finally {
        root.refresh();
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Test(org.junit.Test)

Example 10 with TokenInfo

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

the class TokenInfoTest method testGetUserId.

@Test
public void testGetUserId() {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    assertEquals(userId, info.getUserId());
    info = tokenProvider.getTokenInfo(info.getToken());
    assertEquals(userId, info.getUserId());
}
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