]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add option to disable sending v-loc parameter in init request (#14460).
authorJonas Granvik <jonas@granvik.me>
Mon, 12 Jan 2015 10:44:34 +0000 (12:44 +0200)
committerArtur Signell <artur@vaadin.com>
Mon, 12 Jan 2015 18:44:36 +0000 (18:44 +0000)
Change-Id: Ie17e0621400c3397dc19b386974e231b6f82944c

WebContent/VAADIN/vaadinBootstrap.js
server/src/com/vaadin/server/BootstrapHandler.java
server/src/com/vaadin/server/Constants.java
server/src/com/vaadin/server/DefaultDeploymentConfiguration.java
server/src/com/vaadin/server/DeploymentConfiguration.java
server/src/com/vaadin/server/Page.java
server/tests/src/com/vaadin/server/AbstractDeploymentConfigurationTest.java
server/tests/src/com/vaadin/tests/util/MockDeploymentConfiguration.java
uitest/src/com/vaadin/tests/applicationservlet/DisableSendUrlAsParameters.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/applicationservlet/DisableSendUrlAsParametersTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/AbstractTestUI.java

index 53b213e11065f8810f990210a3e53a9a0b34a395..89514dbcc2363c7f406339bd18384dc70e11e326 100644 (file)
                                        params += extraParams;
                                }
                                
-                               params += '&' + vaadin.getBrowserDetailsParameters(appId); 
+                               params += '&' + vaadin.getBrowserDetailsParameters(appId, getConfig('sendUrlsAsParameters')); 
                                
                                var r;
                                try {
                                ws.pendingApps = null;
                        }
                },
-               getBrowserDetailsParameters: function(parentElementId) {
+               getBrowserDetailsParameters: function(parentElementId, sendUrlsAsParameters) {
                        // Screen height and width
                        var params = 'v-sh=' + window.screen.height;
                        params += '&v-sw=' + window.screen.width;
                        }
                        
                        // Location
-                       params += '&v-loc=' + encodeURIComponent(location.href);
+                       if (sendUrlsAsParameters !== false) {
+                               params += '&v-loc=' + encodeURIComponent(location.href);
+                       }
 
                        // Window name
                        if (window.name) {
index e74f6d7c45f03a9f0bd34c475667e6c883cf6693..a9343a7e03162ae9bcaa27fac16244b7ced46041 100644 (file)
@@ -681,6 +681,12 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
             appConfig.put(ApplicationConstants.SERVICE_URL, serviceUrl);
         }
 
+        boolean sendUrlsAsParameters = vaadinService
+                .getDeploymentConfiguration().isSendUrlsAsParameters();
+        if (!sendUrlsAsParameters) {
+            appConfig.put("sendUrlsAsParameters", false);
+        }
+
         return appConfig;
     }
 
index 02a992a88233f9e462531cc6d33dfd85230f3b61..8036490333a300949dfac3279bad5d483c0b84b4 100644 (file)
@@ -136,6 +136,7 @@ public interface Constants {
     static final String SERVLET_PARAMETER_UI_PROVIDER = "UIProvider";
     static final String SERVLET_PARAMETER_LEGACY_PROPERTY_TOSTRING = "legacyPropertyToString";
     static final String SERVLET_PARAMETER_SYNC_ID_CHECK = "syncIdCheck";
+    static final String SERVLET_PARAMETER_SENDURLSASPARAMETERS = "sendUrlsAsParameters";
 
     // Configurable parameter names
     static final String PARAMETER_VAADIN_RESOURCES = "Resources";
index 22d5210eaa223f642b63f32127a1902372badf65..b26e0484314570013f806c90169aeccc5cc25f06 100644 (file)
@@ -59,6 +59,8 @@ public class DefaultDeploymentConfiguration extends
      */
     public static final boolean DEFAULT_SYNC_ID_CHECK = true;
 
+    public static final boolean DEFAULT_SEND_URLS_AS_PARAMETERS = true;
+
     private final Properties initParameters;
     private boolean productionMode;
     private boolean xsrfProtectionEnabled;
@@ -69,6 +71,7 @@ public class DefaultDeploymentConfiguration extends
     private final Class<?> systemPropertyBaseClass;
     private LegacyProperyToStringMode legacyPropertyToStringMode;
     private boolean syncIdCheck;
+    private boolean sendUrlsAsParameters;
 
     /**
      * Create a new deployment configuration instance.
@@ -93,6 +96,7 @@ public class DefaultDeploymentConfiguration extends
         checkPushMode();
         checkLegacyPropertyToString();
         checkSyncIdCheck();
+        checkSendUrlsAsParameters();
     }
 
     private void checkLegacyPropertyToString() {
@@ -255,6 +259,16 @@ public class DefaultDeploymentConfiguration extends
         return syncIdCheck;
     }
 
+    /**
+     * {@inheritDoc}
+     * <p>
+     * The default value is <code>true</code>.
+     */
+    @Override
+    public boolean isSendUrlsAsParameters() {
+        return sendUrlsAsParameters;
+    }
+
     /**
      * {@inheritDoc}
      * <p>
@@ -347,6 +361,13 @@ public class DefaultDeploymentConfiguration extends
                 Boolean.toString(DEFAULT_SYNC_ID_CHECK)).equals("true");
     }
 
+    private void checkSendUrlsAsParameters() {
+        sendUrlsAsParameters = getApplicationOrSystemProperty(
+                Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS,
+                Boolean.toString(DEFAULT_SEND_URLS_AS_PARAMETERS)).equals(
+                "true");
+    }
+
     private Logger getLogger() {
         return Logger.getLogger(getClass().getName());
     }
index 3c20518c39bc3725448df245b8c62db0921aff9a..968ec7c0c3471436fa28b0e646ea03d548cdbd67 100644 (file)
@@ -110,6 +110,15 @@ public interface DeploymentConfiguration extends Serializable {
      */
     public int getHeartbeatInterval();
 
+    /**
+     * Returns whether the sending of URL's as GET and POST parameters in
+     * requests with content-type <code>application/x-www-form-urlencoded</code>
+     * is enabled or not.
+     * 
+     * @return <code>false</code> if set to false or <code>true</code> otherwise
+     */
+    public boolean isSendUrlsAsParameters();
+
     /**
      * Returns whether a session should be closed when all its open UIs have
      * been idle for longer than its configured maximum inactivity time.
index 3ddf4862b27449dbf66b93dfcd6d64095f9c705e..74d79ade50ccdf7104a2f90c1b98f9b4530b864a 100644 (file)
@@ -939,6 +939,12 @@ public class Page implements Serializable {
      * @return The browser location URI.
      */
     public URI getLocation() {
+        if (location == null
+                && !uI.getSession().getConfiguration().isSendUrlsAsParameters()) {
+            throw new IllegalStateException("Location is not available as the "
+                    + Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS
+                    + " parameter is configured as false");
+        }
         return location;
     }
 
index 7370bd3facefff2455787967d34d30001994fb4f..0518bea6501267a7a1c87681edb19f45d1e53c9f 100644 (file)
@@ -153,5 +153,10 @@ public class AbstractDeploymentConfigurationTest {
             return null;
         }
 
+        @Override
+        public boolean isSendUrlsAsParameters() {
+            return DefaultDeploymentConfiguration.DEFAULT_SEND_URLS_AS_PARAMETERS;
+        }
+
     }
 }
