"
- + " "
+ + " | "
+ " "
+ " "
+ " "
+ " "
+ " "
- + " "
+ + " | "
+ " "
+ " "
- + " Hey %s, | "
+ + " Dear " + username + ", | "
+ " "
+ " "
+ " You recently requested to reset your password for your Teamengine account. Use below verfication code to reset your password. | "
+ " "
+ " "
- + " Verification Code : %s | "
+ + " Verification Code : " + vCode + " | "
+ " "
+ " "
+ " If you did not request a password reset, please ignore this email or contact to CITE team. | "
@@ -112,12 +136,12 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
+ " "
+ " "
+ ""
- + ""
- + username, EmailUtility.getRandomNumberString());
+ + "";
if (emailList.getLength() > 0) {
+ updateUserDetails(doc, userDetails, vCode);
EmailUtility.sendEmail(host, port, user, pass, emailList.item(0).getTextContent(), subject, message);
- response.sendRedirect("resetPassword.jsp?success=true");
+ response.sendRedirect("resetPassword.jsp?emailStatus=true");
} else {
String url = "resetPassword.jsp?error=emailNotExists&username="
+ username;
@@ -128,4 +152,36 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
throw new ServletException(e);
}
}
+ /**
+ * Store verification code into the user.xml file to validate the code.
+ * @param doc
+ * @param userDetails
+ * @param verifyCode
+ */
+ public void updateUserDetails(Document doc, Element userDetails,
+ String verifyCode) {
+
+ NodeList vCodeList = userDetails.getElementsByTagName("verificationCode");
+ if (vCodeList.getLength() != 0) {
+ Element element = (Element) doc.getElementsByTagName("verificationCode")
+ .item(0);
+ Node parent = element.getParentNode();
+ parent.removeChild(element);
+ }
+ Element verificationCode = doc.createElement("verificationCode");
+ verificationCode.setTextContent(verifyCode);
+ userDetails.appendChild(verificationCode);
+ try {
+ DOMSource source = new DOMSource(doc);
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ StreamResult result = new StreamResult(new File(userDir, "user.xml"));
+ transformer.transform(source, result);
+ } catch (Exception e) {
+ throw new RuntimeException(
+ "Failed to update userdetails with the verification code "
+ + e.getMessage());
+ }
+ }
}
From 7170c398a70a56a013f97c0c995005ac62f0d477 Mon Sep 17 00:00:00 2001
From: Keshav Nangare
Date: Thu, 15 Nov 2018 21:14:21 +0530
Subject: [PATCH 04/12] Added upate password page and validated the
verification code.
---
.../occamlab/te/web/ResetPasswordHandler.java | 104 +++++++++++++-----
.../java/com/occamlab/te/web/XMLUtils.java | 50 +++++++++
.../src/main/webapp/WEB-INF/web.xml | 12 +-
teamengine-web/src/main/webapp/login.jsp | 7 ++
.../src/main/webapp/updatePassword.jsp | 104 ++++++++++++++++++
5 files changed, 249 insertions(+), 28 deletions(-)
create mode 100644 teamengine-web/src/main/webapp/updatePassword.jsp
diff --git a/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java b/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java
index 94e081812..1836e7392 100644
--- a/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java
+++ b/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java
@@ -17,19 +17,13 @@ Northrop Grumman Corporation are Copyright (C) 2005-2006, Northrop
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import com.occamlab.te.realm.PasswordStorage;
+
import java.io.File;
/**
@@ -59,6 +53,20 @@ public void init() throws ServletException {
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
+ String servletPath = request.getServletPath();
+ if("/resetPasswordHandler".equalsIgnoreCase(servletPath)) {
+ resetPassowrdHandler(request, response);
+ } else if("/updatePasswordHandler".equalsIgnoreCase(servletPath)) {
+ updatePassword(request, response);
+ }
+ }
+
+ /**
+ * This method will send email to registered user along with the
+ * verification code and verification code will stored into
+ * user.xml file.
+ */
+ public void resetPassowrdHandler(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
String username = request.getParameter("username");
userDir = new File(conf.getUsersDir(), username);
@@ -67,11 +75,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
response.sendRedirect(url);
} else {
File xmlfile = new File(userDir, "user.xml");
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- dbf.setExpandEntityReferences(false);
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(xmlfile);
+ Document doc = XMLUtils.parseDocument(xmlfile);
Element userDetails = (Element) (doc.getElementsByTagName("user")
.item(0));
NodeList emailList = userDetails.getElementsByTagName("email");
@@ -141,7 +145,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
if (emailList.getLength() > 0) {
updateUserDetails(doc, userDetails, vCode);
EmailUtility.sendEmail(host, port, user, pass, emailList.item(0).getTextContent(), subject, message);
- response.sendRedirect("resetPassword.jsp?emailStatus=true");
+ response.sendRedirect("updatePassword.jsp?emailStatus=true");
} else {
String url = "resetPassword.jsp?error=emailNotExists&username="
+ username;
@@ -152,6 +156,65 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
throw new ServletException(e);
}
}
+
+ /**
+ * This method will validate the verification code and update the new password if
+ * the code is valid.
+ * Otherwise it will throw error.
+ * @throws ServletException
+ */
+ public void updatePassword(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException {
+ try {
+ String vCode = request.getParameter("vCode");
+ String username = request.getParameter("username");
+ String password = request.getParameter("password");
+ String hashedPassword = PasswordStorage.createHash(password);
+
+ userDir = new File(conf.getUsersDir(), username);
+ if (!userDir.exists()) {
+ String url = "updatePassword.jsp?error=userNotExists&username="
+ + username;
+ response.sendRedirect(url);
+ } else {
+ File xmlfile = new File(userDir, "user.xml");
+ Document doc = XMLUtils.parseDocument(xmlfile);
+ Element userDetails = (Element) (doc.getElementsByTagName("user")
+ .item(0));
+
+ NodeList vCodeList = userDetails
+ .getElementsByTagName("verificationCode");
+ String storedVerificationCode = null;
+ if (vCodeList.getLength() > 0) {
+ Element vCodeElement = (Element) doc.getElementsByTagName(
+ "verificationCode").item(0);
+ storedVerificationCode = vCodeElement.getTextContent();
+ }
+
+ if (storedVerificationCode.equalsIgnoreCase(vCode)) {
+ NodeList pwdList = userDetails.getElementsByTagName("password");
+ if (pwdList.getLength() != 0) {
+ Element pwdElement = (Element) doc.getElementsByTagName("password")
+ .item(0);
+ Node parent = pwdElement.getParentNode();
+ parent.removeChild(pwdElement);
+ }
+ Element pwdElement = doc.createElement("password");
+ pwdElement.setTextContent(hashedPassword);
+ userDetails.appendChild(pwdElement);
+ XMLUtils.transformDocument(doc, new File(userDir, "user.xml"));
+ String url = "login.jsp?success=pwd";
+ response.sendRedirect(url);
+ } else {
+ String url = "updatePassword.jsp?error=invalidVcode&username=" + username + "&vCode=" + vCode;
+ response.sendRedirect(url);
+ }
+ }
+ } catch (Exception e) {
+ throw new ServletException(e);
+ }
+ }
+
/**
* Store verification code into the user.xml file to validate the code.
* @param doc
@@ -171,17 +234,6 @@ public void updateUserDetails(Document doc, Element userDetails,
Element verificationCode = doc.createElement("verificationCode");
verificationCode.setTextContent(verifyCode);
userDetails.appendChild(verificationCode);
- try {
- DOMSource source = new DOMSource(doc);
- TransformerFactory transformerFactory = TransformerFactory.newInstance();
- Transformer transformer = transformerFactory.newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- StreamResult result = new StreamResult(new File(userDir, "user.xml"));
- transformer.transform(source, result);
- } catch (Exception e) {
- throw new RuntimeException(
- "Failed to update userdetails with the verification code "
- + e.getMessage());
- }
+ XMLUtils.transformDocument(doc, new File(userDir, "user.xml"));
}
}
diff --git a/teamengine-web/src/main/java/com/occamlab/te/web/XMLUtils.java b/teamengine-web/src/main/java/com/occamlab/te/web/XMLUtils.java
index 4a2e9688d..f504cdade 100644
--- a/teamengine-web/src/main/java/com/occamlab/te/web/XMLUtils.java
+++ b/teamengine-web/src/main/java/com/occamlab/te/web/XMLUtils.java
@@ -3,6 +3,15 @@
*/
package com.occamlab.te.web;
+import java.io.File;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
@@ -66,5 +75,46 @@ public static NodeList getAllNodes(Document doc, String xPathExpression) {
return null;
}
+
+ /**
+ * This method is used to parse xml document and will return
+ * document object.
+ *
+ * @param xmlFile
+ * Input should XML file with File object.
+ * @return doc
+ * Return document object.
+ */
+ public static Document parseDocument(File xmlFile) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ dbf.setExpandEntityReferences(false);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(xmlFile);
+ return doc;
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to parse xml file: " + xmlFile
+ + " Error: " + e.getMessage());
+ }
+ }
+
+ /**
+ * The XML file is uploaded
+ * @param xmlFile
+ * @return
+ */
+ public static void transformDocument(Document doc, File xmlFile) {
+ try {
+ DOMSource source = new DOMSource(doc);
+ TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ Transformer transformer = transformerFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ StreamResult result = new StreamResult(xmlFile);
+ transformer.transform(source, result);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to update xml file. " + e.getMessage());
+ }
+ }
}
diff --git a/teamengine-web/src/main/webapp/WEB-INF/web.xml b/teamengine-web/src/main/webapp/WEB-INF/web.xml
index 979691d1c..ed73365f4 100644
--- a/teamengine-web/src/main/webapp/WEB-INF/web.xml
+++ b/teamengine-web/src/main/webapp/WEB-INF/web.xml
@@ -23,12 +23,12 @@
user
- keshav.nangare@gmail.com
+ demo@demo.com
pass
- keshavn@123
+ demo123
test
@@ -64,6 +64,10 @@
resetPasswordHandler
com.occamlab.te.web.ResetPasswordHandler
+
+ updatePasswordHandler
+ com.occamlab.te.web.ResetPasswordHandler
+
emailLog
com.occamlab.te.web.EmailLogServlet
@@ -127,6 +131,10 @@
resetPasswordHandler
/resetPasswordHandler
+
+ updatePasswordHandler
+ /updatePasswordHandler
+
logout
/logout
diff --git a/teamengine-web/src/main/webapp/login.jsp b/teamengine-web/src/main/webapp/login.jsp
index 755bea939..ac9352647 100644
--- a/teamengine-web/src/main/webapp/login.jsp
+++ b/teamengine-web/src/main/webapp/login.jsp
@@ -25,6 +25,13 @@ if (request.getParameter("error") != null) {
out.println("The username and/or password did not match. Please try again.");
}
%>
+
+ <%
+ if ("pwd".equals(request.getParameter("success"))) {
+ out.println("Thank you! Your password is succesfully changed.");
+ }
+ %>
+
+ <%@ include file="footer.jsp"%>
+
+
From c0f97c8739719d43802223d558fcc22906d1a781 Mon Sep 17 00:00:00 2001
From: Keshav Nangare
Date: Mon, 19 Nov 2018 22:23:38 +0530
Subject: [PATCH 05/12] Updated some lables and page layouts.
---
.../occamlab/te/web/ResetPasswordHandler.java | 54 +++++++++----------
.../java/com/occamlab/te/web/XMLUtils.java | 24 ++++++++-
teamengine-web/src/main/webapp/login.jsp | 22 +++++---
.../src/main/webapp/resetPassword.jsp | 31 ++++++-----
.../src/main/webapp/updatePassword.jsp | 8 +--
5 files changed, 85 insertions(+), 54 deletions(-)
diff --git a/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java b/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java
index 1836e7392..3ba010efc 100644
--- a/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java
+++ b/teamengine-web/src/main/java/com/occamlab/te/web/ResetPasswordHandler.java
@@ -1,15 +1,3 @@
-/****************************************************************************
-
- The Original Code is TEAM Engine.
-
- The Initial Developer of the Original Code is Northrop Grumman Corporation
- jointly with The National Technology Alliance. Portions created by
- Northrop Grumman Corporation are Copyright (C) 2005-2006, Northrop
- Grumman Corporation. All Rights Reserved.
-
- Contributor(s): No additional contributors to date
-
- ****************************************************************************/
package com.occamlab.te.web;
import javax.servlet.ServletContext;
@@ -32,14 +20,12 @@ Northrop Grumman Corporation are Copyright (C) 2005-2006, Northrop
*/
public class ResetPasswordHandler extends HttpServlet {
- private static final long serialVersionUID = 7428127065308163495L;
-
Config conf;
private String host;
private String port;
private String user;
private String pass;
- private String subject = "Reset your Teamengine password";
+ private String subject = "Reset your TEAM Engine password";
private String message;
File userDir;
@@ -118,16 +104,19 @@ public void resetPassowrdHandler(HttpServletRequest request, HttpServletResponse
+ " Dear " + username + ", | "
+ " | "
+ " "
- + " You recently requested to reset your password for your Teamengine account. Use below verfication code to reset your password. | "
+ + " You recently requested to reset your password for your TEAM Engine account. Use below verfication code to reset your password. | "
+ " "
+ " "
+ " Verification Code : " + vCode + " | "
+ " "
+ " "
- + " If you did not request a password reset, please ignore this email or contact to CITE team. | "
+ + " If you did not request a password reset, please ignore this email or contact the CITE team. | "
+ + " "
+ + " "
+ + " Follow this link to reset your password. | "
+ " "
+ " "
- + " Regards, CITE TEAM | "
+ + " Regards, CITE team | "
+ " "
+ " "
+ " | "
@@ -143,7 +132,7 @@ public void resetPassowrdHandler(HttpServletRequest request, HttpServletResponse
+ " |