How to get current_user by using Spring Security Grails plugin in GSP

后端 未结 4 910
花落未央
花落未央 2021-01-13 13:42

I am newbie in Grails. I am using Spring Security Grails plugin for Authentication purpose. I want to get current user in my view gsp file.

I am trying like this ..

4条回答
  •  广开言路
    2021-01-13 14:18

    Try tags provided by springSecurity plugin, something like:

    
    
      
                Edit this post
          
    
    
    

    Actually you are trying to inject a service on your GSP page, you can do it with some import statement on the page, but I would say it will not be good programming practice, I think you should send current logged In user's instance from the controller to the GSP page, and then perform a check on it:

    let say you have the controller method:

    def showPostPage(){
    Person currentLoggedInUser = springSecurityService.getCurrentUser();
    [currentLoggedInUser:currentLoggedInUser]
    }
    

    and on your GSP page:

    
          
                Edit this post
          
    
    

提交回复
热议问题