У меня проблема с изменением кода. У меня был проект Spring с колонками email, паролем, активным пользователем. Теперь я хотел сделать то же самое, но без проверки активации. Изменено Spring Security на:
#SPRING SECURITY
spring.queries.users-query=select email, password from user where email=?
spring.queries.roles-query=select u.email, r.role from user u inner join user_role ur on(u.user_id=ur.user_id) inner join role r on(ur.role_id=r.role_id) where u.email=?
Моя настройка безопасности:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private BCryptPasswordEncoder bcp;
@Autowired
private DataSource ds;
@Value("${spring.queries.users-query}")
private String usersQuery;
@Value("${spring.queries.roles-query}")
private String rolesQuery;
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().usersByUsernameQuery(usersQuery).authoritiesByUsernameQuery(rolesQuery).dataSource(ds)
.passwordEncoder(bcp);
}
protected void configure(HttpSecurity httpSec) throws Exception {
httpSec.authorizeRequests().antMatchers("/").permitAll().antMatchers("/login").permitAll()
.antMatchers("/register").permitAll().antMatchers("//adduser").permitAll().antMatchers("/admin")
.hasAuthority("ROLE_ADMIN").anyRequest().authenticated().and().csrf().disable().formLogin()
.loginPage("/login").failureUrl("/login?error=true").defaultSuccessUrl("/").usernameParameter("email")
.passwordParameter("password").and().logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/").and().exceptionHandling().accessDeniedPage("/denied");
}
public void configure(WebSecurity webSec) throws Exception {
webSec.ignoring().antMatchers("/resources/**", "/statics/**", "/css/**", "/js/**", "/images/*", "/incl/**");
}
}
во время входа у меня есть исключение, подобное этому:
[2020-03-26 12:30:09 ] [org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter][ERROR] An internal error occurred while trying to authenticate the user.
org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; SQL [select email, password from user where email=?]; Column Index out of range, 3 > 2. ; nested exception is java.sql.SQLException: Column Index out of range, 3 > 2.
Пожалуйста, помогите, что я нужно сделать :(?