2011-09-07 76 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中加入這個選項。