changeset 8505:b1580e4d342a

(issue1777) Add options to change login redirect and disable login
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 16 Dec 2014 14:16:10 +0100
parents a3bc62722239
children da9365fc2f42
files gwt-client/src/main/java/org/dive4elements/river/client/server/filter/GGInAFilter.java gwt-client/src/main/webapp/WEB-INF/web.xml
diffstat 2 files changed, 47 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/filter/GGInAFilter.java	Tue Dec 16 12:48:25 2014 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/filter/GGInAFilter.java	Tue Dec 16 14:16:10 2014 +0100
@@ -40,8 +40,10 @@
     private static Logger log = Logger.getLogger(GGInAFilter.class);
 
     private boolean deactivate = false;
+    private boolean loginDisabled = false;
     private String authmethod;
     private String redirecturl;
+    private String noAuthRedir;
     private ServletContext sc;
 
     private static final String LOGIN_JSP     = "/login.jsp";
@@ -64,6 +66,17 @@
         log.debug("GGInAFilter context " + this.sc.getContextPath());
         this.authmethod = sc.getInitParameter("authentication");
         this.redirecturl = sc.getInitParameter("redirect-url");
+
+        noAuthRedir = sc.getInitParameter("unauth-redirect-url");
+        if (noAuthRedir == null) {
+            noAuthRedir = LOGIN_JSP;
+        }
+
+        String disableLogin = sc.getInitParameter("disable-login");
+        if (disableLogin != null && disableLogin.equalsIgnoreCase("true")) {
+            loginDisabled = true;
+        }
+
         if (deactivate != null && deactivate.equalsIgnoreCase("true")) {
             this.deactivate = true;
         }
@@ -115,6 +128,15 @@
                 || requesturi.equals(path + SAML_SERVLET)
                 || requesturi.equals(path + FLYS_CSS)) {
             log.debug("Request for login " + requesturi);
+            if (loginDisabled && requesturi.equals(path + LOGIN_JSP)) {
+                log.debug("Login disabled. Redirecting.");
+                if (noAuthRedir.equals(LOGIN_JSP) || noAuthRedir.equals(path + LOGIN_JSP)) {
+                  handleResponse(resp, false); /* Dont redirect to the same page */
+                } else {
+                  handleResponse(resp, true);
+                }
+                return;
+            }
             chain.doFilter(req, resp);
             return;
         }
@@ -166,9 +188,15 @@
     }
 
     private void redirect(ServletResponse resp) throws IOException {
-        log.debug("Redirect to login");
-        ((HttpServletResponse) resp).sendRedirect(this.sc.getContextPath() +
-            "/login.jsp");
+        if (noAuthRedir.startsWith("http")) {
+            log.debug("Redirect to external page: " + noAuthRedir);
+            ((HttpServletResponse) resp).sendRedirect(noAuthRedir);
+        } else {
+            log.debug("Redirect to: " + noAuthRedir);
+            ((HttpServletResponse) resp).sendRedirect(this.sc.getContextPath() +
+                noAuthRedir);
+
+        }
     }
 
     private void sendNotAuthenticated(ServletResponse resp) throws IOException {
--- a/gwt-client/src/main/webapp/WEB-INF/web.xml	Tue Dec 16 12:48:25 2014 +0100
+++ b/gwt-client/src/main/webapp/WEB-INF/web.xml	Tue Dec 16 14:16:10 2014 +0100
@@ -24,6 +24,22 @@
     </context-param>
 
     <context-param>
+        <!-- URL to be redirected to when a user is not authenticated.
+             If this starts with http it is treated as an absolute url.
+             Otherwise it is interpreted as a relative page. -->
+        <param-name>unauth-redirect-url</param-name>
+        <param-value>/login.jsp</param-value>
+    </context-param>
+
+    <context-param>
+        <!-- Set this to disable the login page. Accessing the login
+             page will trigger a redirect to the unauth-redirect-url if
+             the unauth redirect is not the login page. -->
+        <param-name>disable-login</param-name>
+        <param-value>false</param-value>
+    </context-param>
+
+    <context-param>
         <param-name>authentication</param-name>
         <param-value>plain</param-value>
     </context-param>

http://dive4elements.wald.intevation.org