Search in sources :

Example 1 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.

the class TokenProviderImplTest method testCreateTokenFromInvalidCredentials.

@Test
public void testCreateTokenFromInvalidCredentials() throws Exception {
    List<Credentials> invalid = new ArrayList<Credentials>();
    invalid.add(new GuestCredentials());
    invalid.add(new TokenCredentials("sometoken"));
    invalid.add(new ImpersonationCredentials(new GuestCredentials(), null));
    invalid.add(new SimpleCredentials("unknownUserId", new char[0]));
    for (Credentials creds : invalid) {
        assertNull(tokenProvider.createToken(creds));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) ImpersonationCredentials(org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials) ArrayList(java.util.ArrayList) 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) GuestCredentials(javax.jcr.GuestCredentials) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Test(org.junit.Test)

Example 2 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials 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 3 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.

the class TokenLoginModuleTest method testInvalidTokenCredentials.

@Test
public void testInvalidTokenCredentials() throws Exception {
    ContentSession cs = null;
    try {
        cs = login(new TokenCredentials("invalid"));
        fail("Invalid token credentials login should fail");
    } catch (LoginException e) {
    // success
    } finally {
        if (cs != null) {
            cs.close();
        }
    }
}
Also used : ContentSession(org.apache.jackrabbit.oak.api.ContentSession) LoginException(javax.security.auth.login.LoginException) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.

the class TokenInfoTest method testMatches.

@Test
public void testMatches() {
    TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
    assertTrue(info.matches(new TokenCredentials(info.getToken())));
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("something", "value");
    info = tokenProvider.createToken(userId, attributes);
    assertTrue(info.matches(new TokenCredentials(info.getToken())));
    attributes.put(".token-something", "mandatory");
    info = tokenProvider.createToken(userId, attributes);
    assertFalse(info.matches(new TokenCredentials(info.getToken())));
    TokenCredentials tc = new TokenCredentials(info.getToken());
    tc.setAttribute(".token-something", "mandatory");
    assertTrue(info.matches(tc));
    tc.setAttribute("another", "value");
    assertTrue(info.matches(tc));
    tc.setAttribute(".token_ignored", "value");
    assertTrue(info.matches(tc));
}
Also used : HashMap(java.util.HashMap) TokenInfo(org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo) TokenCredentials(org.apache.jackrabbit.api.security.authentication.token.TokenCredentials) Test(org.junit.Test)

Example 5 with TokenCredentials

use of org.apache.jackrabbit.api.security.authentication.token.TokenCredentials in project jackrabbit-oak by apache.

the class TokenAuthenticationTest method testGetTokenInfoAfterAuthenticate.

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

TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)38 Test (org.junit.Test)23 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)17 SimpleCredentials (javax.jcr.SimpleCredentials)16 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)12 LoginException (javax.security.auth.login.LoginException)9 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)9 Credentials (javax.jcr.Credentials)7 RepositoryException (javax.jcr.RepositoryException)6 Session (javax.jcr.Session)6 ArrayList (java.util.ArrayList)5 LoginException (javax.jcr.LoginException)5 GuestCredentials (javax.jcr.GuestCredentials)4 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)4 Root (org.apache.jackrabbit.oak.api.Root)4 TokenProvider (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenProvider)4 Subject (javax.security.auth.Subject)3 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)3 TokenConfiguration (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenConfiguration)3 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)3