How can i get already logged in user authority in jspx page? like SecurityContextHolder.getContext().getAuthenticati on().getName()
Printable View
How can i get already logged in user authority in jspx page? like SecurityContextHolder.getContext().getAuthenticati on().getName()
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">
<spring:param name="ownerId" value="${owner.id}"/>
<spring:param name="petId" value="${pet.id}"/>
</spring:url>
<a href="${fn:escapeXml(visitUrl)}">Add Visit</a>
</td>
</sec:authorize>