在Grails3.0中,如何指定Security应该使用BCrypt进行密码编码?
以下几行应该提供我认为需要做的事情(但我只是猜测):
import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
PasswordEncoder passwordEncoder
passwordEncoder(BCryptPasswordEncoder)我的应用程序将spring-boot-starter-security加载为依赖项:
build.gradle
dependencies {
...
compile "org.springframework.boot:spring-boot-starter-security"我有一个连接到userDetailsService的服务,它使用:
conf/spring/resources.groovy
import com.example.GormUserDetailsService
import com.example.SecurityConfig
beans = {
webSecurityConfiguration(SecurityConfig)
userDetailsService(GormUserDetailsService)
}发布于 2015-05-31 15:08:07
我在grails-app/conf/spring/resources.groovy中有以下代码
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
beans = {
bcryptEncoder(BCryptPasswordEncoder)
}我有一个java文件,它执行spring-security描述的配置。在groovy中也应该可以这样做,但我是在java中完成的。
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);
}
}https://stackoverflow.com/questions/30490862
复制相似问题