package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import .Pbkdf2PasswordEncoder;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
public class LoginAuthenticationProvider extends DaoAuthenticationProvider {
public LoginAuthenticationProvider(UserDetailsService userDetailsService) {
super();
// 这个地方一定要对userDetailsService赋值,不然userDetailsService是null (这个坑有点深)
setUserDetailsService(userDetailsService);
setPasswordEncoder(createDelegatingPasswordEncoder());
}
protected void additionalAuthenticationChecks(UserDetails userDetails,
UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
if (() == null) {
throw new BadCredentialsException(
("", "Bad credentials"));
}
String presentedPassword = ()+().toString();
PasswordEncoder passwordEncoder =getPasswordEncoder();
if (!(presentedPassword, ())) {
("Authentication failed: password does not match stored value");
throw new BadCredentialsException((
"",
"Bad credentials"));
}
}
public static PasswordEncoder createDelegatingPasswordEncoder() {
String encodingId = "SHA-256";
Map<String, PasswordEncoder> encoders = new HashMap<>();
(encodingId, new BCryptPasswordEncoder());
("ldap", new org.());
("MD4", new org..Md4PasswordEncoder());
("MD5", new org.("MD5"));
("noop", ());
("pbkdf2", new Pbkdf2PasswordEncoder());
("scrypt", new SCryptPasswordEncoder());
("SHA-1", new org.("SHA-1"));
("SHA-256", new org.("SHA-256"));
("sha256", new org.());
return new MessageDigestPasswordEncoder("SHA-256");
}
}