From b27ded69712c9e65e1e1c2e2ec08127466356a86 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Thu, 24 Jan 2019 08:19:56 +0000 Subject: [PATCH] "Applied fix from trunk for revision: 1851998" ------------------------------------------------------------------------ r1851998 | jleroux | 2019-01-24 09:17:38 +0100 (jeu. 24 janv. 2019) | 11 lignes Fixed: Impossible secure and autologin cookie names when mountpoint contains a slash inside its name (OFBIZ-10766) Deepak Nigam reported on dev ML: When there is one web app with the empty mount point (i.e. deployed on root), the auto-login cookie will not work for that particular webapp due to the change in the path of the cookie from "/" to "/" + applicationName. Because the system will try to find the cookie at the "/" but it is actually at "/" + applicationName. Thanks Deepak for report ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/branches/release17.12@1852000 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/java/org/apache/ofbiz/base/util/UtilHttp.java | 2 ++ .../java/org/apache/ofbiz/webapp/control/LoginWorker.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java index 9a7807088a..f55a57347a 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java @@ -668,6 +668,8 @@ public final class UtilHttp { if (request.getContextPath().length() > 1) { appName = request.getContextPath().substring(1); } + // When you set a mountpoint which contains a slash inside its name (ie not only a slash as a trailer, which is possible), + // as it's needed with OFBIZ-10765, OFBiz tries to create a cookie with a slash in its name and that's impossible. return appName.replaceAll("/","_"); } diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java index a78eae0d7c..be8ca2c27e 100644 --- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java +++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/LoginWorker.java @@ -720,7 +720,7 @@ public class LoginWorker { Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId")); autoLoginCookie.setMaxAge(60 * 60 * 24 * 365); autoLoginCookie.setDomain(EntityUtilProperties.getPropertyValue("url", "cookie.domain", delegator)); - autoLoginCookie.setPath("/" + applicationName); + autoLoginCookie.setPath( applicationName.equals("root") ? "/" : request.getContextPath()); autoLoginCookie.setSecure(true); autoLoginCookie.setHttpOnly(true); response.addCookie(autoLoginCookie); @@ -796,10 +796,11 @@ public class LoginWorker { // remove the cookie if (userLogin != null) { Delegator delegator = (Delegator) request.getAttribute("delegator"); + String applicationName = UtilHttp.getApplicationName(request); Cookie autoLoginCookie = new Cookie(getAutoLoginCookieName(request), userLogin.getString("userLoginId")); autoLoginCookie.setMaxAge(0); autoLoginCookie.setDomain(EntityUtilProperties.getPropertyValue("url", "cookie.domain", delegator)); - autoLoginCookie.setPath("/" + UtilHttp.getApplicationName(request)); + autoLoginCookie.setPath( applicationName.equals("root") ? "/" : request.getContextPath()); response.addCookie(autoLoginCookie); } // remove the session attributes