use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.
the class PasswordExpiryTest method testAuthenticatePasswordExpired.
@Test
public void testAuthenticatePasswordExpired() throws Exception {
Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
// set password last modified to beginning of epoch
root.getTree(getTestUser().getPath()).getChild(UserConstants.REP_PWD).setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, 0);
root.commit();
try {
a.authenticate(new SimpleCredentials(userId, userId.toCharArray()));
fail("Credentials should be expired");
} catch (CredentialExpiredException e) {
// success
}
}
use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.
the class ResetExpiredPasswordTest method authenticate.
private void authenticate(String expiredPw, Object newPw) throws LoginException {
SimpleCredentials creds = new SimpleCredentials(userId, expiredPw.toCharArray());
creds.setAttribute(UserConstants.CREDENTIALS_ATTRIBUTE_NEWPASSWORD, newPw);
Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
a.authenticate(creds);
}
use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.
the class TokenAuthenticationTest method testAuthenticateWithoutTokenProvider.
@Test
public void testAuthenticateWithoutTokenProvider() throws Exception {
Authentication authentication = new TokenAuthentication(null);
assertFalse(authentication.authenticate(new TokenCredentials("token")));
}
use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.
the class LoginModuleImplTest method testCustomUserAuthentication.
@Test
public void testCustomUserAuthentication() throws Exception {
LoginModuleImpl loginModule = new LoginModuleImpl();
UserAuthenticationFactory factory = new UserAuthenticationFactory() {
@CheckForNull
@Override
public Authentication getAuthentication(@Nonnull UserConfiguration configuration, @Nonnull Root root, @Nullable String userId) {
return new Authentication() {
@Override
public boolean authenticate(@Nullable Credentials credentials) throws LoginException {
return true;
}
@CheckForNull
@Override
public String getUserId() {
return null;
}
@CheckForNull
@Override
public Principal getUserPrincipal() {
return null;
}
};
}
};
CallbackHandler cbh = new TestCallbackHandler(factory);
SimpleCredentials creds = new SimpleCredentials("loginId", new char[0]);
Subject subject = new Subject(false, Sets.<Principal>newHashSet(), ImmutableSet.of(creds), Sets.newHashSet());
loginModule.initialize(subject, cbh, Maps.<String, Object>newHashMap(), Maps.<String, Object>newHashMap());
assertTrue(loginModule.login());
assertTrue(loginModule.commit());
AuthInfo authInfo = subject.getPublicCredentials(AuthInfo.class).iterator().next();
assertEquals("loginId", authInfo.getUserID());
}
use of org.apache.jackrabbit.oak.spi.security.authentication.Authentication in project jackrabbit-oak by apache.
the class PasswordExpiryTest method testAuthenticatePasswordExpiredChangePassword.
@Test
public void testAuthenticatePasswordExpiredChangePassword() throws Exception {
Authentication a = new UserAuthentication(getUserConfiguration(), root, userId);
// set password last modified to beginning of epoch
root.getTree(getTestUser().getPath()).getChild(UserConstants.REP_PWD).setProperty(UserConstants.REP_PASSWORD_LAST_MODIFIED, 0);
root.commit();
// changing the password should reset the pw last mod and the pw no longer be expired
getTestUser().changePassword(userId);
root.commit();
assertTrue(a.authenticate(new SimpleCredentials(userId, userId.toCharArray())));
}
Aggregations