1
|
package eu.dnetlib.openaire.usermanagement;
|
2
|
|
3
|
import eu.dnetlib.openaire.user.utils.InputValidator;
|
4
|
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
5
|
import eu.dnetlib.openaire.user.utils.VerificationActions;
|
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.beans.factory.annotation.Value;
|
10
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
11
|
|
12
|
import javax.servlet.ServletConfig;
|
13
|
import javax.servlet.ServletException;
|
14
|
import javax.servlet.http.HttpServlet;
|
15
|
import javax.servlet.http.HttpServletRequest;
|
16
|
import javax.servlet.http.HttpServletResponse;
|
17
|
import javax.servlet.http.HttpSession;
|
18
|
import java.io.IOException;
|
19
|
import java.io.PrintWriter;
|
20
|
|
21
|
/**
|
22
|
* Created by kiatrop on 28/9/2017.
|
23
|
*/
|
24
|
public class ResetPasswordServlet extends HttpServlet {
|
25
|
|
26
|
public void init(ServletConfig config) throws ServletException {
|
27
|
super.init(config);
|
28
|
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
|
29
|
config.getServletContext());
|
30
|
}
|
31
|
|
32
|
@Autowired
|
33
|
private VerificationActions verificationActions;
|
34
|
|
35
|
@Autowired
|
36
|
private LDAPActions ldapActions;
|
37
|
|
38
|
@Value("${oidc.home}")
|
39
|
private String oidcHomeUrl;
|
40
|
|
41
|
private Logger logger = Logger.getLogger(ResetPasswordServlet.class);
|
42
|
|
43
|
@Override
|
44
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
45
|
response.setContentType("text/html");
|
46
|
PrintWriter printWriter = response.getWriter();
|
47
|
|
48
|
HttpSession session = request.getSession();
|
49
|
String username = (String) session.getAttribute("username");
|
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 resetted");
|
59
|
session.removeAttribute("username");
|
60
|
session.setAttribute("homeUrl", oidcHomeUrl);
|
61
|
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "success.jsp"));
|
62
|
} catch (Exception e) {
|
63
|
logger.error("LDAP error in resetting password", e);
|
64
|
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
|
65
|
}
|
66
|
} else {
|
67
|
if (!InputValidator.isValidPassword(password)) {
|
68
|
logger.info("No valid password");
|
69
|
// 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.");
|
70
|
}
|
71
|
if (!password.equals(confirmPassword)) {
|
72
|
logger.info("No matching passwords");
|
73
|
// request.getSession().setAttribute("msg_pass_conf_error", "These passwords don't match.");
|
74
|
}
|
75
|
response.sendRedirect("./resetPassword.jsp");
|
76
|
}
|
77
|
} else {
|
78
|
logger.info("Empty password");
|
79
|
request.getSession().setAttribute("msg_password_error_display", "display:block" );
|
80
|
// 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.");
|
81
|
response.sendRedirect("./resetPassword.jsp");
|
82
|
}
|
83
|
printWriter.close();
|
84
|
}
|
85
|
|
86
|
public String getOidcHomeUrl() {
|
87
|
return oidcHomeUrl;
|
88
|
}
|
89
|
|
90
|
public void setOidcHomeUrl(String oidcHomeUrl) {
|
91
|
this.oidcHomeUrl = oidcHomeUrl;
|
92
|
}
|
93
|
}
|