我正在尝试在我的 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/