Announcement Announcement Module
Collapse
No announcement yet.
Security Context Holder Jspx Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Security Context Holder Jspx

    How can i get already logged in user authority in jspx page? like SecurityContextHolder.getContext().getAuthenticati on().getName()

  • #2
    I assume you mean the name from the principal (there is not getName() on Authentication). You can use the Spring Security authentication tag to access properties on the Authentication object. For example the following will be the equivalent of SecurityContextHolder.getAuthentication().getPrinc ipal().getName()

    Code:
    <jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:spring="http://www.springframework.org/tags"
        xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
    
       ...
        <sec:authentication property="principal.name"/>
       ...
    </jsp:root>

    Comment


    • #3
      Thaks for reply

      Originally posted by rwinch View Post
      I assume you mean the name from the principal (there is not getName() on Authentication). You can use the Spring Security authentication tag to access properties on the Authentication object. For example the following will be the equivalent of SecurityContextHolder.getAuthentication().getPrinc ipal().getName()

      Code:
      <jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core"
          xmlns:spring="http://www.springframework.org/tags"
          xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
      
         ...
          <sec:authentication property="principal.name"/>
         ...
      </jsp:root>
      According to your reply i got the answer i was loookinf for exactly
      code below .Thanks very much
      <sec:authorize access="hasRole('ROLE_SUPERVISOR')">
      <td>
      <spring:url value="{ownerId}/pets/{petId}/visits/new" var="visitUrl">
      <springaram name="ownerId" value="${owner.id}"/>
      <springaram name="petId" value="${pet.id}"/>
      </spring:url>
      <a href="${fn:escapeXml(visitUrl)}">Add Visit</a>
      </td>
      </sec:authorize>

      Comment

      Working...
      X