| 1 | package com.popx.presentazione; | |
| 2 | ||
| 3 | import com.popx.servizio.AuthenticationService; | |
| 4 | import com.popx.modello.UserBean; | |
| 5 | ||
| 6 | import javax.servlet.ServletException; | |
| 7 | import javax.servlet.annotation.WebServlet; | |
| 8 | import javax.servlet.http.HttpServlet; | |
| 9 | import javax.servlet.http.HttpServletRequest; | |
| 10 | import javax.servlet.http.HttpServletResponse; | |
| 11 | import javax.servlet.http.HttpSession; | |
| 12 | import java.io.IOException; | |
| 13 | ||
| 14 | @WebServlet("/login") | |
| 15 | public class LoginServlet extends HttpServlet { | |
| 16 | ||
| 17 | private final AuthenticationService authService; | |
| 18 | ||
| 19 | // Costruttore usato in produzione | |
| 20 | public LoginServlet() { | |
| 21 | this.authService = new AuthenticationService(); | |
| 22 | } | |
| 23 | ||
| 24 | // Costruttore usato nei test (dependency injection) | |
| 25 | public LoginServlet(AuthenticationService authService) { | |
| 26 | this.authService = authService; | |
| 27 | } | |
| 28 | ||
| 29 | @Override | |
| 30 | public void doPost(HttpServletRequest request, HttpServletResponse response) | |
| 31 | throws ServletException, IOException { | |
| 32 | ||
| 33 | String email = request.getParameter("email"); | |
| 34 | String password = request.getParameter("password"); | |
| 35 | ||
| 36 | try { | |
| 37 | UserBean user = authService.login(email, password); | |
| 38 | ||
| 39 | HttpSession session = request.getSession(true); | |
| 40 |
1
1. doPost : removed call to javax/servlet/http/HttpSession::setAttribute → KILLED |
session.setAttribute("role", user.getRole()); |
| 41 |
1
1. doPost : removed call to javax/servlet/http/HttpSession::setAttribute → KILLED |
session.setAttribute("userEmail", user.getEmail()); |
| 42 | ||
| 43 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED |
response.setStatus(HttpServletResponse.SC_OK); |
| 44 | ||
| 45 | } catch (Exception e) { | |
| 46 |
1
1. doPost : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED |
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); |
| 47 |
1
1. doPost : removed call to java/io/PrintWriter::write → KILLED |
response.getWriter().write("Sbagliato email o password."); |
| 48 | } | |
| 49 | } | |
| 50 | } | |
Mutations | ||
| 40 |
1.1 |
|
| 41 |
1.1 |
|
| 43 |
1.1 |
|
| 46 |
1.1 |
|
| 47 |
1.1 |