Spring Boot Web应用程序,Spring Data JPA,Spring Security,FlywayDB。
SQL
INSERT INTO USER(FIRST_NAME, LAST_NAME, EMAIL, PASSWORD, USER_GROUP) values('D', 'J', 'D@J.com', '123', 'ROLE_USER');
安全配置
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private UserDetailsService userDetailsService;
@Autowired
private BCryptPasswordEncoder bCryptPasswordEncoder;
@Bean
public BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.antMatchers("/**").hasAnyRole("ROLE_USER", "ROLE_ADMIN")
.and()
.formLogin()
.and()
.logout()
.logoutUrl("/logout");
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
}
}
当我尝试使用我使用FlywayDB迁移创建的用户登录时,它不起作用。我收到错误消息“bad credentials”。执行期间没有其他错误。
我是否错过了配置?