Spring boot 2 WebSecurityConfigurerAdapter
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Autowired
private DataSource dataSource;
private static final String USER_SQL = "SELECT" +
" id," +
" login," +
" password" +
" FROM" +
" user" +
" WHERE" +
" login = ?";
private static final String ROLE_SQL = "SELECT" +
" id," +
" login," +
" role" +
" FROM" +
" user" +
" WHERE" +
" login = ?";
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/loginUp").permitAll()
.antMatchers("/signUp").permitAll()
.anyRequest().authenticated();
http.formLogin()
.loginProcessingUrl("/loginUp")
.loginPage("/loginUp")
.failureUrl("/loginUp")
.usernameParameter("login")
.passwordParameter("password")
.defaultSuccessUrl("/", true);
http.csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception{
auth.jdbcAuthentication()
.dataSource(dataSource)
.usersByUsernameQuery(USER_SQL)
.authoritiesByUsernameQuery(ROLE_SQL)
.passwordEncoder(passwordEncoder());
}
}
Пытаюсь настроить конфиг но при попытке авторизации мне возвращает ошибку с зашифрованным паролем:
Caused by: java.lang.NumberFormatException: For input string: "$2a$10$ZG2UwNC.PNKoQyWLEAPj6eALixruO9nNinM0Mxi2RdwvMpcxSSCDy"
Я думаю что ошибка в присвоении/проверки ролей, потому что я не понимаю как оно может определять роли и давать доступ, в том виде что реализовано у меня