我正在使用Spring BootSecurtiy运行Spring Boot应用程序,即身份验证管理器构建器。登录应该由数据库的实体完成。但每次登录时都会显示以下错误。
PreparedStatementCallback; SQL的SELECTSet访问权限无效[SELECT USER_LOGIN_ID,PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID =?];嵌套异常是java.sql.SQLException:列索引无效
编辑1: 建议我将查询更改为:
SELECT USER_LOGIN_ID,PASSWORD,USER_ACCOUNT USEREROGIN_ID =?
从USER_ACCOUNT启用
和
SELECT USER_LOGIN_ID,PASSWORD,ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID =?
我仍然得到错误
原因:PreparedStatementCallback;错误的SQL语法[SELECT USER_LOGIN_ID,PASSWORD,USER_ACCOUNT EERE BLED USER_LOGIN_ID =?];嵌套异常是java.sql.SQLSyntaxErrorException:ORA-00904:“ENABLED”:标识符无效
我的安全配置类
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=?");
}
}
答案 0 :(得分:1)
它正在尝试读取不存在导致此异常的列索引。您的数据模型应支持用户的活动/非活动作为附加列。所以,查询应该是:
SELECT USER_LOGIN_ID, PASSWORD, ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID=?
我没有看到任何其他问题。
答案 1 :(得分:0)
感谢NisseEngström。将查询更改为
SELECT USER_LOGIN_ID,PASSWORD,'TRUE'来自USER_ACCOUNT,其中USER_LOGIN_ID =?
解决了它。