Encryption
Md5PasswordEncoder md5PasswordEncoder =new Md5PasswordEncoder();
md5PasswordEncoder.encodePassword(userRegistrationInfo.getPassword(),AppConstants.MD5_PASSWORD_ENCODER_SALT);
Spring Security Configuration
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
@Bean
public PasswordEncoder passwordEncoder(){
PasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;
}
我需要使用org.springframework.security.authentication.encoding.Md5PasswordEncoder进行密码加密。但是我不知道如何在Spring安全配置中配置passwordEncoder()
最佳答案
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(customUserDetailsService)
.passwordEncoder(passwordEncoder());
}
}
@Bean
public PasswordEncoder passwordEncoder(){
//implements PasswordEncoder and overide encode method with the MD5 protocol
return new MD5PasswordEncoder();
}