Spring安全性在Bootstrap期间返回null SecurityContext

时间:2012-02-01 01:45:04

标签: grails plugins spring-security

我在Grails应用程序中成功使用Spring Security时遇到问题。我安装了spring-security-core插件,然后运行命令来执行初始设置:

s2-quickstart my.package ReUser ReRole

其中ReUser和ReRole分别是我的用户和角色域类。然后我继续按照Peter Ledbrook的Simplified Spring Security屏幕中的设置说明进行操作,但是当我真正尝试运行应用程序并验证用户身份时遇到了麻烦。我在Bootstrap中创建的用户名从未被识别(带有BadCredentialsException),如果我从未存储过那些User,Role和join类值。但是存储它们是,在Bootstrap中声明了保存值的计数。同样,相关的类在Config.groovy中被正确识别为:

grails.plugins.springsecurity.userLookup.userDomainClassName = 're.sec.ReUser'
grails.plugins.springsecurity.userLookup.authorityJoinClassName = 're.sec.ReUserReRole'
grails.plugins.springsecurity.authority.className = 're.sec.ReRole'

这些结果让我感到困惑,直到我在日志中注意到以下序列:

web.FilterChainProxy Converted URL to lowercase, from: '/index.gsp'; to: '/index.gsp'
web.FilterChainProxy Candidate is: '/index.gsp'; pattern is /**; matched=true
web.FilterChainProxy /index.gsp at position 1 of 8 in additional filter chain; firing                    Filter: 'SecurityContextPersistenceFilter'
context.HttpSessionSecurityContextRepository No HttpSession currently exists
context.HttpSessionSecurityContextRepository No SecurityContext was available from the HttpSession: null. A new one will be created.
web.FilterChainProxy /index.gsp at position 2 of 8 in additional filter chain; firing Filter: 'MutableLogoutFilter'
web.FilterChainProxy /index.gsp at position 3 of 8 in additional filter chain; firing Filter: 'RequestHolderAuthenticationFilter'
web.FilterChainProxy /index.gsp at position 4 of 8 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
web.FilterChainProxy /index.gsp at position 5 of 8 in additional filter chain; firing Filter: 'RememberMeAuthenticationFilter'
web.FilterChainProxy /index.gsp at position 6 of 8 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
authentication.AnonymousAuthenticationFilter Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@9055c2bc: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS'
web.FilterChainProxy /index.gsp at position 7 of 8 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
web.FilterChainProxy /index.gsp at position 8 of 8 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
intercept.FilterSecurityInterceptor Public object - authentication not attempted
web.FilterChainProxy /index.gsp reached end of additional filter chain; proceeding with original chain
access.ExceptionTranslationFilter Chain processed normally
context.HttpSessionSecurityContextRepository SecurityContext is empty or anonymous - context will not be stored in HttpSession. 
context.SecurityContextPersistenceFilter SecurityContextHolder now cleared, as request processing completed

这些内容(特别是'SecurityContext是空的还是匿名的 - 上下文不会存储在HttpSession中,所有这些都出现在Bootstraping过程中),解释为什么我的应用程序无法识别我尝试的用户名/密码在Bootstrap期间存储?我做错了什么?

1 个答案:

答案 0 :(得分:1)

您是否在所引用的博客文章中看到了关于对密码进行双重编码的说明?从1.2版开始,用户域类对密码进行编码。如果你在创建用户时再次这样做(例如在BootStrap中),那么它们将被双重编码。