[PATCH 3 of 3] (issue1777) Add options to change login redirect and disable login
Wald Commits
scm-commit at wald.intevation.org
Tue Dec 16 14:16:30 CET 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1418735770 -3600
# Node ID b1580e4d342a4acb07b4f25bf7e354acfc9e4c96
# Parent a3bc62722239fa7c9ef35c58d3d828b7e93286d1
(issue1777) Add options to change login redirect and disable login
diff -r a3bc62722239 -r b1580e4d342a gwt-client/src/main/java/org/dive4elements/river/client/server/filter/GGInAFilter.java
--- 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 {
diff -r a3bc62722239 -r b1580e4d342a gwt-client/src/main/webapp/WEB-INF/web.xml
--- 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>
More information about the Dive4Elements-commits
mailing list