我最近从JSecurity插件迁移到了Spring Security.如何从我的控制器中获取经过身份验证的用户?
是否有过以下情况:
def user = User.get(springSecurityService.principal.id)
Run Code Online (Sandbox Code Playgroud)
过度
def user = springSecurityService.currentUser
Run Code Online (Sandbox Code Playgroud)
我能想到的是阻止懒惰或确保您当前正在操作的数据不是陈旧的?
我想在注册时显示有关用户登录的信息,例如他的详细信息等...怎么做?因为我刚接触grails plz帮助!我使用Spring安全插件
我是Grails的新手.我使用Spring Security Grails插件进行身份验证.我想在我的视图gsp文件中获取当前用户.
我这样想...
<g:if test="${post.author == Person.get(springSecurityService.principal.id).id }">
<g:link controller="post" action="edit" id="${post.id}">
Edit this post
</g:link>
</g:if>
Run Code Online (Sandbox Code Playgroud)
在这里,我想显示编辑此帖子链接,仅显示由signed_in用户创建的帖子.但它显示出错误 -
Error 500: Internal Server Error
URI
/groovypublish/post/list
Class
java.lang.NullPointerException
Message
Cannot get property 'principal' on null object
Run Code Online (Sandbox Code Playgroud)
这是我的Post.groovy -
class Post {
static hasMany = [comments:Comment]
String title
String teaser
String content
Date lastUpdated
Boolean published = false
SortedSet comments
Person author
....... more code ....
Run Code Online (Sandbox Code Playgroud)
这是我的Person.groovy域类文件 -
class Person {
transient springSecurityService
String realName
String …Run Code Online (Sandbox Code Playgroud)