2015-05-27 11 views
5

Grails 3.0'da, Spring Boot Security yazılımının şifre kodlaması için BCrypt kullanması gerektiğini nasıl belirlersiniz?Spring Boot Security'yi Grails 3.0'da BCrypt şifre kodlamasını kullanmak için yapılandırma

aşağıdaki satırları İhtiyaçlarım ne düşündüğünü duygusu vermelidir yapılması gereken (ama çoğunlukla sadece tahmin ediyorum):

import org.springframework.security.crypto.password.PasswordEncoder 
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder 

PasswordEncoder passwordEncoder 

passwordEncoder(BCryptPasswordEncoder) 

başvurum yükleri spring-boot-starter-security bir bağımlılık olarak:

inşa

dependencies { 
    ... 
    compile "org.springframework.boot:spring-boot-starter-security" 

.gradle Ve ben bir hizmet kullanarak userDetailsService için kablolu:

conf/yay/resources.groovy

import com.example.GormUserDetailsService 
import com.example.SecurityConfig 

beans = { 
    webSecurityConfiguration(SecurityConfig) 
    userDetailsService(GormUserDetailsService) 
    } 

cevap

12

I grails-app/conf/spring/resources.groovy

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder 

beans = { 
    bcryptEncoder(BCryptPasswordEncoder) 
} 

aşağıdaki kod ve spring-security tarafından tarif edildiği gibi yapılandırma yapan bir Java dosyası vardır. Bunu da groovy içinde yapmak mümkün olmalıydı, ama ben java'da yaptım.

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 
import org.springframework.security.config.annotation.web.builders.HttpSecurity; 
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity; 
import org.springframework.security.core.userdetails.UserDetailsService; 
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 

@Configuration 
@EnableWebMvcSecurity 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 
    @Autowired 
    BCryptPasswordEncoder bcryptEncoder; 

    @Autowired 
    UserDetailsService myDetailsService 

    @Override 
    protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
      // userDetailsService should be changed to your user details service 
      // password encoder being the bean defined in grails-app/conf/spring/resources.groovy 
      auth.userDetailsService(myDetailsService) 
       .passwordEncoder(bcryptEncoder); 
    } 
}