Whenever we deal with password in an application, we go for some encryption. In spring the password it authenticated within the configuration.
Here is the sample code where we have already saved the password in encrypted form and now during login the password is verified with encryption in the configuration file.
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
// CustomUserDetailsService with service name @Service("userDetailsService")
@Qualifier("userDetailsService")
private UserDetailsService userDetailsService;
@Autowired
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
//bean for md5 encryption
@Bean
public Md5PasswordEncoder passwordEncoder() throws Exception {
return new Md5PasswordEncoder();
}
}
0 Comment(s)