Spring安全:SQL [选择用户名,密码来自用户,其中username =?];列索引超出范围,3> 2

时间:2017-11-22 11:14:57

标签: java spring spring-boot spring-security

我正在尝试在Spring启动应用程序中使用spring security。我有以下方法来验证用户:

@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication()
        .dataSource(dataSource)
        .passwordEncoder(bCryptPasswordEncoder)
        .usersByUsernameQuery("select username,password from user where username=?")
        .authoritiesByUsernameQuery("SELECT username,sys_role "
                                    + " FROM user join user_sys_role on user.id=user_sys_role.user_id"
                                    + " where username=?");

}

但是当我向它发送post请求时它失败了,当我调试应用程序时它会提供错误:

org.springframework.security.authentication.InternalAuthenticationServiceException: PreparedStatementCallback; SQL [select username,password from user where username=?]; Column Index out of range, 3 > 2. ; nested exception is java.sql.SQLException: Column Index out of range, 3 > 2.

我该如何解决?

似乎,

中存在问题
 .usersByUsernameQuery("select username,password from user where username=?")

0 个答案:

没有答案