use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo in project jackrabbit-oak by apache.
the class TokenValidatorTest method testModifyExpirationDate.
@Test
public void testModifyExpirationDate() throws Exception {
TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
NodeUtil tokenTree = new NodeUtil(getTokenTree(info));
tokenTree.setDate(TOKEN_ATTRIBUTE_EXPIRY, new Date().getTime());
root.commit(CommitMarker.asCommitAttributes());
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo in project jackrabbit-oak by apache.
the class TokenValidatorTest method testChangeTokenParentPrimaryType.
@Test
public void testChangeTokenParentPrimaryType() throws Exception {
TokenInfo info = tokenProvider.createToken(userId, Collections.<String, Object>emptyMap());
try {
Tree tokensTree = getTokenTree(info).getParent();
tokensTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED, Type.NAME);
root.commit();
fail("The primary type of the token parent must not be changed from rep:Unstructured to another type.");
} catch (CommitFailedException e) {
assertEquals(69, e.getCode());
} finally {
root.refresh();
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo in project jackrabbit-oak by apache.
the class TokenValidatorTest method testCreateTokenAtInvalidLocationBelowTestNode.
@Test
public void testCreateTokenAtInvalidLocationBelowTestNode() 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();
root.commit(CommitMarker.asCommitAttributes());
fail("Creating a new token not at '/testNode' must fail.");
} catch (CommitFailedException e) {
assertEquals(64, e.getCode());
} finally {
node.getTree().remove();
root.commit(CommitMarker.asCommitAttributes());
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo in project jackrabbit-oak by apache.
the class TokenValidatorTest method testCreateTokenAtInvalidLocationInsideUser.
@Test
public void testCreateTokenAtInvalidLocationInsideUser() 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).addChild("testNode", JcrConstants.NT_UNSTRUCTURED);
try {
createTokenTree(info, node, TOKEN_NT_NAME);
tokenTree.remove();
root.commit(CommitMarker.asCommitAttributes());
fail("Creating a new token '" + node.getTree().getPath() + "' must fail.");
} catch (CommitFailedException e) {
assertEquals(65, e.getCode());
} finally {
node.getTree().remove();
root.commit(CommitMarker.asCommitAttributes());
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo in project jackrabbit-oak by apache.
the class TokenProviderImpl method createToken.
/**
* Create a separate token node underneath a dedicated token store within
* the user home node. That token node contains the hashed token, the
* expiration time and additional mandatory attributes that will be verified
* during login.
*
* @param credentials The current credentials.
* @return A new {@code TokenInfo} or {@code null} if the token could not
* be created.
*/
@CheckForNull
@Override
public TokenInfo createToken(@Nonnull Credentials credentials) {
Credentials creds = extractCredentials(credentials);
String uid = (creds != null) ? credentialsSupport.getUserId(creds) : null;
TokenInfo tokenInfo = null;
if (uid != null) {
Map<String, ?> attributes = credentialsSupport.getAttributes(creds);
tokenInfo = createToken(uid, attributes);
if (tokenInfo != null) {
// also set the new token to the credentials.
if (!credentialsSupport.setAttributes(creds, ImmutableMap.of(TOKEN_ATTRIBUTE, tokenInfo.getToken()))) {
log.debug("Cannot set token attribute to " + creds);
}
}
}
return tokenInfo;
}
Aggregations