Search in sources :

Example 11 with Authentication

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

the class PasswordForceInitialPasswordChangeTest method testChangePassword.

@Test
public void testChangePassword() throws Exception {
    User user = getTestUser();
    PropertyState p1 = root.getTree(user.getPath()).getChild(UserConstants.REP_PWD).getProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED);
    assertNull(p1);
    user.changePassword(userId);
    root.commit();
    PropertyState p2 = root.getTree(user.getPath()).getChild(UserConstants.REP_PWD).getProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED);
    assertNotNull(p2);
    assertTrue(p2.getValue(Type.LONG) > 0);
    // after password change, authentication must succeed
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    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 12 with Authentication

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

the class UserAuthenticationTest method testAuthenticateResolvesToGroup.

@Test
public void testAuthenticateResolvesToGroup() throws Exception {
    Group g = getUserManager(root).createGroup("g1");
    SimpleCredentials sc = new SimpleCredentials(g.getID(), "pw".toCharArray());
    Authentication a = new UserAuthentication(getUserConfiguration(), root, sc.getUserID());
    try {
        a.authenticate(sc);
        fail("Authenticating Group should fail");
    } catch (LoginException e) {
        // success
        assertTrue(e instanceof AccountNotFoundException);
    } finally {
        g.remove();
        root.commit();
    }
}
Also used : Group(org.apache.jackrabbit.api.security.user.Group) SimpleCredentials(javax.jcr.SimpleCredentials) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 13 with Authentication

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

the class UserAuthenticationTest method testAuthenticateCannotResolveUser.

@Test
public void testAuthenticateCannotResolveUser() throws Exception {
    SimpleCredentials sc = new SimpleCredentials("unknownUser", "pw".toCharArray());
    Authentication a = new UserAuthentication(getUserConfiguration(), root, sc.getUserID());
    assertFalse(a.authenticate(sc));
}
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 14 with Authentication

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

the class UserAuthenticationTest method testAuthenticateResolvesToDisabledUser.

@Test
public void testAuthenticateResolvesToDisabledUser() throws Exception {
    User testUser = getTestUser();
    SimpleCredentials sc = new SimpleCredentials(testUser.getID(), testUser.getID().toCharArray());
    Authentication a = new UserAuthentication(getUserConfiguration(), root, sc.getUserID());
    try {
        getTestUser().disable("disabled");
        root.commit();
        a.authenticate(sc);
        fail("Authenticating disabled user should fail");
    } catch (LoginException e) {
        // success
        assertTrue(e instanceof AccountLockedException);
    } finally {
        getTestUser().disable(null);
        root.commit();
    }
}
Also used : SimpleCredentials(javax.jcr.SimpleCredentials) AccountLockedException(javax.security.auth.login.AccountLockedException) User(org.apache.jackrabbit.api.security.user.User) Authentication(org.apache.jackrabbit.oak.spi.security.authentication.Authentication) LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 15 with Authentication

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

the class PasswordExpiryAndForceInitialChangeTest method testAuthenticateMustChangePassword.

@Test
public void testAuthenticateMustChangePassword() throws Exception {
    Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
    try {
        // the user should need to change the password on first login
        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