2017-05-27 96 views
0

我使用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=?"); 
    } 
} 
+2

[Spring Security:configure(AuthenticationManagerBuilder auth)](https://stackoverflow.com/questions/42928268/spring-security-configureauthenticationmanagerbuilder-auth) – dur

回答

1

它試圖讀取一個不存在的列索引造成這種例外。您的數據模型應該支持用戶的活動/不活動作爲附加列。所以,查詢應該是:

SELECT USER_LOGIN_ID, PASSWORD, ACTIVE FROM USER_ACCOUNT WHERE USER_LOGIN_ID=? 

我沒有看到任何其他問題。

+0

的可能重複請檢查編輯。 –

+0

我在數據庫中沒有活動或非活動狀態。 –

0

感謝NisseEngström。更改查詢

SELECT USER_LOGIN_ID,密碼, '真' FROM USER_ACCOUNT WHERE USER_LOGIN_ID =?

解決了它。

相關問題