1 |
49196
|
katerina.i
|
package eu.dnetlib.openaire.usermanagement;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
4 |
|
|
import eu.dnetlib.openaire.user.utils.VerificationActions;
|
5 |
51986
|
sofia.balt
|
import eu.dnetlib.openaire.user.utils.InputValidator;
|
6 |
51139
|
sofia.balt
|
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
|
7 |
49406
|
sofia.balt
|
import org.apache.log4j.Logger;
|
8 |
49196
|
katerina.i
|
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
51200
|
katerina.i
|
import org.springframework.beans.factory.annotation.Value;
|
10 |
49196
|
katerina.i
|
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 |
49408
|
sofia.balt
|
import javax.servlet.http.HttpSession;
|
18 |
49196
|
katerina.i
|
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 |
51200
|
katerina.i
|
@Value("${oidc.home}")
|
39 |
|
|
private String oidcHomeUrl;
|
40 |
|
|
|
41 |
49406
|
sofia.balt
|
private Logger logger = Logger.getLogger(ResetPasswordServlet.class);
|
42 |
|
|
|
43 |
49196
|
katerina.i
|
@Override
|
44 |
|
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
45 |
|
|
response.setContentType("text/html");
|
46 |
|
|
PrintWriter printWriter = response.getWriter();
|
47 |
|
|
|
48 |
49408
|
sofia.balt
|
HttpSession session = request.getSession();
|
49 |
|
|
String username = (String) session.getAttribute("username");
|
50 |
49409
|
sofia.balt
|
|
51 |
49197
|
katerina.i
|
String password = request.getParameter("password");
|
52 |
49406
|
sofia.balt
|
String confirmPassword = request.getParameter("password_conf");
|
53 |
49196
|
katerina.i
|
|
54 |
51932
|
sofia.balt
|
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 |
49406
|
sofia.balt
|
}
|
77 |
51932
|
sofia.balt
|
} 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 |
49552
|
sofia.balt
|
}
|
83 |
|
|
printWriter.close();
|
84 |
51200
|
katerina.i
|
}
|
85 |
49551
|
sofia.balt
|
|
86 |
51200
|
katerina.i
|
public String getOidcHomeUrl() {
|
87 |
|
|
return oidcHomeUrl;
|
88 |
49196
|
katerina.i
|
}
|
89 |
51200
|
katerina.i
|
|
90 |
|
|
public void setOidcHomeUrl(String oidcHomeUrl) {
|
91 |
|
|
this.oidcHomeUrl = oidcHomeUrl;
|
92 |
|
|
}
|
93 |
49196
|
katerina.i
|
}
|