use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class TokenProviderTest method testReset.
public void testReset() throws Exception {
TokenInfo info = tokenProvider.createToken(testuser, new SimpleCredentials(userId, userId.toCharArray()));
long expTime = getTokenNode(info).getProperty("rep:token.exp").getLong();
long loginTime = waitForSystemTimeIncrement(System.currentTimeMillis());
assertFalse(info.resetExpiration(loginTime));
assertFalse(info.resetExpiration(loginTime + TokenBasedAuthentication.TOKEN_EXPIRATION));
assertTrue(info.resetExpiration(loginTime + TokenBasedAuthentication.TOKEN_EXPIRATION / 2));
long expTime2 = getTokenNode(info).getProperty("rep:token.exp").getLong();
assertFalse(expTime == expTime2);
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class TokenProviderTest method testTokenNode.
public void testTokenNode() throws Exception {
Map<String, String> privateAttributes = new HashMap<String, String>();
privateAttributes.put(".token_exp", "value");
privateAttributes.put(".tokenTest", "value");
privateAttributes.put(".token_something", "value");
Map<String, String> publicAttributes = new HashMap<String, String>();
publicAttributes.put("any", "value");
publicAttributes.put("another", "value");
Map<String, String> attributes = new HashMap<String, String>();
attributes.putAll(publicAttributes);
attributes.putAll(privateAttributes);
SimpleCredentials sc = new SimpleCredentials(userId, userId.toCharArray());
for (String s : attributes.keySet()) {
sc.setAttribute(s, attributes.get(s));
}
TokenInfo info = tokenProvider.createToken(testuser, sc);
Node tokenNode = getTokenNode(info);
Property prop = tokenNode.getProperty("rep:token.key");
assertNotNull(prop);
assertEquals(PropertyType.STRING, prop.getType());
assertTrue(prop.getDefinition().isProtected());
prop = tokenNode.getProperty("rep:token.exp");
assertNotNull(prop);
assertEquals(PropertyType.DATE, prop.getType());
assertTrue(prop.getDefinition().isProtected());
for (String key : privateAttributes.keySet()) {
assertEquals(privateAttributes.get(key), tokenNode.getProperty(key).getString());
}
for (String key : publicAttributes.keySet()) {
assertEquals(publicAttributes.get(key), tokenNode.getProperty(key).getString());
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class CryptedSimpleCredentialsTest method testPasswordMatch.
public void testPasswordMatch() throws NoSuchAlgorithmException, UnsupportedEncodingException {
// simple credentials containing the crypted pw must not match.
SimpleCredentials sc = new SimpleCredentials(userID, cCreds.get(0).getPassword().toCharArray());
for (CryptedSimpleCredentials cc : cCreds) {
assertFalse(cc.matches(sc));
}
// simple credentials containing different pw must not match.
SimpleCredentials sc2 = new SimpleCredentials(userID, "otherPw".toCharArray());
for (CryptedSimpleCredentials cc : cCreds) {
assertFalse(cc.matches(sc2));
}
// simple credentials with pw in digested form must not match.
SimpleCredentials sc3 = new SimpleCredentials(userID, "{unknown}somePw".toCharArray());
for (CryptedSimpleCredentials cc : cCreds) {
assertFalse(cc.matches(sc3));
}
// simple credentials with pw with different digest must not match
SimpleCredentials sc4 = new SimpleCredentials(userID, ("{md5}" + Text.digest("md5", pw.getBytes("UTF-8"))).toCharArray());
for (CryptedSimpleCredentials cc : cCreds) {
assertFalse(cc.matches(sc4));
}
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class TokenBasedAuthenticationCompatTest method testDoCreateToken.
public void testDoCreateToken() {
assertFalse(TokenBasedAuthentication.doCreateToken(creds));
assertFalse(TokenBasedAuthentication.doCreateToken(simpleCreds));
assertFalse(TokenBasedAuthentication.doCreateToken(tokenCreds));
SimpleCredentials sc = new SimpleCredentials("uid", "pw".toCharArray());
sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, null);
assertFalse(TokenBasedAuthentication.doCreateToken(sc));
sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "somevalue");
assertFalse(TokenBasedAuthentication.doCreateToken(sc));
sc.setAttribute(TokenBasedAuthentication.TOKEN_ATTRIBUTE, "");
assertTrue(TokenBasedAuthentication.doCreateToken(sc));
}
use of javax.jcr.SimpleCredentials in project jackrabbit by apache.
the class CompatTokenProviderTest method testCreateTokenIsCaseInsensitive.
public void testCreateTokenIsCaseInsensitive() throws Exception {
String upperCaseUserId = userId.toUpperCase();
TokenInfo info = tokenProvider.createToken(testuser, new SimpleCredentials(upperCaseUserId, new char[0]));
assertTokenInfo(info);
}
Aggregations