From e69c4908ba61b1fd09f0b50ecbc2e0ec11cd06f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Fri, 17 Aug 2012 16:54:35 +0300 Subject: [PATCH] Bugfixes: pass application properties to AbstractDeploymentConfiguration constructor so they are properly parsed and checked; properly use deploymentConfiguration in AbstractApplicationPortlet.isProductionMode(); return correct value from isXsrfProtectionEnabled() (#9340) --- .../server/AbstractApplicationPortlet.java | 183 +++++++++--------- .../server/AbstractApplicationServlet.java | 77 ++++---- .../AbstractDeploymentConfiguration.java | 8 +- 3 files changed, 136 insertions(+), 132 deletions(-) diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 06ed54990a..bd39504237 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -217,99 +217,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet // TODO Can we close the application when the portlet is removed? Do we know // when the portlet is removed? - private boolean productionMode = false; - - private DeploymentConfiguration deploymentConfiguration = new AbstractDeploymentConfiguration( - getClass()) { - @Override - public String getConfiguredWidgetset(WrappedRequest request) { - - String widgetset = getApplicationOrSystemProperty( - PARAMETER_WIDGETSET, null); - - if (widgetset == null) { - // If no widgetset defined for the application, check the - // portal - // property - widgetset = WrappedPortletRequest.cast(request) - .getPortalProperty(PORTAL_PARAMETER_VAADIN_WIDGETSET); - } - - if (widgetset == null) { - // If no widgetset defined for the portal, use the default - widgetset = DEFAULT_WIDGETSET; - } - - return widgetset; - } - - @Override - public String getConfiguredTheme(WrappedRequest request) { - - // is the default theme defined by the portal? - String themeName = WrappedPortletRequest.cast(request) - .getPortalProperty(Constants.PORTAL_PARAMETER_VAADIN_THEME); - - if (themeName == null) { - // no, using the default theme defined by Vaadin - themeName = DEFAULT_THEME_NAME; - } - - return themeName; - } - - @Override - public boolean isStandalone(WrappedRequest request) { - return false; - } - - /* - * (non-Javadoc) - * - * @see - * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation - * (com.vaadin.terminal.WrappedRequest) - * - * Return the URL from where static files, e.g. the widgetset and the - * theme, are served. In a standard configuration the VAADIN folder - * inside the returned folder is what is used for widgetsets and themes. - * - * @return The location of static resources (inside which there should - * be a VAADIN directory). Does not end with a slash (/). - */ - - @Override - public String getStaticFileLocation(WrappedRequest request) { - String staticFileLocation = WrappedPortletRequest.cast(request) - .getPortalProperty( - Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH); - if (staticFileLocation != null) { - // remove trailing slash if any - while (staticFileLocation.endsWith(".")) { - staticFileLocation = staticFileLocation.substring(0, - staticFileLocation.length() - 1); - } - return staticFileLocation; - } else { - // default for Liferay - return "/html"; - } - } - - @Override - public String getMimeType(String resourceName) { - return getPortletContext().getMimeType(resourceName); - } - }; - - private final AddonContext addonContext = new AddonContext( - getDeploymentConfiguration()); + private DeploymentConfiguration deploymentConfiguration; + private AddonContext addonContext; @Override public void init(PortletConfig config) throws PortletException { super.init(config); - Properties applicationProperties = getDeploymentConfiguration() - .getInitParameters(); + Properties applicationProperties = new Properties(); // Read default parameters from the context final PortletContext context = config.getPortletContext(); @@ -328,6 +242,93 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet config.getInitParameter(name)); } + deploymentConfiguration = new AbstractDeploymentConfiguration( + getClass(), applicationProperties) { + @Override + public String getConfiguredWidgetset(WrappedRequest request) { + + String widgetset = getApplicationOrSystemProperty( + PARAMETER_WIDGETSET, null); + + if (widgetset == null) { + // If no widgetset defined for the application, check the + // portal property + widgetset = WrappedPortletRequest.cast(request) + .getPortalProperty( + PORTAL_PARAMETER_VAADIN_WIDGETSET); + } + + if (widgetset == null) { + // If no widgetset defined for the portal, use the default + widgetset = DEFAULT_WIDGETSET; + } + + return widgetset; + } + + @Override + public String getConfiguredTheme(WrappedRequest request) { + + // is the default theme defined by the portal? + String themeName = WrappedPortletRequest.cast(request) + .getPortalProperty( + Constants.PORTAL_PARAMETER_VAADIN_THEME); + + if (themeName == null) { + // no, using the default theme defined by Vaadin + themeName = DEFAULT_THEME_NAME; + } + + return themeName; + } + + @Override + public boolean isStandalone(WrappedRequest request) { + return false; + } + + /* + * (non-Javadoc) + * + * @see + * com.vaadin.terminal.DeploymentConfiguration#getStaticFileLocation + * (com.vaadin.terminal.WrappedRequest) + * + * Return the URL from where static files, e.g. the widgetset and + * the theme, are served. In a standard configuration the VAADIN + * folder inside the returned folder is what is used for widgetsets + * and themes. + * + * @return The location of static resources (inside which there + * should be a VAADIN directory). Does not end with a slash (/). + */ + + @Override + public String getStaticFileLocation(WrappedRequest request) { + String staticFileLocation = WrappedPortletRequest + .cast(request) + .getPortalProperty( + Constants.PORTAL_PARAMETER_VAADIN_RESOURCE_PATH); + if (staticFileLocation != null) { + // remove trailing slash if any + while (staticFileLocation.endsWith(".")) { + staticFileLocation = staticFileLocation.substring(0, + staticFileLocation.length() - 1); + } + return staticFileLocation; + } else { + // default for Liferay + return "/html"; + } + } + + @Override + public String getMimeType(String resourceName) { + return getPortletContext().getMimeType(resourceName); + } + }; + + addonContext = new AddonContext(deploymentConfiguration); addonContext.init(); } @@ -384,13 +385,13 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet } /** - * Returns true if the servlet is running in production mode. Production + * Returns true if the portlet is running in production mode. Production * mode disables all debug facilities. * * @return true if in production mode, false if in debug mode */ public boolean isProductionMode() { - return productionMode; + return deploymentConfiguration.isProductionMode(); } protected void handleRequest(PortletRequest request, diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 8857c0e964..062ba6cdf7 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -99,43 +99,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements private final String resourcePath = null; - private DeploymentConfiguration deploymentConfiguration = new AbstractDeploymentConfiguration( - getClass()) { + private DeploymentConfiguration deploymentConfiguration; - @Override - public String getStaticFileLocation(WrappedRequest request) { - HttpServletRequest servletRequest = WrappedHttpServletRequest - .cast(request); - return AbstractApplicationServlet.this - .getStaticFilesLocation(servletRequest); - } - - @Override - public String getConfiguredWidgetset(WrappedRequest request) { - return getApplicationOrSystemProperty( - AbstractApplicationServlet.PARAMETER_WIDGETSET, - AbstractApplicationServlet.DEFAULT_WIDGETSET); - } - - @Override - public String getConfiguredTheme(WrappedRequest request) { - // Use the default - return AbstractApplicationServlet.getDefaultTheme(); - } - - @Override - public boolean isStandalone(WrappedRequest request) { - return true; - } - - @Override - public String getMimeType(String resourceName) { - return getServletContext().getMimeType(resourceName); - } - }; - - private final AddonContext addonContext = new AddonContext( - getDeploymentConfiguration()); + private AddonContext addonContext; /** * Called by the servlet container to indicate to a servlet that the servlet @@ -152,8 +118,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException { super.init(servletConfig); - Properties applicationProperties = getDeploymentConfiguration() - .getInitParameters(); + Properties applicationProperties = new Properties(); // Read default parameters from server.xml final ServletContext context = servletConfig.getServletContext(); @@ -172,6 +137,42 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements servletConfig.getInitParameter(name)); } + deploymentConfiguration = new AbstractDeploymentConfiguration( + getClass(), applicationProperties) { + + @Override + public String getStaticFileLocation(WrappedRequest request) { + HttpServletRequest servletRequest = WrappedHttpServletRequest + .cast(request); + return AbstractApplicationServlet.this + .getStaticFilesLocation(servletRequest); + } + + @Override + public String getConfiguredWidgetset(WrappedRequest request) { + return getApplicationOrSystemProperty( + AbstractApplicationServlet.PARAMETER_WIDGETSET, + AbstractApplicationServlet.DEFAULT_WIDGETSET); + } + + @Override + public String getConfiguredTheme(WrappedRequest request) { + // Use the default + return AbstractApplicationServlet.getDefaultTheme(); + } + + @Override + public boolean isStandalone(WrappedRequest request) { + return true; + } + + @Override + public String getMimeType(String resourceName) { + return getServletContext().getMimeType(resourceName); + } + }; + + addonContext = new AddonContext(deploymentConfiguration); addonContext.init(); } diff --git a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java index a8e4cdfaca..ad5acad5e9 100644 --- a/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java +++ b/server/src/com/vaadin/terminal/gwt/server/AbstractDeploymentConfiguration.java @@ -28,14 +28,16 @@ public abstract class AbstractDeploymentConfiguration implements DeploymentConfiguration { private final Class systemPropertyBaseClass; - private final Properties applicationProperties = new Properties(); + private final Properties applicationProperties; private AddonContext addonContext; private boolean productionMode; private boolean xsrfProtectionEnabled; private int resourceCacheTime; - public AbstractDeploymentConfiguration(Class systemPropertyBaseClass) { + public AbstractDeploymentConfiguration(Class systemPropertyBaseClass, + Properties applicationProperties) { this.systemPropertyBaseClass = systemPropertyBaseClass; + this.applicationProperties = applicationProperties; checkProductionMode(); checkXsrfProtection(); @@ -192,7 +194,7 @@ public abstract class AbstractDeploymentConfiguration implements * Log a warning if cross-site request forgery protection is disabled. */ private void checkXsrfProtection() { - xsrfProtectionEnabled = getApplicationOrSystemProperty( + xsrfProtectionEnabled = !getApplicationOrSystemProperty( Constants.SERVLET_PARAMETER_DISABLE_XSRF_PROTECTION, "false") .equals("true"); if (!xsrfProtectionEnabled) { -- 2.39.5