When making JDBC Authentication in Spring Boot, do I have to use the default 'users' table?

Yaşar Selçuk Çalışkan :

I am trying to use JDBC Authentication in Spring Boot. I am trying to use a different table than the default 'users'. But with this method

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.jdbcAuthentication().dataSource(dataSource)
        .usersByUsernameQuery("SELECT email as USERNAME, PASSWORD as password FROM [user_account] WHERE email=?");
}

With the given table schema: [![f][1]][1]

I get the following error:

17:34:29.800 [http-nio-8081-exec-1] INFO  o.s.j.support.SQLErrorCodesFactory - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
17:34:29.806 [http-nio-8081-exec-1] WARN  o.s.s.o.p.endpoint.TokenEndpoint - Handling error: [![enter image description here][2]][2]InternalAuthenticationServiceException, PreparedStatementCallback; SQL [SELECT email as USERNAME, PASSWORD as password FROM [user_account] WHERE email=?]; The index 3 is out of range.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The index 3 is out of range.

What can I do to use my own user data table for JDBC Authentication?

Jayesh :

can you update your query by appending enabled as the third paramater to select

SELECT email as USERNAME, PASSWORD as password, enabled FROM [user_account] WHERE email=?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=108026&siteId=1