Add session check to redirect pages

This commit is contained in:
Sofia Baltzi 2018-03-09 16:11:28 +00:00
parent 0200152a7e
commit 79407a4555
15 changed files with 100 additions and 37 deletions

View File

@ -2,6 +2,7 @@ package eu.dnetlib.openaire.usermanagement;
import eu.dnetlib.openaire.user.utils.LDAPActions;
import eu.dnetlib.openaire.user.utils.VerificationActions;
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@ -51,12 +52,15 @@ public class ActivationCodeServlet extends HttpServlet{
ldapActions.moveUser(formUsername);
} catch (Exception e) {
logger.error("LDAP error in moving user", e);
response.sendRedirect("./error.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
//response.sendRedirect("./error.jsp");
}
response.sendRedirect("./registerSuccess.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "registerSuccess.jsp"));
//response.sendRedirect("./registerSuccess.jsp");
} else {
logger.info("Verification code has expired!");
response.sendRedirect("./expiredVerificationCode.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "expiredVerificationCode.jsp"));
//response.sendRedirect("./expiredVerificationCode.jsp");
}
} else {
request.getSession().setAttribute("message", "Username or activation code are not valid.");

View File

@ -2,6 +2,7 @@ package eu.dnetlib.openaire.usermanagement;
import eu.dnetlib.openaire.user.utils.LDAPActions;
import eu.dnetlib.openaire.user.utils.VerificationActions;
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@ -51,12 +52,14 @@ public class AddPasswordServlet extends HttpServlet {
logger.info("password added");
} catch (Exception e) {
logger.error("LDAP error in adding password", e);
response.sendRedirect("./error.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
//response.sendRedirect("./error.jsp");
}
}
session.removeAttribute("username");
response.sendRedirect("./success.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "success.jsp"));
//response.sendRedirect("./success.jsp");
printWriter.close();
}

View File

@ -4,12 +4,12 @@ import com.unboundid.ldap.sdk.LDAPException;
import eu.dnetlib.openaire.user.utils.EmailSender;
import eu.dnetlib.openaire.user.utils.LDAPActions;
import eu.dnetlib.openaire.user.utils.VerificationActions;
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.mail.MessagingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -72,17 +72,7 @@ public class ForgotPasswordServlet extends HttpServlet {
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
}
String scheme = request.getScheme();
String serverName = request.getServerName();
int portNumber = request.getServerPort();
String contextPath = request.getContextPath();
String resultPath;
if (portNumber == 80) {
resultPath = scheme + "://" + serverName + contextPath + "/verify.jsp";
} else {
resultPath = scheme + "://" + serverName + ":" + portNumber + contextPath + "/verify.jsp";
}
String resultPath = UrlConstructor.getRedirectUrl(request, "verify.jsp");
String verificationCodeMsg = "<p>Hello,</p>" +
"<p> A request has been made to reset your OpenAIRE account password. To reset your " +
@ -103,7 +93,8 @@ public class ForgotPasswordServlet extends HttpServlet {
} catch (LDAPException ldape) {
logger.error("LDAP error", ldape);
response.sendRedirect("./error.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
//response.sendRedirect("./error.jsp");
} catch (MessagingException e) {
logger.error("Error in sending email", e);
@ -113,4 +104,5 @@ public class ForgotPasswordServlet extends HttpServlet {
}
}

View File

@ -3,6 +3,7 @@ package eu.dnetlib.openaire.usermanagement;
import eu.dnetlib.openaire.user.utils.EmailSender;
import eu.dnetlib.openaire.user.utils.LDAPActions;
import eu.dnetlib.openaire.user.utils.VerificationActions;
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@ -80,17 +81,7 @@ public class RegisterServlet extends HttpServlet {
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
}
String scheme = request.getScheme();
String serverName = request.getServerName();
int portNumber = request.getServerPort();
String contextPath = request.getContextPath();
String resultPath;
if (portNumber == 80) {
resultPath = scheme + "://" + serverName + contextPath + "/activate.jsp";
} else {
resultPath = scheme + "://" +serverName + ":" +portNumber + contextPath + "/activate.jsp";
}
String resultPath = UrlConstructor.getRedirectUrl(request, "activate.jsp");
String verificationCodeMsg = "<p>Hello " + username + ",</p>" +
"<p> A request has been made to verify your email and activate your OpenAIRE account. To activate your " +
@ -152,7 +143,8 @@ public class RegisterServlet extends HttpServlet {
} catch (Exception e) {
logger.error("LDAP error in creating user", e);
response.sendRedirect("./error.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
//response.sendRedirect("./error.jsp");
}
}
printWriter.close();

View File

@ -3,6 +3,7 @@ package eu.dnetlib.openaire.usermanagement;
import com.unboundid.ldap.sdk.LDAPException;
import eu.dnetlib.openaire.user.utils.EmailSender;
import eu.dnetlib.openaire.user.utils.LDAPActions;
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -67,11 +68,13 @@ public class RemindUsernameServlet extends HttpServlet {
} catch (LDAPException ldape) {
logger.error("Could not find user with email " + formEmail, ldape);
response.sendRedirect("./error.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
//response.sendRedirect("./error.jsp");
} catch (MessagingException e) {
logger.error("Error in sending email", e);
response.sendRedirect("./error.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
//response.sendRedirect("./error.jsp");
}
}

View File

@ -2,6 +2,7 @@ package eu.dnetlib.openaire.usermanagement;
import eu.dnetlib.openaire.user.utils.LDAPActions;
import eu.dnetlib.openaire.user.utils.VerificationActions;
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@ -51,12 +52,14 @@ public class ResetPasswordServlet extends HttpServlet {
logger.info("password resetted");
} catch (Exception e) {
logger.error("LDAP error in resetting password", e);
response.sendRedirect("./error.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "error.jsp"));
//response.sendRedirect("./error.jsp");
}
}
session.removeAttribute("username");
response.sendRedirect("./success.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "success.jsp"));
//response.sendRedirect("./success.jsp");
printWriter.close();
}

View File

@ -1,6 +1,7 @@
package eu.dnetlib.openaire.usermanagement;
import eu.dnetlib.openaire.user.utils.VerificationActions;
import eu.dnetlib.openaire.usermanagement.utils.UrlConstructor;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
@ -46,7 +47,8 @@ public class VerificationCodeServlet extends HttpServlet {
response.sendRedirect("./resetPassword.jsp");
} else {
logger.info("Verification code has expired!");
response.sendRedirect("./expiredVerificationCode.jsp");
response.sendRedirect(UrlConstructor.getRedirectUrl(request, "expiredVerificationCode.jsp"));
//response.sendRedirect("./expiredVerificationCode.jsp");
}
} else {
request.getSession().setAttribute("message", "Username or verification code are not valid.");

View File

@ -0,0 +1,42 @@
package eu.dnetlib.openaire.usermanagement.utils;
import javax.servlet.http.HttpServletRequest;
/**
* Created by sofia on 8/3/2018.
*/
public class UrlConstructor {
public static String getRedirectUrl(HttpServletRequest request, String jspPage) {
String scheme = request.getScheme();
String serverName = request.getServerName();
int portNumber = request.getServerPort();
String contextPath = request.getContextPath();
String resultPath;
if (portNumber == 80) {
resultPath = scheme + "://" + serverName + contextPath + "/" + jspPage;
} else {
resultPath = scheme + "://" + serverName + ":" + portNumber + contextPath + "/" + jspPage;
}
if (jspPage.equals("error.jsp")) {
request.getSession().setAttribute("error", "true");
}
if (jspPage.equals("success.jsp")) {
request.getSession().setAttribute("success", "true");
}
if (jspPage.equals("successAddPassword.jsp")) {
request.getSession().setAttribute("successAddPassword", "true");
}
if (jspPage.equals("expiredVerificationCode.jsp")) {
request.getSession().setAttribute("expiredVerificationCode", "true");
}
if (jspPage.equals("registerSuccess.jsp")) {
request.getSession().setAttribute("registerSuccess", "true");
}
return resultPath;
}
}

View File

@ -9,7 +9,7 @@
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% if (session.getAttribute("username") == null) {
String redirectURL = "/dnet-openaire-users-1.0.0-SNAPSHOT/forgotPassword.jsp";
String redirectURL = request.getContextPath() + "/forgotPassword.jsp";
response.sendRedirect(redirectURL);
}%>
<%--<%String name=(String)request.getAttribute("name");--%>

View File

@ -7,6 +7,11 @@
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% if (session.getAttribute("error") == null) {
String redirectURL = request.getContextPath() + "/error404.jsp";
response.sendRedirect(redirectURL);
}%>
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -7,6 +7,11 @@
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% if (session.getAttribute("expiredVerificationCode") == null) {
String redirectURL = request.getContextPath() + "/error404.jsp";
response.sendRedirect(redirectURL);
}%>
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

View File

@ -8,6 +8,10 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% if (session.getAttribute("registerSuccess") == null) {
String redirectURL = request.getContextPath() + "/error404.jsp";
response.sendRedirect(redirectURL);
}%>
<META HTTP-EQUIV=Refresh CONTENT="0.5; URL=http://beta.services.openaire.eu/uoa-user-management/openid_connect_login">
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
<head>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% if (session.getAttribute("username") == null) {
String redirectURL = "/dnet-openaire-users-1.0.0-SNAPSHOT/forgotPassword.jsp";
String redirectURL = request.getContextPath() + "/forgotPassword.jsp";
response.sendRedirect(redirectURL);
}
%>

View File

@ -8,6 +8,10 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% if (session.getAttribute("success") == null) {
String redirectURL = request.getContextPath() + "/error404.jsp";
response.sendRedirect(redirectURL);
}%>
<META HTTP-EQUIV=Refresh CONTENT="0.5; URL=http://beta.services.openaire.eu/uoa-user-management/openid_connect_login">
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
<head>

View File

@ -9,6 +9,10 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% if (session.getAttribute("successAddPassword") == null) {
String redirectURL = request.getContextPath() + "/error404.jsp";
response.sendRedirect(redirectURL);
}%>
<META HTTP-EQUIV=Refresh CONTENT="0.5; URL=http://beta.services.openaire.eu/uoa-user-management/openid_connect_login">
<html lang="en-gb" dir="ltr" vocab="http://schema.org/">
<head>