2015-05-27 11 views
5

W Grails 3.0, w jaki sposób określić, że Spring Boot Security powinien używać BCrypt do kodowania hasłem?Konfigurowanie Spring Boot Security w celu użycia kodowania haseł BCrypt w Grails 3.0

następujące linie powinny zapewnić poczucie tego, co myślę, że należy zrobić (ale ja przeważnie właśnie zgadywania):

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

PasswordEncoder passwordEncoder 

passwordEncoder(BCryptPasswordEncoder) 

moja aplikacja ładunki spring-boot-starter-security jako zależność:

budowlanej .gradle

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

i mam usługa okablowany dla userDetailsService używając:

conf/źródło/resources.groovy

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

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

Odpowiedz

12

I mają następujące kod grails-app/conf/spring/resources.groovy

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

beans = { 
    bcryptEncoder(BCryptPasswordEncoder) 
} 

i ma pliku javy która nie konfigurację opisaną przez spring-security. Powinno być możliwe robienie tego również w groovy, ale zrobiłem to w Javie.

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); 
    } 
} 
Powiązane problemy