Spring Security 1: First Application

DemoController:

1
2
3
4
5
6
7
8
@Controller
public class DemoController {
// This is the index of application
@GetMapping("/")
public String showHome() {
return "home";
}
}

LoginController:

1
2
3
4
5
6
7
8
9
@Controller
public class LoginController {
// Due to the DemoSecurityConfig,
// before we accessing the index page, we have to login
@GetMapping("/showMyLoginPage")
public String showMyLoginPage() {
return "fancy-login";
}
}

login.jsp:

1
2
3
4
5
<c:if test="${param.error != null}">
<div>
Invalid username and password.
</div>
</c:if>

In Spring Security system, if the log in step fails, there will be a param error in the link, like:http://localhost:8080/showMyLoginPage?error. So jstl can be used to check if the log in fails and show different pages.