1
|
package eu.dnetlib.openaire.usermanagement;
|
2
|
|
3
|
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
4
|
import eu.dnetlib.openaire.user.utils.VerificationActions;
|
5
|
import eu.dnetlib.openaire.usermanagement.utils.InputValidator;
|
6
|
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
|
7
|
import org.apache.log4j.Logger;
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
10
|
|
11
|
import javax.servlet.ServletConfig;
|
12
|
import javax.servlet.ServletException;
|
13
|
import javax.servlet.http.HttpServlet;
|
14
|
import javax.servlet.http.HttpServletRequest;
|
15
|
import javax.servlet.http.HttpServletResponse;
|
16
|
import javax.servlet.http.HttpSession;
|
17
|
import java.io.IOException;
|
18
|
import java.io.PrintWriter;
|
19
|
|
20
|
/**
|
21
|
* Created by sofia on 23/10/2017.
|
22
|
*/
|
23
|
public class AddPasswordServlet extends HttpServlet {
|
24
|
|
25
|
public void init(ServletConfig config) throws ServletException {
|
26
|
super.init(config);
|
27
|
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
|
28
|
config.getServletContext());
|
29
|
}
|
30
|
|
31
|
@Autowired
|
32
|
private VerificationActions verificationActions;
|
33
|
|
34
|
@Autowired
|
35
|
private LDAPActions ldapActions;
|
36
|
|
37
|
private Logger logger = Logger.getLogger(AddPasswordServlet.class);
|
38
|
|
39
|
@Override
|
40
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
41
|
response.setContentType("text/html");
|
42
|
PrintWriter printWriter = response.getWriter();
|
43
|
|
44
|
HttpSession session = request.getSession();
|
45
|
String username = (String) session.getAttribute("username");
|
46
|
|
47
|
if (username == null){
|
48
|
logger.info("Empty username in session");
|
49
|
}
|
50
|
|
51
|
String password = request.getParameter("password");
|
52
|
String confirmPassword = request.getParameter("password_conf");
|
53
|
|
54
|
if (InputValidator.isFilled(password)) {
|
55
|
if (InputValidator.isValidPassword(password) && password.equals(confirmPassword) && username !=null) {
|
56
|
try {
|
57
|
ldapActions.resetPassword(username, password);
|
58
|
logger.info("password added");
|
59
|
session.removeAttribute("username");
|
60
|
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "success.jsp"));
|
61
|
} catch (Exception e) {
|
62
|
logger.error("LDAP error in adding password", e);
|
63
|
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
|
64
|
}
|
65
|
} else {
|
66
|
if (!InputValidator.isValidPassword(password)) {
|
67
|
logger.info("No valid password");
|
68
|
// request.getSession().setAttribute("msg_invalid_password", "The password must contain a lowercase letter, a capital (uppercase) letter, a number and must be at least 6 characters long. White space character is not allowed.");
|
69
|
}
|
70
|
if (!password.equals(confirmPassword)) {
|
71
|
logger.info("No matching passwords");
|
72
|
// request.getSession().setAttribute("msg_pass_conf_error", "These passwords don't match.");
|
73
|
}
|
74
|
response.sendRedirect("./addPassword.jsp");
|
75
|
}
|
76
|
} else {
|
77
|
logger.info("Empty password");
|
78
|
request.getSession().setAttribute("msg_password_error_display", "display:block" );
|
79
|
// request.getSession().setAttribute("msg_invalid_password", "The password must contain a lowercase letter, a capital (uppercase) letter, a number and must be at least 6 characters long. White space character is not allowed.");
|
80
|
response.sendRedirect("./resetPassword.jsp");
|
81
|
}
|
82
|
|
83
|
printWriter.close();
|
84
|
|
85
|
}
|
86
|
}
|