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));
}
}
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();
}
}
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();
}
}
}
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));
}
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());
}
Aggregations