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 670b99ce27..05754d51da 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 dc6229093b..e63c889774 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 @@ -932,7 +932,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); @@ -948,11 +948,13 @@ public class LoginWorker { Delegator delegator = (Delegator) request.getAttribute("delegator"); HttpSession session = request.getSession(); GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); + String applicationName = UtilHttp.getApplicationName(request); + if (userLogin != null) { Cookie securedLoginIdCookie = new Cookie(getSecuredLoginIdCookieName(request), userLogin.getString("userLoginId")); securedLoginIdCookie.setMaxAge(-1); securedLoginIdCookie.setDomain(EntityUtilProperties.getPropertyValue("url", "cookie.domain", delegator)); - securedLoginIdCookie.setPath("/" + UtilHttp.getApplicationName(request)); + securedLoginIdCookie.setPath( applicationName.equals("root") ? "/" : request.getContextPath()); securedLoginIdCookie.setSecure(true); securedLoginIdCookie.setHttpOnly(true); response.addCookie(securedLoginIdCookie); @@ -1052,10 +1054,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