Get Spring Security Principal in JSP EL expression

后端 未结 11 2040
终归单人心
终归单人心 2020-12-13 04:07

I am using Spring MVC and Spring Security version 3.0.6.RELEASE. What is the easiest way to get the user name in my JSP? Or even just whether or not the user is logged in? I

11条回答
  •  粉色の甜心
    2020-12-13 05:07

    I agree with alephx, I even voted his answer.

    But if you need another approach, you could use the one that Spring Roo uses.

    If you have the SecurityContextHolderAwareRequestFilter, it provides the standard servlet API security methods, using a request wrapper which accesses the SecurityContext.

    This filter is registered with the tag from the Spring Security namespace. You can also register it in the FilterChainProxy's security filter chain (just add the reference to a declared bean in your applicationContext-security.xml)

    Then, you can access the security servlet API as Roo does (find the footer.jspx to see how a conditional logout link is written)

      
    
    ...
    

提交回复
热议问题