Skip to content

Instantly share code, notes, and snippets.

@bytestree
Last active May 6, 2016 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bytestree/ead02e7ce44e51645e3a5853fa80fea5 to your computer and use it in GitHub Desktop.
Save bytestree/ead02e7ce44e51645e3a5853fa80fea5 to your computer and use it in GitHub Desktop.
Custom Login page for Spring Security 4 including CSRF token config
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Spring Security</title>
</head>
<body>
<div>
<form action="login" method="post">
<fieldset>
<legend>Please Login</legend>
<c:if test="${param.error != null}">
<div>
<p>Authentication Failed : ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}</p>
</div>
</c:if>
<c:if test="${param.logout != null}">
<div>
<p>You have been logged out successfully.</p>
</div>
</c:if>
<label for="username">Username</label>
<input type="text" id="username" name="username" /> <br>
<label for="password">Password</label>
<input type="password" id="password" name="password" /> <br>
<div>
<button type="submit">Log in</button>
</div>
</fieldset>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
</form>
</div>
</body>
</html>
@bytestree
Copy link
Author

Refer Spring Security 4 with Hibernate for complete example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment