It is a login process using the ID and password entered from the screen. Since the password is hashed and stored in the database user table, I had to compare the password entered with the hash value stored in the database.
Authentication is NG when trying to log in with the account that should be stored in the user table. If you remove the hashing process and log in in plain text, authentication is OK.
I wrote such a source.
WebSecurityConfig.java(Before correction)
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UserDetailsServiceImpl userDetailsService;
/**~ Omitted ~*/
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}
}
When I googled the article about Spring login authentication, it was written that most sites set the password encoding method in the configureGlobal
method.
I'm doing exactly what is written on the site I'm referring to! ?? If you think
Apparently it was overwritten by the settings in the configure
method.
It seems that it was the processing order. I don't understand it in great detail, so I thought I should know the life cycle of Spring properly.
WebSecurityConfig.java(Revised)
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
UserDetailsServiceImpl userDetailsService;
/**~ Omitted ~*/
@Bean
PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
/**~ Delete configure method ~*/
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService)
.passwordEncoder(passwordEncoder());
}
}
Recommended Posts