index 8eceaea53f9b33955d5bc44364c3e99825cb569d..ddee23a9ecf4eea3666342a4bd8036ce9d7a4baa 100644 (file)
@@ -21,6 +21,7 @@ public class MockDeploymentConfiguration extends
     private Map<String, String> applicationOrSystemProperty = new HashMap<String, String>();
     private LegacyProperyToStringMode legacyPropertyToStringMode = LegacyProperyToStringMode.DISABLED;
     private boolean syncIdCheckEnabled = true;
+    private boolean sendUrlsAsParameters = true;
 
     @Override
     public boolean isProductionMode() {
@@ -119,4 +120,9 @@ public class MockDeploymentConfiguration extends
         this.legacyPropertyToStringMode = legacyPropertyToStringMode;
     }
 
+    @Override
+    public boolean isSendUrlsAsParameters() {
+        return sendUrlsAsParameters;
+    }
+
 }
diff --git a/uitest/src/com/vaadin/tests/applicationservlet/DisableSendUrlAsParameters.java b/uitest/src/com/vaadin/tests/applicationservlet/DisableSendUrlAsParameters.java
new file mode 100644 (file)
index 0000000..d398ead
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.applicationservlet;
+
+import com.vaadin.launcher.CustomDeploymentConfiguration;
+import com.vaadin.launcher.CustomDeploymentConfiguration.Conf;
+import com.vaadin.server.Constants;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+
+@CustomDeploymentConfiguration({ @Conf(name = Constants.SERVLET_PARAMETER_SENDURLSASPARAMETERS, value = "false") })
+public class DisableSendUrlAsParameters extends AbstractTestUIWithLog {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        try {
+            log("Init location: " + getPage().getLocation());
+        } catch (IllegalStateException e) {
+            log("Init location exception: " + e.getMessage());
+        }
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/applicationservlet/DisableSendUrlAsParametersTest.java b/uitest/src/com/vaadin/tests/applicationservlet/DisableSendUrlAsParametersTest.java
new file mode 100644 (file)
index 0000000..f10f281
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.applicationservlet;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class DisableSendUrlAsParametersTest extends SingleBrowserTest {
+
+    @Test
+    public void testInitLocation() {
+        openTestURL();
+
+        String logRow = getLogRow(0);
+
+        Assert.assertEquals(
+                "1. Init location exception: Location is not available as the sendUrlsAsParameters parameter is configured as false",
+                logRow);
+    }
+}
index 3a7d42e29cd6c18728e7374e269e913076999b65..dba055a65a06e4a543b5f06efafbed16e4c2015b 100644 (file)
@@ -46,6 +46,11 @@ public abstract class AbstractTestUI extends UI {
     }
 
     protected void warnIfWidgetsetMaybeNotCompiled() {
+        // Can't check location if sendUrlAsParameters is disabled
+        if (!getSession().getConfiguration().isSendUrlsAsParameters()) {
+            return;
+        }
+
         // Ignore if using debug mode
         String query = getPage().getLocation().getQuery();
         if (query != null && query.matches(".*[&?]gwt\\.codesvr.*")) {