Get Spring Security Principal in JSP EL expression

Get Spring Security Principal in JSP EL expression

Asked on October 24, 2018 in Spring.
Add Comment


  • 3 Answer(s)

    Use this code:

    <sec:authorize access="isAuthenticated()">
    
    
    Answered on October 24, 2018.
    Add Comment
    <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
    

       Create a user object by adding:

    <sec:authentication var="user" property="principal" />
    

       Then when we can show the username by adding. the ‘principal’ object is generally of the type string unless we have implemented the spring security in a way to change it to another Class in our project:

    <sec:authorize access="hasRole('ROLE_USER') and isAuthenticated()">
    ${user}
    </sec:authorize>
    
    Answered on October 24, 2018.
    Add Comment

    Use this: Spring Security Tag Lib – 3.1.3.RELEASE

    <sec:authentication var="principal" property="principal" />
    
    

    then

    ${principal.username}
    
    
    Answered on October 24, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.