2014-06-12 26 views
8

PostgreSQL'de yaylı güvenlik için varsayılan şema kullanmak gerçekten imkânsız, bölüm "varchar_ignorecase" does not exist değiştirilemez mi?Spring Security jdbcAuthentication varsayılan şema hatası PostgreSQL

Sadece varsayılan ayarı test ediyorum. Aşağıda

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

Ve

varsayılan şema Nedeni hata

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 

cevap

11

olan PostgreSQL için uygun değildir, ben kendi şema oluşturmak ve kullanıcı ve yetki sorgusu için kendi sorgu uygulamak gerekir.

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

Çözümünüz de MySQL için iyi çalışıyor. –

+1

PostgreSQL ve MySQL için şema neden uygun değil? BTW, çalışıyor ... tks – Hinotori

+1

@Hinotori Varsayılan şema (başına http://docs.spring.io/spring-security/site/docs/current/reference/html/appendix-schema.html) yazılmıştır. HSQLDB için SQL lehçesi (özellikle, PostgreSQL varsayılan kullanıcı şemasında bulunan 'varchar_ignorecase' türüne sahip değildir). Diğer veritabanlarının kullanıcıları bunu çalışan bir şeye çevirmek zorundadır. Bir veritabanını Spring JDBC ile başlatmaya ilişkin belgelere bakın, bazı mükemmel ipuçlarına sahiptir: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto- başlat-a-veritabanı-kullanarak-bahar-jdbc – Lyle