Grails authenticatedUser为null,但principle不为null
这里是Grails安全的新手。我正在浏览文档,并尝试了这个。 成功登录后,why is authenticated user为null,即使主体已填充。我还有别的事要做吗Grails authenticatedUser为null,但principle不为null,grails,spring-security,grails-2.0,grails-plugin,Grails,Spring Security,Grails 2.0,Grails Plugin,这里是Grails安全的新手。我正在浏览文档,并尝试了这个。 成功登录后,why is authenticated user为null,即使主体已填充。我还有别的事要做吗 class SecureController { @Secured(['ROLE_ADMIN']) def userInfo(){ if (isLoggedIn()){ //authenticatedUser is null though user is authenticated. r
class SecureController {
@Secured(['ROLE_ADMIN'])
def userInfo(){
if (isLoggedIn()){
//authenticatedUser is null though user is authenticated.
render authenticatedUser
//render principal
}
}
}
从文件中
getAuthenticatedUser
从与当前域相对应的数据库加载用户域类实例
已验证的用户,如果未验证,则为null。这是
相当于为springSecurityService添加依赖项注入
和呼唤
PersonDomainClassName.get(springSecurityService.principal.id)(
通常采用的典型方法)
您需要在控制器中注入springSecurityService
class SecureController {
def springSecurityService
@Secured(['ROLE_ADMIN'])
def userInfo(){
if (springSecurityService.isLoggedIn()){
//authenticatedUser is null though user is authenticated.
render authenticatedUser
//render principal
}
}
}
您还可以使用springSecurityService.getCurrentUser()检查是否有有效的登录用户并呈现该用户。问题很清楚,看看吧 我不认为我需要注入springSecurityService,除非我在代码中直接使用它。isLoggedIn()是一种方便的访问器方法。但我的问题是,无论我是否注射isLoggedIn,isLoggedIn都有效。主体也被填充。我遇到问题的是经过身份验证的用户。