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()));
}
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();
}
}
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));
}
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();
}
}
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
}
}
Aggregations