In this recipe, you'll learn how to display some elements of a page only to authenticated users. For example, a summary box with the information about the account of the currently logged-in user.
Use the <sec:authorize>
tag in the JSP file to add conditions for some content to be displayed:
Add the Maven dependency for the Spring Security JSP tags library in
pom.xml
:<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> <version>3.2.5.RELEASE</version> </dependency>
In the JSP, declare the tag library and use
<sec:authorize>
:<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> <sec:authorize access="isAuthenticated()"> Username: <sec:authentication property="principal.username" /> </sec:authorize>