From 484676ad2452e375d2150d74bebdb0b606cc20f3 Mon Sep 17 00:00:00 2001 From: Sofia Baltzi <> Date: Mon, 23 Oct 2017 14:00:44 +0000 Subject: [PATCH] Add AddPasswordServlet.java --- .../usermanagement/AddPasswordServlet.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java diff --git a/src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java b/src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java new file mode 100644 index 0000000..59bde3f --- /dev/null +++ b/src/main/java/eu/dnetlib/openaire/usermanagement/AddPasswordServlet.java @@ -0,0 +1,63 @@ +package eu.dnetlib.openaire.usermanagement; + +import eu.dnetlib.openaire.user.utils.LDAPActions; +import eu.dnetlib.openaire.user.utils.VerificationActions; +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.context.support.SpringBeanAutowiringSupport; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Created by sofia on 23/10/2017. + */ +public class AddPasswordServlet extends HttpServlet { + + public void init(ServletConfig config) throws ServletException { + super.init(config); + SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, + config.getServletContext()); + } + + @Autowired + private VerificationActions verificationActions; + + @Autowired + private LDAPActions ldapActions; + + private Logger logger = Logger.getLogger(AddPasswordServlet.class); + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + response.setContentType("text/html"); + PrintWriter printWriter = response.getWriter(); + + HttpSession session = request.getSession(); + String username = (String) session.getAttribute("username"); + + String password = request.getParameter("password"); + String confirmPassword = request.getParameter("password_conf"); + + if (password.equals(confirmPassword) && username != null) { + try { + ldapActions.resetPassword(username, password); + logger.info("password added"); + } catch (Exception e) { + logger.error("LDAP error in adding password", e); + response.sendRedirect("./error.jsp"); + } + } + + session.removeAttribute("username"); + response.sendRedirect("./success.jsp"); + printWriter.close(); + + } +}