PreparedStatementCallback;对 SQL[SQLStatememnt] 的无效结果集访问;嵌套异常是 java.sql.SQLException:列索引无效 Spring Auth
PreparedStatementCallback;invalid ResultSet access for SQL[SQLStatememnt];nested exception is java.sql.SQLException:Invalid column index Spring Auth
我是 运行 一个带有 Spring BootSecurtiy 的 Spring 启动应用程序,即身份验证管理器生成器。登录应该由数据库的实体完成。但是每当我登录时它都会显示以下错误。
PreparedStatementCallback; invalid ResultSet access for SQL [SELECT USER_LOGIN_ID, PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?]; nested exception is java.sql.SQLException: Invalid column index
编辑 1:
按照建议,我将查询更改为:
SELECT USER_LOGIN_ID, PASSWORD, ENABLED FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
和
SELECT USER_LOGIN_ID, PASSWORD, ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
我仍然收到错误
Reason: PreparedStatementCallback; bad SQL grammar [SELECT USER_LOGIN_ID, PASSWORD, ENABLED FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00904: "ENABLED": invalid identifier
我的安全配置class
package io.trial;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void globalConfig(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception{
/*auth.jdbcAuthentication()
.dataSource(dataSource)
.authoritiesByUsernameQuery("select p.user as principal, p.password as credentials, true from Provider p where p.user= ?");*/
//System.out.println(dataSource);
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("SELECT USER_LOGIN_ID, PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?")
.authoritiesByUsernameQuery("SELECT USER_LOGIN_ID , PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?");
}
}
它正在尝试读取不存在的列索引,导致此异常。您的数据模型应支持用户的 active/inactive 作为附加列。所以,查询应该是:
SELECT USER_LOGIN_ID, PASSWORD, ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
我没有发现任何其他问题。
感谢 Nisse Engström。将查询更改为
SELECT USER_LOGIN_ID, PASSWORD, 'TRUE' FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
解决了。
我是 运行 一个带有 Spring BootSecurtiy 的 Spring 启动应用程序,即身份验证管理器生成器。登录应该由数据库的实体完成。但是每当我登录时它都会显示以下错误。
PreparedStatementCallback; invalid ResultSet access for SQL [SELECT USER_LOGIN_ID, PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?]; nested exception is java.sql.SQLException: Invalid column index
编辑 1: 按照建议,我将查询更改为:
SELECT USER_LOGIN_ID, PASSWORD, ENABLED FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
和
SELECT USER_LOGIN_ID, PASSWORD, ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
我仍然收到错误
Reason: PreparedStatementCallback; bad SQL grammar [SELECT USER_LOGIN_ID, PASSWORD, ENABLED FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00904: "ENABLED": invalid identifier
我的安全配置class
package io.trial;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled=true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void globalConfig(AuthenticationManagerBuilder auth, DataSource dataSource) throws Exception{
/*auth.jdbcAuthentication()
.dataSource(dataSource)
.authoritiesByUsernameQuery("select p.user as principal, p.password as credentials, true from Provider p where p.user= ?");*/
//System.out.println(dataSource);
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("SELECT USER_LOGIN_ID, PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?")
.authoritiesByUsernameQuery("SELECT USER_LOGIN_ID , PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?");
}
}
它正在尝试读取不存在的列索引,导致此异常。您的数据模型应支持用户的 active/inactive 作为附加列。所以,查询应该是:
SELECT USER_LOGIN_ID, PASSWORD, ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
我没有发现任何其他问题。
感谢 Nisse Engström。将查询更改为
SELECT USER_LOGIN_ID, PASSWORD, 'TRUE' FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
解决了。