2014-06-12 13 views
8

È davvero impossibile utilizzare lo schema di default per la sicurezza Spring su PostgreSQL, la parte "varchar_ignorecase" does not exist non può essere sostituita?Spring Security jdbcAuthentication errore di schema predefinito su PostgreSQL

Sto solo testando l'impostazione predefinita.

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

E sotto è l'errore

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 

risposta

11

Causa lo schema predefinito non è adatto per PostgreSQL, ho bisogno di creare il mio schema e implementare propria query per l'utente e l'autorità query.

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

La soluzione funziona anche con MySQL. –

+1

Perché lo schema è "non adatto" per PostgreSQL e MySQL? A proposito, funziona ... tks – Hinotori

+1

@Hinotori Lo schema predefinito (per http://docs.spring.io/spring-security/site/docs/current/reference/html/appendix-schema.html) è scritto in un Dialetto SQL per HSQLDB (in particolare, PostgreSQL non ha il tipo 'varchar_ignorecase' che è presente nello schema utente predefinito). Gli utenti di altri database devono tradurli in qualcosa che funzioni. Vedere la documentazione sull'inizializzazione di un database con Spring JDBC qui, ha alcuni suggerimenti eccellenti: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto- initialize-a-database-using-spring-jdbc – Lyle

Problemi correlati