Search in sources :

Example 16 with SimpleCredentials

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);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

Example 17 with SimpleCredentials

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());
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) HashMap(java.util.HashMap) Node(javax.jcr.Node) Property(javax.jcr.Property)

Example 18 with SimpleCredentials

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));
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

Example 19 with SimpleCredentials

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));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

Example 20 with SimpleCredentials

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);
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials)

Aggregations

SimpleCredentials (javax.jcr.SimpleCredentials)289 Test (org.junit.Test)142 Session (javax.jcr.Session)83 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)60 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)53 User (org.apache.jackrabbit.api.security.user.User)41 Credentials (javax.jcr.Credentials)39 JackrabbitSession (org.apache.jackrabbit.api.JackrabbitSession)35 UserManager (org.apache.jackrabbit.api.security.user.UserManager)34 LoginException (javax.security.auth.login.LoginException)30 Node (javax.jcr.Node)28 RepositoryException (javax.jcr.RepositoryException)25 Principal (java.security.Principal)22 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)21 GuestCredentials (javax.jcr.GuestCredentials)20 LoginException (javax.jcr.LoginException)19 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)19 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)18 Before (org.junit.Before)18 ImpersonationCredentials (org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials)17