Spring Security JDBC authentication default schema error when using PostgreSQL

£可爱£侵袭症+ 提交于 2019-12-03 16:39:17

问题


Is it really impossible to use default schema for Spring Security with PostgreSQL, because the part "varchar_ignorecase" does not exist can't be replaced?

I'm just testing the default settings:

auth.jdbcAuthentication()
            .dataSource(dataSource)
            .withDefaultSchema();

And below is the error:

Caused by:
org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.servlet.Filter org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain() throws java.lang.Exception] threw exception;

nested exception is
org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement at line 1 of resource class path resource
[org/springframework/security/core/userdetails/jdbc/users.ddl]: create table users(username varchar_ignorecase(50) not null primary key,password varchar_ignorecase(500) not null,enabled boolean not null);

nested exception is
org.postgresql.util.PSQLException: ERROR: type "varchar_ignorecase" does not exist


回答1:


Cause the default schema is not suitable for PostgreSQL, I need to create my own schema and implement own query for user and authority query.

auth.jdbcAuthentication()
                .dataSource(dataSource)
                .usersByUsernameQuery(
                        "select username,password, enabled from users where username=?")
                .authoritiesByUsernameQuery(
                        "select username, role from user_roles where username=?");


来源:https://stackoverflow.com/questions/24174884/spring-security-jdbc-authentication-default-schema-error-when-using-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!