Spring Security Authentication

The Spring Security Authentication object is primarily used to gain access to the object that represents the Logged in user.

The authentication object follows the standard bean naming convention.

The tag has below properties.

  • name:
  • authorities:
  • credentials:
  • details:
  • principal
  • isAuthenticated:

Now to read the logged in user we shall be adding the following code inside our JSP page

<sec:authentication property="name" />

Now the modified home.jsp will be something like this

home.jsp


<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page session="false"%>
<html>
<head>
<title>Home</title>
</head>
<body>
     
<P>Welcome <sec:authentication property="name" /> !, <br/>
The time on the server is ${serverTime}.
 
 
     
<form action="whoami" method="get">
        <input type="text" name="userName">
 <input type="submit" value="Login">
    </form>
 
</body>
</html>
Doubts? WhatsApp me !