throws AuthenticationException {
if (authentication.getCredentials() == null) {
logger.debug("Authentication failed: no credentials provided");
throw new BadCredentialsException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.badCredentials",
"Bad credentials"));
}
String presentedPasswd = authentication.getCredentials().toString();
String salt = null;
if(userDetails instanceof CartUserDetails){
CartUserDetails cartUserDetails = (CartUserDetails)userDetails;
salt = cartUserDetails.getSalt();
}else{
throw new AuthenticationServiceException("UserDetails cannot be casted to CartUserDetails");
}
String encPass = Password.encode(salt.toString(), presentedPasswd);
if(!StringUtils.equals(userDetails.getPassword(), encPass)){
logger.debug("Authentication failed: password does not match stored value");
throw new BadCredentialsException(messages.getMessage(
"AbstractUserDetailsAuthenticationProvider.badCredentials",
"Bad credentials"));
}
}