svn commit: r1785098 - in /ofbiz/branches/release13.07/framework: common/src/org/ofbiz/common/email/NotificationServices.java webapp/src/org/ofbiz/webapp/control/RequestHandler.java webapp/src/org/ofbiz/webapp/ftl/OfbizUrlTransform.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1785098 - in /ofbiz/branches/release13.07/framework: common/src/org/ofbiz/common/email/NotificationServices.java webapp/src/org/ofbiz/webapp/control/RequestHandler.java webapp/src/org/ofbiz/webapp/ftl/OfbizUrlTransform.java

jleroux@apache.org
Author: jleroux
Date: Thu Mar  2 10:17:15 2017
New Revision: 1785098

URL: http://svn.apache.org/viewvc?rev=1785098&view=rev
Log:
Fixed: "Login and logout process in demos shows a certificate issue"
(OFBIZ-9206)

After my conclusions at OFBIZ-9240 I decided to reapply the changes

Here, unlike in trunk and stable, I kept getDefaultServerRootUrl()
and did no changes in url.properties.
URL properties will be, for instance,
used to specify the ports used in demos (28443/28080)


The idea is to use the port initially passed by a successful login request as
it's done since WebSiteProperties class exists. I also don't add twice the
portOffset when it's build  from the request, and only then.
Keep it as is when it's build from a WebSite GenericValue.
We then trust the user and don't rely on the request.

Thanks: Pierre Smits for report

Modified:
    ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/email/NotificationServices.java
    ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
    ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/ftl/OfbizUrlTransform.java

Modified: ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/email/NotificationServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/email/NotificationServices.java?rev=1785098&r1=1785097&r2=1785098&view=diff
==============================================================================
--- ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/email/NotificationServices.java (original)
+++ ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/email/NotificationServices.java Thu Mar  2 10:17:15 2017
@@ -27,8 +27,6 @@ import java.net.UnknownHostException;
 import java.util.Locale;
 import java.util.Map;
 
-import javolution.util.FastMap;
-
 import org.ofbiz.base.container.ClassLoaderContainer;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilGenerics;
@@ -48,6 +46,7 @@ import org.ofbiz.service.ModelService;
 import org.ofbiz.service.ServiceUtil;
 
 import freemarker.template.TemplateException;
+import javolution.util.FastMap;
 
 /**
  * Provides generic services related to preparing and
@@ -267,6 +266,7 @@ public class NotificationServices {
             String httpPort = null;
             String httpServer = null;
             Boolean enableHttps = null;
+            Boolean dontAdd = false;
 
             try {
                 // using just the IP address of localhost if we don't have a defined server
@@ -296,7 +296,10 @@ public class NotificationServices {
 
             // fill in any missing properties with fields from the global file
             if (UtilValidate.isEmpty(httpsPort)) {
-                httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", "443", delegator);
+                httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", delegator);
+                if ("8443" != httpsPort) {
+                    dontAdd = true; // Here we can't initialise the port from a request, so we assume it's set in properties or DB, we don't add the portOffset anyway
+                }
             }
             if (UtilValidate.isEmpty(httpsServer)) {
                 httpsServer = EntityUtilProperties.getPropertyValue("url.properties", "force.https.host", localServer, delegator);
@@ -315,9 +318,13 @@ public class NotificationServices {
                 Integer httpPortValue = Integer.valueOf(httpPort);
                 httpPortValue += ClassLoaderContainer.portOffset;
                 httpPort = httpPortValue.toString();
-                Integer httpsPortValue = Integer.valueOf(httpsPort);
-                httpsPortValue += ClassLoaderContainer.portOffset;
-                httpsPort = httpsPortValue.toString();
+                if (!dontAdd) {
+                    Integer httpsPortValue = Integer.valueOf(httpsPort);
+                    if (!httpsPort.isEmpty()) {
+                        httpsPortValue += ClassLoaderContainer.portOffset;
+                    }
+                    httpsPort = httpsPortValue.toString();
+                }
             }
 
             // prepare the (non-secure) URL

Modified: ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=1785098&r1=1785097&r2=1785098&view=diff
==============================================================================
--- ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original)
+++ ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Thu Mar  2 10:17:15 2017
@@ -34,8 +34,6 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
-import javolution.util.FastMap;
-
 import org.ofbiz.base.container.ClassLoaderContainer;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.SSLUtil;
@@ -61,6 +59,8 @@ import org.ofbiz.webapp.view.ViewHandler
 import org.ofbiz.webapp.website.WebSiteWorker;
 import org.owasp.esapi.errors.EncodingException;
 
+import javolution.util.FastMap;
+
 /**
  * RequestHandler - Request Processor Object
  */
