use of net.sf.acegisecurity.CredentialsExpiredException in project alfresco-repository by Alfresco.
the class AuthenticationTest method testAuthentication.
public void testAuthentication() {
dao.createUser("GUEST", DONT_CARE_PASSWORD);
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("GUEST", new String(DONT_CARE_PASSWORD));
token.setAuthenticated(false);
Authentication result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.createUser("Andy", "squash".toCharArray());
token = new UsernamePasswordAuthenticationToken("Andy", "squash");
token.setAuthenticated(false);
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.setEnabled("Andy", false);
try {
result = authenticationManager.authenticate(token);
assertNotNull(result);
assertNotNull(null);
} catch (DisabledException e) {
// Expected
}
dao.setEnabled("Andy", true);
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.setLocked("Andy", true);
try {
result = authenticationManager.authenticate(token);
assertNotNull(result);
assertNotNull(null);
} catch (LockedException e) {
// Expected
}
dao.setLocked("Andy", false);
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.setAccountExpires("Andy", true);
dao.setCredentialsExpire("Andy", true);
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.setAccountExpiryDate("Andy", null);
dao.setCredentialsExpiryDate("Andy", null);
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.setAccountExpiryDate("Andy", new Date(new Date().getTime() + 10000));
dao.setCredentialsExpiryDate("Andy", new Date(new Date().getTime() + 10000));
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.setAccountExpiryDate("Andy", new Date(new Date().getTime() - 10000));
try {
result = authenticationManager.authenticate(token);
assertNotNull(result);
assertNotNull(null);
} catch (AccountExpiredException e) {
// Expected
}
dao.setAccountExpiryDate("Andy", new Date(new Date().getTime() + 10000));
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.setCredentialsExpiryDate("Andy", new Date(new Date().getTime() - 10000));
try {
result = authenticationManager.authenticate(token);
assertNotNull(result);
assertNotNull(null);
} catch (CredentialsExpiredException e) {
// Expected
}
dao.setCredentialsExpiryDate("Andy", new Date(new Date().getTime() + 10000));
result = authenticationManager.authenticate(token);
assertNotNull(result);
dao.deleteUser("Andy");
// assertNull(dao.getUserOrNull("Andy"));
}
use of net.sf.acegisecurity.CredentialsExpiredException in project alfresco-repository by Alfresco.
the class AuthenticationContextImpl method setUserDetails.
/**
* Explicitly set the given validated user details to be authenticated.
*
* @param ud
* the User Details
* @return Authentication
*/
public Authentication setUserDetails(UserDetails ud) {
String userId = ud.getUsername();
try {
// door'.
if (!ud.isEnabled()) {
throw new DisabledException("User is disabled");
}
if (!ud.isAccountNonExpired()) {
throw new AccountExpiredException("User account has expired");
}
if (!ud.isAccountNonLocked()) {
throw new LockedException("User account is locked");
}
if (!ud.isCredentialsNonExpired()) {
throw new CredentialsExpiredException("User credentials have expired");
}
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud.getAuthorities());
auth.setDetails(ud);
auth.setAuthenticated(true);
return setCurrentAuthentication(auth);
} catch (net.sf.acegisecurity.AuthenticationException ae) {
if (logger.isWarnEnabled()) {
// Shows only first 2 symbols of the username and masks all other character with '*' [see also ProtectedUser]
StringBuilder sb = new StringBuilder();
sb.append(ae.getMessage());
sb.append(" [");
sb.append(AuthenticationUtil.maskUsername(userId));
sb.append("] - cannot set details for user");
logger.warn(sb.toString());
}
throw new AuthenticationException(ae.getMessage(), ae);
} finally {
// Support for logging tenantdomain / username (via log4j NDC)
AuthenticationUtil.logNDC(ud.getUsername());
}
}
Aggregations