Spring Boot Web MVC Security custom Login
Al anterior post se le agrega una forma de login customizado.
https://jalbertomr.blogspot.com/2019/08/spring-boot-web-mvc.html
Se crea un controlador para el login y un jsp
https://github.com/jalbertomr/bootWebMVCSecLogin/commit/33038795bfd207bf3d1b6bc7f91dd2bc4f3a0de9
loginController.java
@Controller
public class LoginController {
private static final Logger logger = LoggerFactory.getLogger(ListEmployeeController.class);
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(Model model, String error, String logout) {
if (error != null) {
model.addAttribute("errorMsg", "El Usuario y/o Clave son incorrectos.");
}
if (logout != null) {
model.addAttribute("msg", "Se ha Desautenticado Satisfactoriamente.");
}
return "login";
}
}
login.jsp
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Autenticacion con credenciales</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<form method="POST" action="${contextPath}/login" class="form-signin">
<h2 class="form-heading">Autenticación</h2>
<div class="form-group ${error != null ? 'hayError' : ''}">
<span>${msg}</span>
<input name="username" type="text" class="form-control" placeholder="Usuario"
autofocus="true"/>
<input name="password" type="password" class="form-control" placeholder="Clave"/>
<span>${errorMsg}</span>
<button class="btn btn-lg btn-primary btn-block" type="submit">Autenticarse</button>
</div>
</form>
</div>
<!-- /container -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script></body>
</html>
Se ejecuta
eot
No hay comentarios:
Publicar un comentario