2014-06-12 11 views
8

Jest naprawdę niemożliwe, aby użyć domyślnego schematu dla bezpieczeństwa wiosny w PostgreSQL, część "varchar_ignorecase" does not exist nie może być zastąpiona?Spring Security jdbcAuthentication domyślny błąd schematu na PostgreSQL

Właśnie testuję ustawienie domyślne.

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

A poniżej jest błąd

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 

Odpowiedz

11

Przyczyna domyślnego schematu nie nadaje się do PostgreSQL, muszę stworzyć własny schemat i realizować własne zapytanie do zapytania użytkownika i władzy.

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

Twoje rozwiązanie działa również dla MySQL. –

+1

Dlaczego schemat jest "nieodpowiedni" dla PostgreSQL i MySQL? BTW, działa ... tks – Hinotori

+1

@Hinotori Schemat domyślny (na http://docs.spring.io/spring-security/site/docs/current/reference/html/appendix-schema.html) jest napisany w Dialekt SQL dla HSQLDB (w szczególności, PostgreSQL nie ma typu "varchar_ignorecase", który jest obecny w domyślnym schemacie użytkownika). Użytkownicy innych baz danych muszą przetłumaczyć to na coś, co działa. Zobacz dokumentację na temat inicjowania bazy danych w Spring JDBC tutaj, ma kilka doskonałych wskazówek: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto- initialize-a-database-using-spring-jdbc – Lyle

Powiązane problemy