gpt4 book ai didi

Grails Spring Security 默认配置 : How to define default user and password

转载 作者:行者123 更新时间:2023-12-02 14:06:49 26 4
gpt4 key购买 nike

在纯净的 Spring 我可以这样做

<security:authentication-manager>
<security:authentication-provider user-service-ref="customUserDetailsService">
<security:password-encoder ref="passwordEncoder"/>
</security:authentication-provider>
<security:authentication-provider>
<security:user-service>
<security:user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" />
</security:user-service>

是否可以通过 Spring Security 插件在 Grails 中做同样的事情?

我可以实现自己的身份验证提供,但在这种情况下,我将存储在类中硬编码的凭据。

最佳答案

您可以使用 InMemoryUserDetailsManager(在 resources.groovy 中)来完成此操作:

import org.springframework.security.provisioning.InMemoryUserDetailsManager
import org.springframework.security.core.userdetails.User
import org.springframework.security.core.authority.SimpleGrantedAuthority

beans = {
userDetailsService(InMemoryUserDetailsManager,
[new User('admin', 'password hash', [new SimpleGrantedAuthority('ROLE_ADMIN')])])
}

关于Grails Spring Security 默认配置 : How to define default user and password,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32952909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com