带有 Spring Security 插件和 Salted 密码的 Grails

标签 grails spring-security

我正在尝试在我的 Grails + Spring Security 应用程序中进行加盐密码哈希处理。我使用了 Grails 站点上的教程,以及我在 Internet 上随机找到的教程。

目前,我已经按照this设置了一切。教程。但是,在使用 resources.groovy 中的以下 bean 声明部署应用程序时,我遇到了问题:

saltSource(cq.MySaltSource) {
    userPropertyToUse = CH.config.grails.plugins.springsecurity.dao.reflectionSaltSourceProperty
}

它提示找不到CH

经过一番挖掘,我发现了一篇关于 nabble 的帖子声明如下:

Also - don't use ConfigurationHolder (CH) since it's deprecated in 2.0. You can pass in a reference to the grailsApplication bean and get the config from there:

saltSource(MySaltSource) {
  grailsApplication = ref('grailsApplication')
}

and then in your class add

def grailsApplication

and get the property via

String userPropertyToUse  grailsApplication.config.grails.plugins.springsecurity.dao.reflectionSaltSourceProperty 

我不遵循的部分是关于“...并通过...获取属性”的最后一个陈述。他给出的代码行对我来说似乎格式不正确。

如果有人可以在这里阐明一些观点,或者提供一种在 Grails 和 Spring Security 中使用加盐密码的不同方法,我将不胜感激。请注意,它需要是每个用户唯一的盐,而不是系统范围的盐或单一盐,或者从用户名派生的盐。

谢谢


更新

所以我在第一个教程中得到了它(忘记了 resources.groovy 顶部的 import 语句。但我仍然想使用第二种方式(以与 future 版本保持兼容)。


更新2

如果有人对此感兴趣,我已经写了一个完整的教程:

Setting up a Grails web application using Spring Security and salted passwords.

最佳答案

在定义 saltSource bean 的 resources.groovy 中,GrailsApplication 可用作 application变量,因此您可以将 bean 声明更改为

saltSource(cq.MySaltSource) {
   userPropertyToUse = application.config.grails.plugins.springsecurity.dao.reflectionSaltSourceProperty
}

关于带有 Spring Security 插件和 Salted 密码的 Grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7739296/

相关文章:

grails - Grails Spring Security自定义用户详细信息Bean被覆盖

spring - TAM Webseal + spring 预认证

java - Spring 安全: can't clear authentication object

spring - 移动设备注册 Spring Social

java - 使用 IIS 7/Tomcat 连接器托管的 Grails 应用程序中的错误页面

rest - 如何处理RestResponse

grails - 从Groovy服务类中的应用程序读取XML文件

java - 有没有关于使用 spring security 实现 2-legged oauth 的引用?

session - 在grails 1.3.7中设置 session 变量

spring - Geronimo.out增加太快