我的grails 2.2 app有一个简单的基于自定义表单的登录控制器,可以根据外部系统对用户进行身份验证,并返回一个布尔响应。如果成功响应,则调用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
}