Grails and Spring Security: How do I get the authenticated user from within a controller?

后端 未结 6 2060
说谎
说谎 2020-12-09 19:13

I recently moved from the JSecurity plugin to Spring Security. How do I get the authenticated user from within my controllers?

6条回答
  •  难免孤独
    2020-12-09 20:02

    I'm using 0.5.1 and the following works for me:

    class EventController {
      def authenticateService
    
      def list = { 
         def user = authenticateService.principal() 
         def username = user?.getUsername()
         .....
         .....
      } 
    }
    

提交回复
热议问题