2014-06-12 12 views
8

Thực sự không thể sử dụng lược đồ mặc định cho bảo mật mùa xuân trên PostgreSQL, phần "varchar_ignorecase" does not exist không thể thay thế được?Lỗi bảo mật mùa xuân jdbcAuthentication lược đồ mặc định trên PostgreSQL

Tôi chỉ đang thử nghiệm cài đặt mặc định.

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

Và dưới đây là lỗi

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 

Trả lời

11

Nguyên nhân schema mặc định là không thích hợp cho PostgreSQL, tôi cần phải tạo giản đồ của riêng tôi và thực hiện các truy vấn riêng cho người sử dụng và quyền hạn truy vấn.

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

Giải pháp của bạn cũng hoạt động tốt cho cả MySQL. –

+1

Tại sao lược đồ là "không phù hợp" cho PostgreSQL và MySQL? BTW, nó hoạt động ... tks – Hinotori

+1

@Hinotori Giản đồ mặc định (theo http://docs.spring.io/spring-security/site/docs/current/reference/html/appendix-schema.html) được viết bằng Phương ngữ SQL cho HSQLDB (đặc biệt, PostgreSQL không có kiểu 'varchar_ignorecase' có trong lược đồ người dùng mặc định). Người sử dụng các cơ sở dữ liệu khác cần phải dịch nó sang một cái gì đó hoạt động. Xem tài liệu về việc khởi tạo một cơ sở dữ liệu với Spring JDBC ở đây, nó có một số mẹo tuyệt vời: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto- initialize-a-database-using-spring-jdbc – Lyle

Các vấn đề liên quan