Spring Security Custom Login
Spring Security provides it's own built-in login module to authenticate the user. It validates the user credentials and provide accessibility into the application.
The login page rendered by the module is built-in. So, we does not require to create new jsp page. But if we want to customize the login page then how we can?
The answer is, we can create our own jsp login page and integrate to the application. In this topic we will create a custom login page and will use it to get login.
See, an example. Create a maven project by providing following details.
After finishing, it creates the following project structure.
Configure project to apply spring security. It require following four files. Create a package com.javatpoint and put these files into this.
See, in configure method, after formLogin() a method loginPage("/login") is used. It is the actual method that required to call custom login page.
First create a login page our own. According to the spring official, the login page should looks like the below.
Create a controller HomeController inside the com.javatpoint.controller package.
Our project looks like the this:
Run the Server
Now, login by providing user credentials.
See, it's working fine. Now, we can create it more decorative and custom according to the need.
Download this example.