Revision 49628
Added by Sofia Baltzi over 6 years ago
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java | ||
---|---|---|
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 org.apache.log4j.Logger; |
|
6 |
import org.springframework.beans.factory.annotation.Autowired; |
|
7 |
import org.springframework.web.context.support.SpringBeanAutowiringSupport; |
|
8 |
|
|
9 |
import javax.servlet.ServletConfig; |
|
10 |
import javax.servlet.ServletException; |
|
11 |
import javax.servlet.http.HttpServlet; |
|
12 |
import javax.servlet.http.HttpServletRequest; |
|
13 |
import javax.servlet.http.HttpServletResponse; |
|
14 |
import javax.servlet.http.HttpSession; |
|
15 |
import java.io.IOException; |
|
16 |
import java.io.PrintWriter; |
|
17 |
|
|
18 |
/** |
|
19 |
* Created by sofia on 23/10/2017. |
|
20 |
*/ |
|
21 |
public class AddPasswordServlet extends HttpServlet { |
|
22 |
|
|
23 |
public void init(ServletConfig config) throws ServletException { |
|
24 |
super.init(config); |
|
25 |
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, |
|
26 |
config.getServletContext()); |
|
27 |
} |
|
28 |
|
|
29 |
@Autowired |
|
30 |
private VerificationActions verificationActions; |
|
31 |
|
|
32 |
@Autowired |
|
33 |
private LDAPActions ldapActions; |
|
34 |
|
|
35 |
private Logger logger = Logger.getLogger(AddPasswordServlet.class); |
|
36 |
|
|
37 |
@Override |
|
38 |
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { |
|
39 |
response.setContentType("text/html"); |
|
40 |
PrintWriter printWriter = response.getWriter(); |
|
41 |
|
|
42 |
HttpSession session = request.getSession(); |
|
43 |
String username = (String) session.getAttribute("username"); |
|
44 |
|
|
45 |
String password = request.getParameter("password"); |
|
46 |
String confirmPassword = request.getParameter("password_conf"); |
|
47 |
|
|
48 |
if (password.equals(confirmPassword) && username != null) { |
|
49 |
try { |
|
50 |
ldapActions.resetPassword(username, password); |
|
51 |
logger.info("password added"); |
|
52 |
} catch (Exception e) { |
|
53 |
logger.error("LDAP error in adding password", e); |
|
54 |
response.sendRedirect("./error.jsp"); |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
session.removeAttribute("username"); |
|
59 |
response.sendRedirect("./success.jsp"); |
|
60 |
printWriter.close(); |
|
61 |
|
|
62 |
} |
|
63 |
} |
Also available in: Unified diff
Add AddPasswordServlet.java