Wrap any DataAccessExceptions thrown by the Ldaptemplate with AuthenticationServiceFailureExceptions

This commit is contained in:
Luke Taylor 2006-05-31 21:46:16 +00:00
parent 5d7a75a421
commit 9f41b9f470
1 changed files with 10 additions and 3 deletions

View File

@ -18,6 +18,7 @@ package org.acegisecurity.providers.ldap;
import org.acegisecurity.AuthenticationException; import org.acegisecurity.AuthenticationException;
import org.acegisecurity.BadCredentialsException; import org.acegisecurity.BadCredentialsException;
import org.acegisecurity.GrantedAuthority; import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.AuthenticationServiceException;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.acegisecurity.providers.dao.AbstractUserDetailsAuthenticationProvider; import org.acegisecurity.providers.dao.AbstractUserDetailsAuthenticationProvider;
@ -31,6 +32,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.dao.DataAccessException;
/** /**
@ -132,7 +134,7 @@ public class LdapAuthenticationProvider extends AbstractUserDetailsAuthenticatio
//~ Methods ======================================================================================================== //~ Methods ========================================================================================================
protected void additionalAuthenticationChecks(UserDetails userDetails, protected void additionalAuthenticationChecks(UserDetails userDetails,
UsernamePasswordAuthenticationToken authentication) UsernamePasswordAuthenticationToken authentication)
throws AuthenticationException { throws AuthenticationException {
if (!userDetails.getPassword().equals(authentication.getCredentials().toString())) { if (!userDetails.getPassword().equals(authentication.getCredentials().toString())) {
throw new BadCredentialsException(messages.getMessage( throw new BadCredentialsException(messages.getMessage(
@ -192,8 +194,13 @@ public class LdapAuthenticationProvider extends AbstractUserDetailsAuthenticatio
"Empty Password")); "Empty Password"));
} }
LdapUserDetails ldapUser = authenticator.authenticate(username, password); try {
LdapUserDetails ldapUser = authenticator.authenticate(username, password);
return createUserDetails(ldapUser, username, password); return createUserDetails(ldapUser, username, password);
} catch (DataAccessException ldapAccessFailure) {
throw new AuthenticationServiceException(ldapAccessFailure.getMessage(), ldapAccessFailure);
}
} }
} }