Search in sources :

Example 31 with TokenInfo

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

the class TokenInfoTest method testIsExpired.

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

Example 32 with TokenInfo

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

the class TokenInfoTest method testRemoveTokenRemovesNode.

@Test
public void testRemoveTokenRemovesNode() throws Exception {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    Tree userTree = root.getTree(getUserManager(root).getAuthorizable(userId).getPath());
    Tree tokens = userTree.getChild(TOKENS_NODE_NAME);
    String tokenNodePath = tokens.getChildren().iterator().next().getPath();
    info.remove();
    assertFalse(root.getTree(tokenNodePath).exists());
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) Test(org.junit.Test)

Example 33 with TokenInfo

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

the class TokenInfoTest method testRemoveToken2.

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

Example 34 with TokenInfo

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

the class TokenInfoTest method testResetTokenExpiration.

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

Example 35 with TokenInfo

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

the class TokenAuthenticationTest method testGetUserId.

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

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