我使用Spring BootSecurtiy即身份驗證管理器構建器運行Spring Boot應用程序。登錄應該由數據庫的實體完成。但是,無論何時登錄,它都會顯示以下錯誤。PreparedStatementCallback;對於SQL [SQLStatememnt]無效的ResultSet訪問;嵌套的異常是java.sql.SQLException:無效的列索引Spring Auth
PreparedStatementCallback; SQL無效的ResultSet訪問[SELECT USER_LOGIN_ID,PASSWORD FROM USER_ACCOUNT WHERE USER_LOGIN_ID =?];嵌套的異常是java.sql.SQLException中:無效的列索引
編輯1: 如所建議的,我改變查詢以:
SELECT USER_LOGIN_ID,密碼ENABLED FROM USER_ACCOUNT WHERE USER_LOGIN_ID =?
和
SELECT USER_LOGIN_ID,密碼,ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID =?
我仍然得到錯誤的
原因:PreparedStatementCallback;錯誤的SQL語法[SELECT USER_LOGIN_ID,PASSWORD,ENABLED FROM USER_ACCOUNT WHERE USER_LOGIN_ID =?];嵌套的例外是java.sql.SQLSyntaxErrorException:ORA-00904:「啓動」:無效的標識符
我的安全配置類
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=?");
}
}
[Spring Security:configure(AuthenticationManagerBuilder auth)](https://stackoverflow.com/questions/42928268/spring-security-configureauthenticationmanagerbuilder-auth) – dur