From 9046a9c735248f14ff70759e4b3fd5533d74dfda Mon Sep 17 00:00:00 2001 From: jeb228 Date: Wed, 8 Dec 2010 22:35:04 +0000 Subject: [PATCH] NIHVIVO-1379 If not sufficiently authorized to view a restricted page, redirect to home page with a message. --- webapp/config/web.xml | 4 ---- .../vitro/webapp/controller/Controllers.java | 1 - .../webapp/controller/VitroHttpServlet.java | 20 ++++++++++++++----- .../freemarker/EmptyController.java | 1 - .../body/insufficientAuthorization.ftl | 11 ---------- 5 files changed, 15 insertions(+), 22 deletions(-) delete mode 100644 webapp/web/templates/freemarker/body/insufficientAuthorization.ftl diff --git a/webapp/config/web.xml b/webapp/config/web.xml index 3bd4a1aaa..c3b41bf68 100644 --- a/webapp/config/web.xml +++ b/webapp/config/web.xml @@ -400,10 +400,6 @@ EmptyController /login - - EmptyController - /insufficientAuthorization - RevisionInfoController diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java index 7a2122bfe..a357c1d37 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java @@ -44,7 +44,6 @@ public class Controllers { public static final String LOGIN_JSP = "/login"; public static final String LOGOUT_JSP = "/logout"; - public static final String INSUFFICIENT_AUTHORIZATION = "/insufficientAuthorization"; public static final String BASIC_JSP = "/templates/page/basicPage.jsp"; public static final String DEBUG_JSP = "/templates/page/debug.jsp"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java index 6152fc863..259427dc4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/VitroHttpServlet.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vedit.beans.LoginStatusBean; +import edu.cornell.mannlib.vitro.webapp.beans.DisplayMessage; import edu.cornell.mannlib.vitro.webapp.controller.authenticate.LogoutRedirector; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean; import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean.State; @@ -43,6 +44,15 @@ public class VitroHttpServlet extends HttpServlet { public final static String TTL_MIMETYPE = "text/turtle"; // unofficial and // unregistered + /** + * Show this to the user if they are logged in, but still not authorized to + * view the page. + */ + private static final String INSUFFICIENT_AUTHORIZATION_MESSAGE = "We're sorry, " + + "but you are not authorized to view the page you requested. " + + "If you think this is an error, " + + "please contact us and we'll be happy to help."; + /** * Setup the auth flag, portal flag and portal bean objects. Put them in the * request attributes. @@ -108,15 +118,15 @@ public class VitroHttpServlet extends HttpServlet { /** * Logged in, but with insufficent authorization. Send them to the - * corresponding page. They won't be coming back. + * home page with a message. They won't be coming back. */ - public static void redirectToInsufficientAuthorizationPage( + private static void redirectToInsufficientAuthorizationPage( HttpServletRequest request, HttpServletResponse response) { try { - response.sendRedirect(request.getContextPath() - + Controllers.INSUFFICIENT_AUTHORIZATION); + DisplayMessage.setMessage(request, INSUFFICIENT_AUTHORIZATION_MESSAGE); + response.sendRedirect(request.getContextPath()); } catch (IOException e) { - log.error("Could not redirect to insufficient authorization page."); + log.error("Could not redirect to show insufficient authorization."); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/EmptyController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/EmptyController.java index e9d01cc32..368461660 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/EmptyController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/EmptyController.java @@ -24,7 +24,6 @@ public class EmptyController extends FreemarkerHttpServlet { private static final Map urlsToTemplates = new HashMap(){ { put("/login", "login.ftl"); - put("/insufficientAuthorization", "insufficientAuthorization.ftl"); } }; diff --git a/webapp/web/templates/freemarker/body/insufficientAuthorization.ftl b/webapp/web/templates/freemarker/body/insufficientAuthorization.ftl deleted file mode 100644 index 4caaf5169..000000000 --- a/webapp/web/templates/freemarker/body/insufficientAuthorization.ftl +++ /dev/null @@ -1,11 +0,0 @@ -<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> - -<#-- Template for the insufficient authorization page --> - -
-

Houston...we have a problem

- -

We're sorry, but you are not authorized to view the page you requested. If you think this is an error, please contact us and we'll be happy to help.

- -

Return to the home page.

-