2014-06-12 9 views
8

पोस्टग्रेएसक्यूएल पर वसंत सुरक्षा के लिए डिफ़ॉल्ट योजना का उपयोग करना वास्तव में असंभव है, भाग "varchar_ignorecase" does not exist को प्रतिस्थापित नहीं किया जा सकता है?स्प्रिंग सुरक्षा jdbc प्रमाणीकरण डिफ़ॉल्ट योजना त्रुटि PostgreSQL

मैं बस डिफ़ॉल्ट सेटिंग का परीक्षण कर रहा हूं।

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

और नीचे त्रुटि

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 

उत्तर

11

कारण डिफ़ॉल्ट स्कीमा है PostgreSQL लिए उपयुक्त नहीं है, मैं अपने ही स्कीमा बना सकते हैं और उपयोगकर्ता और अधिकार क्वेरी के लिए खुद क्वेरी को लागू करने की जरूरत है।

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

आपका समाधान भी MySQL के लिए ठीक काम करता है। –

+1

PostgreSQL और MySQL के लिए स्कीमा "उपयुक्त नहीं" क्यों है? बीटीडब्लू, यह काम कर रहा है ... tks – Hinotori

+1

@ हिनोटरि डिफ़ॉल्ट स्कीमा (प्रति http://docs.spring.io/spring-security/site/docs/current/reference/html/appendix-schema.html) एक में लिखा गया है एचएसक्यूएलडीबी के लिए एसक्यूएल बोली (विशेष रूप से, PostgreSQL में 'varchar_ignorecase' प्रकार नहीं है जो डिफ़ॉल्ट उपयोगकर्ता स्कीमा में मौजूद है)। अन्य डेटाबेस के उपयोगकर्ताओं को उस चीज़ को अनुवाद करने की आवश्यकता होती है जो काम करता है। यहां वसंत जेडीबीसी के साथ डेटाबेस शुरू करने के लिए प्रलेखन देखें, इसमें कुछ उत्कृष्ट युक्तियां हैं: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto- प्रारंभिक-ए-डेटाबेस-उपयोग-वसंत-जेडीबीसी – Lyle

संबंधित मुद्दे