@@ -942,7 +942,12 @@ public class RequestHandler {
 
     public static String getDefaultServerRootUrl(HttpServletRequest request, boolean secure) {
         Delegator delegator = (Delegator) request.getAttribute("delegator");
-        String httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", "443", delegator);
+        Boolean dontAdd = false;
+        String httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", delegator);
+        if (httpsPort.isEmpty() ) {
+            httpsPort = String.valueOf(request.getServerPort());
+            dontAdd = true; // We take the port from the request, don't add the portOffset
+        }
         String httpsServer = EntityUtilProperties.getPropertyValue("url.properties", "force.https.host", delegator);
         String httpPort = EntityUtilProperties.getPropertyValue("url.properties", "port.http", "80", delegator);
         String httpServer = EntityUtilProperties.getPropertyValue("url.properties", "force.http.host", delegator);
@@ -952,9 +957,13 @@ public class RequestHandler {
             Integer httpPortValue = Integer.valueOf(httpPort);
             httpPortValue += ClassLoaderContainer.portOffset;
             httpPort = httpPortValue.toString();
-            Integer httpsPortValue = Integer.valueOf(httpsPort);
-            httpsPortValue += ClassLoaderContainer.portOffset;
-            httpsPort = httpsPortValue.toString();
+            if (!dontAdd) {
+                Integer httpsPortValue = Integer.valueOf(httpsPort);
+                if (!httpsPort.isEmpty()) {
+                    httpsPortValue += ClassLoaderContainer.portOffset;
+                }
+                httpsPort = httpsPortValue.toString();
+            }
         }
         
         StringBuilder newURL = new StringBuilder();
@@ -1064,6 +1073,7 @@ public class RequestHandler {
         String httpPort = null;
         String httpServer = null;
         Boolean enableHttps = null;
+        Boolean dontAdd = false;
 
         // load the properties from the website entity
         GenericValue webSite;
@@ -1084,7 +1094,11 @@ public class RequestHandler {
 
         // fill in any missing properties with fields from the global file
         if (UtilValidate.isEmpty(httpsPort)) {
-            httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", "443", delegator);
+            httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", delegator);
+            if (httpsPort.isEmpty() ) {
+                httpsPort = String.valueOf(request.getServerPort());
+                dontAdd = true; // We take the port from the request, don't add the portOffset
+            }
         }
         if (UtilValidate.isEmpty(httpsServer)) {
             httpsServer = EntityUtilProperties.getPropertyValue("url.properties", "force.https.host", delegator);
@@ -1103,9 +1117,13 @@ public class RequestHandler {
             Integer httpPortValue = Integer.valueOf(httpPort);
             httpPortValue += ClassLoaderContainer.portOffset;
             httpPort = httpPortValue.toString();
-            Integer httpsPortValue = Integer.valueOf(httpsPort);
-            httpsPortValue += ClassLoaderContainer.portOffset;
-            httpsPort = httpsPortValue.toString();
+            if (!dontAdd) {
+                Integer httpsPortValue = Integer.valueOf(httpsPort);
+                if (!httpsPort.isEmpty()) {
+                    httpsPortValue += ClassLoaderContainer.portOffset;
+                }
+                httpsPort = httpsPortValue.toString();
+            }
         }
         
         // create the path the the control servlet

Modified: ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/ftl/OfbizUrlTransform.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/ftl/OfbizUrlTransform.java?rev=1785098&r1=1785097&r2=1785098&view=diff
==============================================================================
--- ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/ftl/OfbizUrlTransform.java (original)
+++ ofbiz/branches/release13.07/framework/webapp/src/org/ofbiz/webapp/ftl/OfbizUrlTransform.java Thu Mar  2 10:17:15 2017
@@ -104,6 +104,7 @@ public class OfbizUrlTransform implement
                     BeanModel res = (BeanModel) env.getVariable("response");
                     Object prefix = env.getVariable("urlPrefix");
                     if (UtilValidate.isNotEmpty(webSiteId)) {
+                        Boolean dontAdd = false;
                         HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
                         Delegator delegator = (Delegator) request.getAttribute("delegator");
                         String httpsPort = null;
@@ -127,7 +128,11 @@ public class OfbizUrlTransform implement
                         }
                         // fill in any missing properties with fields from the global file
                         if (UtilValidate.isEmpty(httpsPort)) {
-                            httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", "443", delegator);
+                            httpsPort = EntityUtilProperties.getPropertyValue("url.properties", "port.https", delegator);
+                            if (httpsPort.isEmpty() ) {
+                                httpsPort = String.valueOf(request.getServerPort());
+                                dontAdd = true; // We take the port from the request, don't add the portOffset
+                            }
                         }
                         if (UtilValidate.isEmpty(httpsServer)) {
                             httpsServer = EntityUtilProperties.getPropertyValue("url.properties", "force.https.host", delegator);
@@ -146,11 +151,14 @@ public class OfbizUrlTransform implement
                             Integer httpPortValue = Integer.valueOf(httpPort);
                             httpPortValue += ClassLoaderContainer.portOffset;
                             httpPort = httpPortValue.toString();
-                            Integer httpsPortValue = Integer.valueOf(httpsPort);
-                            httpsPortValue += ClassLoaderContainer.portOffset;
-                            httpsPort = httpsPortValue.toString();
+                            if (!dontAdd) {
+                                Integer httpsPortValue = Integer.valueOf(httpsPort);
+                                if (!httpsPort.isEmpty()) {
+                                    httpsPortValue += ClassLoaderContainer.portOffset;
+                                }
+                                httpsPort = httpsPortValue.toString();
+                            }
                         }
-
                         if (secure && enableHttps) {
                             String server = httpsServer;
                             if (UtilValidate.isEmpty(server)) {