2011-09-07 130 views
2

我有兴趣在成功验证后清除Credentials对象中的纯文本密码,并且想知道做到这一点的最佳方法是什么?看起来它可能会在ProviderManager对象上设置eraseCredentialsAfterAuthentication属性,但在Spring Security插件中如何做到这一点并不明显。Grails Spring Security 1.2.1和eraseCredentialsAfterAuthentication

+0

戴夫,你看到我的答案在下面吗? –

+0

我做过了,它看起来会起作用。谢谢。 – Dave

回答

2

我发现设置此属性的唯一方法是在Bootstrap期间这样做。在BootStrap.groovy中,在init关闭时添加以下两行:

def ctx = org.codehaus.groovy.grails.web.context.ServletContextHolder.servletContext.getAttribute(org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes.APPLICATION_CONTEXT); 

ctx.authenticationManager.setEraseCredentialsAfterAuthentication(true) 

我已经在Grails 1.3.7上测试过了。

+3

BootStrap支持依赖注入,所以你可以在'init()'中添加'def authenticationManager'作为字段并且调用'authenticationManager.eraseCredentialsAfterAuthentication = true' –

1

这在Spring Security插件(1.2.7)的最新版本中更容易实现。只需将此设置添加到Config.groovy

grails.plugins.springsecurity.providerManager.eraseCredentialsAfterAuthentication = true 

它出现的插件版本1.2.2中加入这个选项。