Search in sources :

Example 1 with Authentication

use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.

the class UserAuthenticationFactoryImplTest method testGetAuthentication.

@Test
public void testGetAuthentication() throws Exception {
    Authentication authentication = factory.getAuthentication(getUserConfiguration(), root, userId);
    assertNotNull(authentication);
    assertTrue(authentication instanceof UserAuthentication);
}
Also used : Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 2 with Authentication

use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.

the class PasswordExpiryAndForceInitialChangeTest method testChangePasswordReset.

@Test
public void testChangePasswordReset() throws Exception {
    // once the user changes the password, the login should succeed
    User user = getTestUser();
    user.changePassword(userId);
    root.commit();
    PropertyState p = root.getTree(user.getPath()).getChild(UserConstants.REP_PWD).getProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED);
    long newModTime = p.getValue(Type.LONG);
    assertTrue(newModTime > 0);
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    // during user creation pw last modified is set, thus it shouldn't expire
    a.authenticate(new SimpleCredentials(userId, userId.toCharArray()));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 3 with Authentication

use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.

the class PasswordExpiryHistoryTest method testAuthenticatePasswordExpiredAndInHistory.

@Test
public void testAuthenticatePasswordExpiredAndInHistory() throws Exception {
    User user = getTestUser();
    user.changePassword("pw12345678");
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    // set password last modified to beginning of epoch
    root.getTree(user.getPath()).getChild(UserConstants.REP_PWD).setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, 0);
    root.commit();
    try {
        a.authenticate(new SimpleCredentials(userId, "pw12345678".toCharArray()));
        fail("Credentials should be expired");
    } catch (CredentialExpiredException e) {
        // success, credentials are expired
        // try to change password to the same one, this should fail due pw history
        SimpleCredentials pwChangeCreds = new SimpleCredentials(userId, "pw12345678".toCharArray());
        try {
            pwChangeCreds.setAttribute(UserConstants.CREDENTIALS_ATTRIBUTE_NEWPASSWORD, user.getID());
            a.authenticate(pwChangeCreds);
            fail("User password changed in spite of enabled pw history");
        } catch (CredentialExpiredException c) {
            // success, pw found in history
            Object attr = pwChangeCreds.getAttribute(PasswordHistoryException.class.getSimpleName());
            assertEquals("credentials should contain pw change failure reason", "New password was found in password history.", attr);
        }
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) User(org.apache.jackrabbit.api.security.user.User) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) CredentialExpiredException(javax.security.auth.login.CredentialExpiredException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 4 with Authentication

use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.

the class PasswordExpiryTest method testAuthenticatePasswordExpiredNewUser.

@Test
public void testAuthenticatePasswordExpiredNewUser() throws Exception {
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    // during user creation pw last modified is set, thus it shouldn't expire
    a.authenticate(new SimpleCredentials(userId, userId.toCharArray()));
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 5 with Authentication

use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.

the class PasswordForceInitialPasswordChangeTest method testAuthenticateMustChangePassword.

@Test
public void testAuthenticateMustChangePassword() throws Exception {
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    try {
        a.authenticate(new SimpleCredentials(userId, userId.toCharArray()));
        fail("Credentials should be expired");
    } catch (CredentialExpiredException e) {
    // success
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) CredentialExpiredException(javax.security.auth.login.CredentialExpiredException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

Authentication (org.apache.jackrabbit.oak.spi.security.authentication.Authentication)19 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)17 Test (org.junit.Test)17 SimpleCredentials (javax.jcr.SimpleCredentials)16 CredentialExpiredException (javax.security.auth.login.CredentialExpiredException)7 User (org.apache.jackrabbit.api.security.user.User)6 LoginException (javax.security.auth.login.LoginException)3 FailedLoginException (javax.security.auth.login.FailedLoginException)2 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)2 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Credentials (javax.jcr.Credentials)1 GuestCredentials (javax.jcr.GuestCredentials)1 Subject (javax.security.auth.Subject)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 AccountLockedException (javax.security.auth.login.AccountLockedException)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 TokenCredentials (org.apache.jackrabbit.api.security.authentication.token.TokenCredentials)1 Group (org.apache.jackrabbit.api.security.user.Group)1 AuthInfo (org.apache.jackrabbit.oak.api.AuthInfo)1