我的 grails 2.2 应用程序有一个简单的基于自定义表单的登录控制器,它针对外部系统对用户进行身份验证并返回一个布尔响应。如果响应成功,它会调用 reauthenticate 方法,更新会话并重定向。
springSecurityService.reauthenticate(thisuser.username)
session['SPRING_SECURITY_CONTEXT'] = SecurityContextHolder.context
if (springSecurityService.isLoggedIn()) {
println "Redirecting to postauth"
redirect(action: 'postauth')
}
问题是重定向后新页面将无法呈现。从用户的角度来看,登录页面在单击登录按钮后不会更改,即使在日志中用户已登录并且具有身份验证的活动会话。但是,如果您单击按钮转到主页,它会显示用户已通过身份验证并且一切正常,但直到采取此操作或其他操作时才会显示。阅读我在文档和类似的 stackoverflow 问题中可以找到的所有内容,但我被困在这里。
日志
pid.authenticateads: [juser:testuser, action:authenticateads, controller:pid]
ADS Validation:true
testuser is logged in
Authentication org.springframework.security.authentication.UsernamePasswordAuthenticationToken@1927f6c4: Principal: org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser@ba7ee5b2: Username: testuser; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_ADMIN
Session Content:
SPRING_SECURITY_CONTEXT = org.springframework.security.core.context.SecurityContextImpl@1927f6c4: Authentication: org.springframework.security.authentication.UsernamePasswordAuthenticationToken@1927f6c4: Principal: org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser@ba7ee5b2: Username: testuser; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: null; Granted Authorities: ROLE_ADMIN
Redirecting to postauth
pid.postauth: [action:postauth, controller:pid]
In postauth action, redirecting to Cluster controller, action search
cluster.search: [action:search, controller:cluster]
试图添加一些额外的不必要的重定向只是为了确保主体被通过,但问题在于渲染。搜索 gsp 基本上是空白的,以消除任何用于测试的资源插件布局问题。调试已打开,并且没有呈现错误或资源错误。它调用显示页面,但实际上没有任何更新。同样,如果我在登录后转到浏览器并手动更改 url,则显示用户已登录。还尝试清除 cachedRequestMaps 和所有 sessionfixationprevention 选项。
class ClusterController {
def springSecurityService
def search() {
def user = User.get(springSecurityService.principal.id)
println "In Cluster controller, action: search, user: "+user.username
}