You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by sd...@apache.org on 2017/03/29 09:56:50 UTC
[01/16] struts-extras git commit: added
HttpsOffloadAwareServletRedirectResult
Repository: struts-extras
Updated Branches:
refs/heads/master 8e1aadda4 -> c056b516a
added HttpsOffloadAwareServletRedirectResult
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/1a64217f
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/1a64217f
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/1a64217f
Branch: refs/heads/master
Commit: 1a64217f87566831864371622673951d29dca79a
Parents: 8e1aadd
Author: Stefaan Dutry <st...@gmail.com>
Authored: Mon Mar 27 23:20:48 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Mon Mar 27 23:20:48 2017 +0200
----------------------------------------------------------------------
struts2-custom-results-plugin/pom.xml | 104 +++++++++++++
.../HttpsOffloadAwareServletRedirectResult.java | 146 +++++++++++++++++++
2 files changed, 250 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/1a64217f/struts2-custom-results-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/pom.xml b/struts2-custom-results-plugin/pom.xml
new file mode 100644
index 0000000..44eadde
--- /dev/null
+++ b/struts2-custom-results-plugin/pom.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts-master</artifactId>
+ <version>10</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>struts2-custom-results-plugin</artifactId>
+ <version>1.2-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>struts2 custom results plugin</name>
+
+ <description>
+ This plugin defines some additional result types
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <scm>
+ <connection>scm:git:git://git.apache.org/struts-extras.git</connection>
+ <developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/struts-extras.git</developerConnection>
+ <url>http://git.apache.org/struts-extras.git</url>
+ <tag>HEAD</tag>
+ </scm>
+
+ <issueManagement>
+ <system>JIRA</system>
+ <url>https://issues.apache.org/jira/browse/WW</url>
+ </issueManagement>
+
+ <ciManagement>
+ <system>Jenkins</system>
+ <url>https://builds.apache.org/hudson/view/S-Z/view/Struts</url>
+ <notifiers>
+ <notifier>
+ <type>mail</type>
+ <configuration>
+ <address>dev@struts.apache.org</address>
+ </configuration>
+ </notifier>
+ </notifiers>
+ </ciManagement>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.struts</groupId>
+ <artifactId>struts2-core</artifactId>
+ <version>2.3.20.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>2.8</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/1a64217f/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
new file mode 100644
index 0000000..751e783
--- /dev/null
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
@@ -0,0 +1,146 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.struts2.dispatcher;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.dispatcher.ServletRedirectResult;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.views.util.UrlHelper;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.inject.Inject;
+
+public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
+ private static final long serialVersionUID = -5384946213381645549L;
+ private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
+
+ private UrlHelper urlHelper;
+
+ @Inject
+ public void setUrlHelper(UrlHelper urlHelper) {
+ this.urlHelper = urlHelper;
+ }
+
+ /**
+ * Redirects to the location specified by calling
+ * {@link HttpServletResponse#sendRedirect(String)}.
+ *
+ * @param finalLocation
+ * the location to redirect to.
+ * @param invocation
+ * an encapsulation of the action execution state.
+ * @throws Exception
+ * if an error occurs when redirecting.
+ */
+ protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+ ActionContext ctx = invocation.getInvocationContext();
+ HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
+ HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
+
+ if (isPathUrl(finalLocation)) {
+ if (!finalLocation.startsWith("/")) {
+ ActionMapping mapping = actionMapper.getMapping(request,
+ Dispatcher.getInstance().getConfigurationManager());
+ String namespace = null;
+ if (mapping != null) {
+ namespace = mapping.getNamespace();
+ }
+
+ if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
+ finalLocation = namespace + "/" + finalLocation;
+ } else {
+ finalLocation = "/" + finalLocation;
+ }
+ }
+
+ // if the URL's are relative to the servlet context, append the
+ // servlet context path
+ if (prependServletContext && (request.getContextPath() != null)
+ && (request.getContextPath().length() > 0)) {
+ finalLocation = request.getContextPath() + finalLocation;
+ }
+
+ finalLocation = fixSchemeIfNeeded(finalLocation, request);
+ }
+ ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
+ if (resultConfig != null) {
+ Map<String, String> resultConfigParams = resultConfig.getParams();
+
+ List<String> prohibitedResultParams = getProhibitedResultParams();
+ for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
+ if (!prohibitedResultParams.contains(e.getKey())) {
+ Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
+ suppressEmptyParameters);
+ if (!suppressEmptyParameters || !values.isEmpty()) {
+ requestParameters.put(e.getKey(), values);
+ }
+ }
+ }
+ }
+
+ StringBuilder tmpLocation = new StringBuilder(finalLocation);
+ urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
+
+ // add the anchor
+ if (anchor != null) {
+ tmpLocation.append('#').append(anchor);
+ }
+
+ finalLocation = response.encodeRedirectURL(tmpLocation.toString());
+
+ LOG.debug("Redirecting to finalLocation: {}", finalLocation);
+
+ sendRedirect(response, finalLocation);
+ }
+
+ private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
+ if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
+ LOG.debug("https offloading happened, fixing redirectlocation");
+ StringBuilder fixedLocation = new StringBuilder();
+ fixedLocation.append("https");
+ fixedLocation.append("://");
+ fixedLocation.append(request.getServerName());
+ if (request.getServerPort() != 80) {
+ fixedLocation.append(':');
+ fixedLocation.append(request.getServerPort());
+ }
+ fixedLocation.append(location);
+
+ return fixedLocation.toString();
+ } else {
+ return location;
+ }
+ }
+
+}
[08/16] struts-extras git commit: renamed https offloading to the
more widely used ssl offloading
Posted by sd...@apache.org.
renamed https offloading to the more widely used ssl offloading
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/b3ce14c9
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/b3ce14c9
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/b3ce14c9
Branch: refs/heads/master
Commit: b3ce14c9e744ca713373b358f71f0659bfb35803
Parents: ba12972
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 16:25:06 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 16:25:06 2017 +0200
----------------------------------------------------------------------
...OffloadAwareServletActionRedirectResult.java | 123 ------------
.../HttpsOffloadAwareServletRedirectResult.java | 188 -------------------
...OffloadAwareServletActionRedirectResult.java | 123 ++++++++++++
.../SslOffloadAwareServletRedirectResult.java | 188 +++++++++++++++++++
4 files changed, 311 insertions(+), 311 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/b3ce14c9/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java
deleted file mode 100644
index 0cd1390..0000000
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * $Id$
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.struts2.result;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.struts2.ServletActionContext;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.result.ServletRedirectResult;
-import org.apache.struts2.views.util.UrlHelper;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.config.entities.ResultConfig;
-import com.opensymphony.xwork2.inject.Inject;
-
-public class HttpsOffloadAwareServletActionRedirectResult extends HttpsOffloadAwareServletRedirectResult {
- /* The default parameter */
- public static final String DEFAULT_PARAM = "actionName";
-
- protected String actionName;
- protected String namespace;
- protected String method;
-
- public HttpsOffloadAwareServletActionRedirectResult() {}
-
- public HttpsOffloadAwareServletActionRedirectResult(String actionName) {
- this(null, actionName, null, null);
- }
-
- public HttpsOffloadAwareServletActionRedirectResult(String actionName, String method) {
- this(null, actionName, method, null);
- }
-
- public HttpsOffloadAwareServletActionRedirectResult(String namespace, String actionName, String method) {
- this(namespace, actionName, method, null);
- }
-
- public HttpsOffloadAwareServletActionRedirectResult(String namespace, String actionName, String method, String anchor) {
- super(null, anchor);
- this.namespace = namespace;
- this.actionName = actionName;
- this.method = method;
- }
-
- /**
- * @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
- */
- public void execute(ActionInvocation invocation) throws Exception {
- actionName = conditionalParse(actionName, invocation);
- if (namespace == null) {
- namespace = invocation.getProxy().getNamespace();
- } else {
- namespace = conditionalParse(namespace, invocation);
- }
- if (method == null) {
- method = "";
- } else {
- method = conditionalParse(method, invocation);
- }
-
- String tmpLocation = actionMapper.getUriFromActionMapping(new ActionMapping(actionName, namespace, method, null));
-
- setLocation(tmpLocation);
-
- super.execute(invocation);
- }
-
- /**
- * Sets the action name
- *
- * @param actionName The name
- */
- public void setActionName(String actionName) {
- this.actionName = actionName;
- }
-
- /**
- * Sets the namespace
- *
- * @param namespace The namespace
- */
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
-
- /**
- * Sets the method
- *
- * @param method The method
- */
- public void setMethod(String method) {
- this.method = method;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/b3ce14c9/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
deleted file mode 100644
index 3431467..0000000
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * $Id$
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.struts2.result;
-
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.struts2.ServletActionContext;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.result.ServletRedirectResult;
-import org.apache.struts2.views.util.UrlHelper;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.config.entities.ResultConfig;
-import com.opensymphony.xwork2.inject.Inject;
-
-public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
- private static final long serialVersionUID = -5384946213381645549L;
- private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
- private static final Pattern FORWARDED_PROTO_PARAM_HTTPS = Pattern.compile("[^;]proto=https[$;]");
-
- private UrlHelper urlHelper;
-
- @Inject
- public void setUrlHelper(UrlHelper urlHelper) {
- this.urlHelper = urlHelper;
- }
-
- public HttpsOffloadAwareServletRedirectResult() {
- super();
- }
-
- public HttpsOffloadAwareServletRedirectResult(String location) {
- this(location, null);
- }
-
- public HttpsOffloadAwareServletRedirectResult(String location, String anchor) {
- super(location, anchor);
- }
-
- /**
- * Redirects to the location specified by calling
- * {@link HttpServletResponse#sendRedirect(String)}.
- *
- * @param finalLocation
- * the location to redirect to.
- * @param invocation
- * an encapsulation of the action execution state.
- * @throws Exception
- * if an error occurs when redirecting.
- */
- protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
- ActionContext ctx = invocation.getInvocationContext();
- HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
- HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
-
- if (isPathUrl(finalLocation)) {
- if (!finalLocation.startsWith("/")) {
- ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
- String namespace = null;
- if (mapping != null) {
- namespace = mapping.getNamespace();
- }
-
- if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
- finalLocation = namespace + "/" + finalLocation;
- } else {
- finalLocation = "/" + finalLocation;
- }
- }
-
- // if the URL's are relative to the servlet context, append the
- // servlet context path
- if (prependServletContext && (request.getContextPath() != null)
- && (request.getContextPath().length() > 0)) {
- finalLocation = request.getContextPath() + finalLocation;
- }
-
- finalLocation = fixSchemeIfNeeded(finalLocation, request);
- }
- ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
- if (resultConfig != null) {
- Map<String, String> resultConfigParams = resultConfig.getParams();
-
- List<String> prohibitedResultParams = getProhibitedResultParams();
- for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
- if (!prohibitedResultParams.contains(e.getKey())) {
- Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
- suppressEmptyParameters);
- if (!suppressEmptyParameters || !values.isEmpty()) {
- requestParameters.put(e.getKey(), values);
- }
- }
- }
- }
-
- StringBuilder tmpLocation = new StringBuilder(finalLocation);
- urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
-
- // add the anchor
- if (anchor != null) {
- tmpLocation.append('#').append(anchor);
- }
-
- finalLocation = response.encodeRedirectURL(tmpLocation.toString());
-
- LOG.debug("Redirecting to finalLocation: {}", finalLocation);
-
- sendRedirect(response, finalLocation);
- }
-
- protected String fixSchemeIfNeeded(String location, HttpServletRequest request) {
- if (shouldFixScheme(request)) {
- LOG.debug("https offloading happened, fixing redirectlocation");
- StringBuilder fixedLocation = new StringBuilder();
- fixedLocation.append("https");
- fixedLocation.append("://");
- fixedLocation.append(request.getServerName());
- if (request.getServerPort() != 80) {
- fixedLocation.append(':');
- fixedLocation.append(request.getServerPort());
- }
- fixedLocation.append(location);
-
- return fixedLocation.toString();
- } else {
- return location;
- }
- }
-
- protected boolean shouldFixScheme(HttpServletRequest request) {
- return "https".equals(request.getHeader("X-Forwarded-Proto")) || hasForwardedHeaderWithProtoParamHttps(request);
- }
-
- private boolean hasForwardedHeaderWithProtoParamHttps(HttpServletRequest request) {
- Enumeration<String> forwardedHeaders = request.getHeaders("Forwarded");
-
- if (forwardedHeaders == null) {
- return false;
- }
-
- while (forwardedHeaders.hasMoreElements()) {
- String forwardedHeader = forwardedHeaders.nextElement();
- String[] forwardedHeaderElements = forwardedHeader.split(",");
-
- for (String forwardedHeaderElement : forwardedHeaderElements) {
- Matcher matcher = FORWARDED_PROTO_PARAM_HTTPS.matcher(forwardedHeaderElement.trim());
-
- if (matcher.matches()) {
- return true;
- }
- }
- }
-
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/b3ce14c9/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java
new file mode 100644
index 0000000..7c812f4
--- /dev/null
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java
@@ -0,0 +1,123 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.struts2.result;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.result.ServletRedirectResult;
+import org.apache.struts2.views.util.UrlHelper;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.inject.Inject;
+
+public class SslOffloadAwareServletActionRedirectResult extends SslOffloadAwareServletRedirectResult {
+ /* The default parameter */
+ public static final String DEFAULT_PARAM = "actionName";
+
+ protected String actionName;
+ protected String namespace;
+ protected String method;
+
+ public SslOffloadAwareServletActionRedirectResult() {}
+
+ public SslOffloadAwareServletActionRedirectResult(String actionName) {
+ this(null, actionName, null, null);
+ }
+
+ public SslOffloadAwareServletActionRedirectResult(String actionName, String method) {
+ this(null, actionName, method, null);
+ }
+
+ public SslOffloadAwareServletActionRedirectResult(String namespace, String actionName, String method) {
+ this(namespace, actionName, method, null);
+ }
+
+ public SslOffloadAwareServletActionRedirectResult(String namespace, String actionName, String method, String anchor) {
+ super(null, anchor);
+ this.namespace = namespace;
+ this.actionName = actionName;
+ this.method = method;
+ }
+
+ /**
+ * @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
+ */
+ public void execute(ActionInvocation invocation) throws Exception {
+ actionName = conditionalParse(actionName, invocation);
+ if (namespace == null) {
+ namespace = invocation.getProxy().getNamespace();
+ } else {
+ namespace = conditionalParse(namespace, invocation);
+ }
+ if (method == null) {
+ method = "";
+ } else {
+ method = conditionalParse(method, invocation);
+ }
+
+ String tmpLocation = actionMapper.getUriFromActionMapping(new ActionMapping(actionName, namespace, method, null));
+
+ setLocation(tmpLocation);
+
+ super.execute(invocation);
+ }
+
+ /**
+ * Sets the action name
+ *
+ * @param actionName The name
+ */
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
+ /**
+ * Sets the namespace
+ *
+ * @param namespace The namespace
+ */
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ /**
+ * Sets the method
+ *
+ * @param method The method
+ */
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/b3ce14c9/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
new file mode 100644
index 0000000..399c6f8
--- /dev/null
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
@@ -0,0 +1,188 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.struts2.result;
+
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.result.ServletRedirectResult;
+import org.apache.struts2.views.util.UrlHelper;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.inject.Inject;
+
+public class SslOffloadAwareServletRedirectResult extends ServletRedirectResult {
+ private static final long serialVersionUID = -5384946213381645549L;
+ private static final Logger LOG = LogManager.getLogger(SslOffloadAwareServletRedirectResult.class);
+ private static final Pattern FORWARDED_PROTO_PARAM_HTTPS = Pattern.compile("[^;]proto=https[$;]");
+
+ private UrlHelper urlHelper;
+
+ @Inject
+ public void setUrlHelper(UrlHelper urlHelper) {
+ this.urlHelper = urlHelper;
+ }
+
+ public SslOffloadAwareServletRedirectResult() {
+ super();
+ }
+
+ public SslOffloadAwareServletRedirectResult(String location) {
+ this(location, null);
+ }
+
+ public SslOffloadAwareServletRedirectResult(String location, String anchor) {
+ super(location, anchor);
+ }
+
+ /**
+ * Redirects to the location specified by calling
+ * {@link HttpServletResponse#sendRedirect(String)}.
+ *
+ * @param finalLocation
+ * the location to redirect to.
+ * @param invocation
+ * an encapsulation of the action execution state.
+ * @throws Exception
+ * if an error occurs when redirecting.
+ */
+ protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+ ActionContext ctx = invocation.getInvocationContext();
+ HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
+ HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
+
+ if (isPathUrl(finalLocation)) {
+ if (!finalLocation.startsWith("/")) {
+ ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
+ String namespace = null;
+ if (mapping != null) {
+ namespace = mapping.getNamespace();
+ }
+
+ if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
+ finalLocation = namespace + "/" + finalLocation;
+ } else {
+ finalLocation = "/" + finalLocation;
+ }
+ }
+
+ // if the URL's are relative to the servlet context, append the
+ // servlet context path
+ if (prependServletContext && (request.getContextPath() != null)
+ && (request.getContextPath().length() > 0)) {
+ finalLocation = request.getContextPath() + finalLocation;
+ }
+
+ finalLocation = fixSchemeIfNeeded(finalLocation, request);
+ }
+ ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
+ if (resultConfig != null) {
+ Map<String, String> resultConfigParams = resultConfig.getParams();
+
+ List<String> prohibitedResultParams = getProhibitedResultParams();
+ for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
+ if (!prohibitedResultParams.contains(e.getKey())) {
+ Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
+ suppressEmptyParameters);
+ if (!suppressEmptyParameters || !values.isEmpty()) {
+ requestParameters.put(e.getKey(), values);
+ }
+ }
+ }
+ }
+
+ StringBuilder tmpLocation = new StringBuilder(finalLocation);
+ urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
+
+ // add the anchor
+ if (anchor != null) {
+ tmpLocation.append('#').append(anchor);
+ }
+
+ finalLocation = response.encodeRedirectURL(tmpLocation.toString());
+
+ LOG.debug("Redirecting to finalLocation: {}", finalLocation);
+
+ sendRedirect(response, finalLocation);
+ }
+
+ protected String fixSchemeIfNeeded(String location, HttpServletRequest request) {
+ if (shouldFixScheme(request)) {
+ LOG.debug("https offloading happened, fixing redirectlocation");
+ StringBuilder fixedLocation = new StringBuilder();
+ fixedLocation.append("https");
+ fixedLocation.append("://");
+ fixedLocation.append(request.getServerName());
+ if (request.getServerPort() != 80) {
+ fixedLocation.append(':');
+ fixedLocation.append(request.getServerPort());
+ }
+ fixedLocation.append(location);
+
+ return fixedLocation.toString();
+ } else {
+ return location;
+ }
+ }
+
+ protected boolean shouldFixScheme(HttpServletRequest request) {
+ return "https".equals(request.getHeader("X-Forwarded-Proto")) || hasForwardedHeaderWithProtoParamHttps(request);
+ }
+
+ private boolean hasForwardedHeaderWithProtoParamHttps(HttpServletRequest request) {
+ Enumeration<String> forwardedHeaders = request.getHeaders("Forwarded");
+
+ if (forwardedHeaders == null) {
+ return false;
+ }
+
+ while (forwardedHeaders.hasMoreElements()) {
+ String forwardedHeader = forwardedHeaders.nextElement();
+ String[] forwardedHeaderElements = forwardedHeader.split(",");
+
+ for (String forwardedHeaderElement : forwardedHeaderElements) {
+ Matcher matcher = FORWARDED_PROTO_PARAM_HTTPS.matcher(forwardedHeaderElement.trim());
+
+ if (matcher.matches()) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+}
[05/16] struts-extras git commit: make method protected instead of
private
Posted by sd...@apache.org.
make method protected instead of private
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/b4b8c2d7
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/b4b8c2d7
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/b4b8c2d7
Branch: refs/heads/master
Commit: b4b8c2d7e962d1206a473bfdad47689895ff874b
Parents: 276471c
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 08:40:20 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 08:40:20 2017 +0200
----------------------------------------------------------------------
.../struts2/result/HttpsOffloadAwareServletRedirectResult.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/b4b8c2d7/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
index 9de6739..a211afb 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
@@ -135,7 +135,7 @@ public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResul
sendRedirect(response, finalLocation);
}
- private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
+ protected String fixSchemeIfNeeded(String location, HttpServletRequest request) {
if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
LOG.debug("https offloading happened, fixing redirectlocation");
StringBuilder fixedLocation = new StringBuilder();
[10/16] struts-extras git commit: added README.md
Posted by sd...@apache.org.
added README.md
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/f84e3f23
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/f84e3f23
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/f84e3f23
Branch: refs/heads/master
Commit: f84e3f2335065533e33de5e8ebea7d82d1125e8b
Parents: 00137f7
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 19:12:37 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 19:12:37 2017 +0200
----------------------------------------------------------------------
README.md | 1 +
struts2-custom-results-plugin/README.md | 42 ++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/f84e3f23/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index e5169d4..c1a5cad 100644
--- a/README.md
+++ b/README.md
@@ -9,6 +9,7 @@ mostly focused on fixing (if possibe) vulnerabilities in older versions of the f
- [Apache Struts 2 Secure Jakarta Multipart parser plugin](struts2-secure-jakarta-multipart-parser-plugin/README.md)
- [Apache Struts 2 Secure Jakarta Stream Multipart parser plugin](struts2-secure-jakarta-stream-multipart-parser-plugin/README.md)
+- [Apache Struts 2 Custom results plugin](struts2-custom-results-plugin/README.md)
## License
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/f84e3f23/struts2-custom-results-plugin/README.md
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/README.md b/struts2-custom-results-plugin/README.md
new file mode 100644
index 0000000..f19f2fb
--- /dev/null
+++ b/struts2-custom-results-plugin/README.md
@@ -0,0 +1,42 @@
+# Apache Struts 2 Extras - custom results plugin
+
+[![License](http://img.shields.io/:license-apache-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
+
+This plugin provides additional result types.
+
+## Supported versions
+
+This plugin can be used with the Apache Struts versions 2.5.x .
+
+## Result Type categories
+
+### SSL offloading support
+
+These result types are made to support redirecting under the https protocol while being behind a SSL offloading proxy.
+
+#### Result Types
+
+##### sslOffloadRedirect
+
+This Result Type should replace the `redirect` Result Type.
+It takes into account 2 ways of detecting the offloading:
+- `X-Forwarded-Proto` header (de-facto standard header)
+- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
+
+##### sslOffloadRedirectAction
+
+This Result Type should replace the `redirectAction` Result Type.
+It takes into account 2 ways of detecting the offloading:
+- `X-Forwarded-Proto` header (de-facto standard header)
+- `proto` attribute of the `Forwarded` header ( [RFC7239](https://tools.ietf.org/html/rfc7239) )
+
+#### struts packages
+
+##### ssl-offload
+
+Only thing this package does is defining the result types so that they can be used.
+
+##### ssl-offload-default
+
+Merely combines the `struts-default` package and the `ssl-offload` package.
+
[06/16] struts-extras git commit: extracted overridable method for
condition
Posted by sd...@apache.org.
extracted overridable method for condition
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/785a77fc
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/785a77fc
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/785a77fc
Branch: refs/heads/master
Commit: 785a77fcfc85c4e8643b1379c3304563bd2705a5
Parents: b4b8c2d
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 08:45:58 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 08:45:58 2017 +0200
----------------------------------------------------------------------
.../struts2/result/HttpsOffloadAwareServletRedirectResult.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/785a77fc/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
index a211afb..5c70339 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
@@ -136,7 +136,7 @@ public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResul
}
protected String fixSchemeIfNeeded(String location, HttpServletRequest request) {
- if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
+ if (shouldFixScheme(request)) {
LOG.debug("https offloading happened, fixing redirectlocation");
StringBuilder fixedLocation = new StringBuilder();
fixedLocation.append("https");
@@ -154,4 +154,8 @@ public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResul
}
}
+ protected boolean shouldFixScheme(HttpServletRequest request) {
+ return "https".equals(request.getHeader("X-Forwarded-Proto"));
+ }
+
}
[13/16] struts-extras git commit: removed $Id$ tag
Posted by sd...@apache.org.
removed $Id$ tag
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/5df13a81
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/5df13a81
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/5df13a81
Branch: refs/heads/master
Commit: 5df13a81305c4943015cf43426622eb04698f280
Parents: 6845ba7
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 21:17:57 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 21:17:57 2017 +0200
----------------------------------------------------------------------
.../struts2/result/SslOffloadAwareServletActionRedirectResult.java | 2 --
.../struts2/result/SslOffloadAwareServletRedirectResult.java | 2 --
2 files changed, 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/5df13a81/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java
index 7c812f4..a52ebfb 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletActionRedirectResult.java
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/5df13a81/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
index 399c6f8..6a1b4d3 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
[14/16] struts-extras git commit: change method modifier to protected
Posted by sd...@apache.org.
change method modifier to protected
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/6ac80743
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/6ac80743
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/6ac80743
Branch: refs/heads/master
Commit: 6ac80743f253c0f5581c15a41c28b4e11e44abb4
Parents: 5df13a8
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 21:20:05 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 21:20:05 2017 +0200
----------------------------------------------------------------------
.../struts2/result/SslOffloadAwareServletRedirectResult.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/6ac80743/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
index 6a1b4d3..c540ad0 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
@@ -160,7 +160,7 @@ public class SslOffloadAwareServletRedirectResult extends ServletRedirectResult
return "https".equals(request.getHeader("X-Forwarded-Proto")) || hasForwardedHeaderWithProtoParamHttps(request);
}
- private boolean hasForwardedHeaderWithProtoParamHttps(HttpServletRequest request) {
+ protected boolean hasForwardedHeaderWithProtoParamHttps(HttpServletRequest request) {
Enumeration<String> forwardedHeaders = request.getHeaders("Forwarded");
if (forwardedHeaders == null) {
[11/16] struts-extras git commit: defined dependencies as optional
Posted by sd...@apache.org.
defined dependencies as optional
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/3ca17a46
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/3ca17a46
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/3ca17a46
Branch: refs/heads/master
Commit: 3ca17a46dd1432404967566ea6218120dbcf8aec
Parents: f84e3f2
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 21:13:31 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 21:13:31 2017 +0200
----------------------------------------------------------------------
struts2-custom-results-plugin/pom.xml | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/3ca17a46/struts2-custom-results-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/pom.xml b/struts2-custom-results-plugin/pom.xml
index b0efc2d..e3cc5e7 100644
--- a/struts2-custom-results-plugin/pom.xml
+++ b/struts2-custom-results-plugin/pom.xml
@@ -71,12 +71,14 @@
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.10.1</version>
+ <optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8</version>
+ <optional>true</optional>
</dependency>
<dependency>
[09/16] struts-extras git commit: added struts-plugin.xml providing
both a ssl-offload package and a convenience ssl-offload-default package
Posted by sd...@apache.org.
added struts-plugin.xml providing both a ssl-offload package and a convenience ssl-offload-default package
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/00137f77
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/00137f77
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/00137f77
Branch: refs/heads/master
Commit: 00137f775abae1859743c5aedb3b1b0d23b71315
Parents: b3ce14c
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 16:43:22 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 16:43:22 2017 +0200
----------------------------------------------------------------------
.../src/main/resources/struts-plugin.xml | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/00137f77/struts2-custom-results-plugin/src/main/resources/struts-plugin.xml
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/resources/struts-plugin.xml b/struts2-custom-results-plugin/src/main/resources/struts-plugin.xml
new file mode 100644
index 0000000..a47009e
--- /dev/null
+++ b/struts2-custom-results-plugin/src/main/resources/struts-plugin.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
+ "http://struts.apache.org/dtds/struts-2.5.dtd">
+
+<struts>
+ <package name="ssl-offload">
+ <result-types>
+ <result-type name="sslOffloadRedirect" class="org.apache.struts2.result.SslOffloadAwareServletRedirectResult"/>
+ <result-type name="sslOffloadRedirectAction" class="org.apache.struts2.result.SslOffloadAwareServletActionRedirectResult"/>
+ </result-types>
+ </package>
+
+ <package name="ssl-offload-default" extends="struts-default, ssl-offload">
+ </package>
+</struts>
+
[07/16] struts-extras git commit: added support for the Forwarded
header (RFC7239)
Posted by sd...@apache.org.
added support for the Forwarded header (RFC7239)
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/ba12972c
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/ba12972c
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/ba12972c
Branch: refs/heads/master
Commit: ba12972cbc0e030a20dec11cf6a0b4dd2360aafd
Parents: 785a77f
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 13:24:52 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 13:24:52 2017 +0200
----------------------------------------------------------------------
.../HttpsOffloadAwareServletRedirectResult.java | 29 +++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/ba12972c/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
index 5c70339..3431467 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
@@ -22,8 +22,11 @@
package org.apache.struts2.result;
import java.util.Collection;
+import java.util.Enumeration;
import java.util.List;
import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -44,6 +47,7 @@ import com.opensymphony.xwork2.inject.Inject;
public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
private static final long serialVersionUID = -5384946213381645549L;
private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
+ private static final Pattern FORWARDED_PROTO_PARAM_HTTPS = Pattern.compile("[^;]proto=https[$;]");
private UrlHelper urlHelper;
@@ -155,7 +159,30 @@ public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResul
}
protected boolean shouldFixScheme(HttpServletRequest request) {
- return "https".equals(request.getHeader("X-Forwarded-Proto"));
+ return "https".equals(request.getHeader("X-Forwarded-Proto")) || hasForwardedHeaderWithProtoParamHttps(request);
+ }
+
+ private boolean hasForwardedHeaderWithProtoParamHttps(HttpServletRequest request) {
+ Enumeration<String> forwardedHeaders = request.getHeaders("Forwarded");
+
+ if (forwardedHeaders == null) {
+ return false;
+ }
+
+ while (forwardedHeaders.hasMoreElements()) {
+ String forwardedHeader = forwardedHeaders.nextElement();
+ String[] forwardedHeaderElements = forwardedHeader.split(",");
+
+ for (String forwardedHeaderElement : forwardedHeaderElements) {
+ Matcher matcher = FORWARDED_PROTO_PARAM_HTTPS.matcher(forwardedHeaderElement.trim());
+
+ if (matcher.matches()) {
+ return true;
+ }
+ }
+ }
+
+ return false;
}
}
[04/16] struts-extras git commit: added
HttpsOffloadAwareServletActionRedirectResult
Posted by sd...@apache.org.
added HttpsOffloadAwareServletActionRedirectResult
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/276471cc
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/276471cc
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/276471cc
Branch: refs/heads/master
Commit: 276471cc49c84e5016d2beaf7770a5e036e5e191
Parents: 02a1ca6
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 08:35:36 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 08:35:36 2017 +0200
----------------------------------------------------------------------
...OffloadAwareServletActionRedirectResult.java | 123 +++++++++++++++++++
.../HttpsOffloadAwareServletRedirectResult.java | 12 ++
2 files changed, 135 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/276471cc/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java
new file mode 100644
index 0000000..0cd1390
--- /dev/null
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletActionRedirectResult.java
@@ -0,0 +1,123 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.struts2.result;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.result.ServletRedirectResult;
+import org.apache.struts2.views.util.UrlHelper;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.inject.Inject;
+
+public class HttpsOffloadAwareServletActionRedirectResult extends HttpsOffloadAwareServletRedirectResult {
+ /* The default parameter */
+ public static final String DEFAULT_PARAM = "actionName";
+
+ protected String actionName;
+ protected String namespace;
+ protected String method;
+
+ public HttpsOffloadAwareServletActionRedirectResult() {}
+
+ public HttpsOffloadAwareServletActionRedirectResult(String actionName) {
+ this(null, actionName, null, null);
+ }
+
+ public HttpsOffloadAwareServletActionRedirectResult(String actionName, String method) {
+ this(null, actionName, method, null);
+ }
+
+ public HttpsOffloadAwareServletActionRedirectResult(String namespace, String actionName, String method) {
+ this(namespace, actionName, method, null);
+ }
+
+ public HttpsOffloadAwareServletActionRedirectResult(String namespace, String actionName, String method, String anchor) {
+ super(null, anchor);
+ this.namespace = namespace;
+ this.actionName = actionName;
+ this.method = method;
+ }
+
+ /**
+ * @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
+ */
+ public void execute(ActionInvocation invocation) throws Exception {
+ actionName = conditionalParse(actionName, invocation);
+ if (namespace == null) {
+ namespace = invocation.getProxy().getNamespace();
+ } else {
+ namespace = conditionalParse(namespace, invocation);
+ }
+ if (method == null) {
+ method = "";
+ } else {
+ method = conditionalParse(method, invocation);
+ }
+
+ String tmpLocation = actionMapper.getUriFromActionMapping(new ActionMapping(actionName, namespace, method, null));
+
+ setLocation(tmpLocation);
+
+ super.execute(invocation);
+ }
+
+ /**
+ * Sets the action name
+ *
+ * @param actionName The name
+ */
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
+ /**
+ * Sets the namespace
+ *
+ * @param namespace The namespace
+ */
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ /**
+ * Sets the method
+ *
+ * @param method The method
+ */
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/276471cc/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
index 201eb3b..9de6739 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
@@ -52,6 +52,18 @@ public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResul
this.urlHelper = urlHelper;
}
+ public HttpsOffloadAwareServletRedirectResult() {
+ super();
+ }
+
+ public HttpsOffloadAwareServletRedirectResult(String location) {
+ this(location, null);
+ }
+
+ public HttpsOffloadAwareServletRedirectResult(String location, String anchor) {
+ super(location, anchor);
+ }
+
/**
* Redirects to the location specified by calling
* {@link HttpServletResponse#sendRedirect(String)}.
[12/16] struts-extras git commit: corrected java version
Posted by sd...@apache.org.
corrected java version
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/6845ba79
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/6845ba79
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/6845ba79
Branch: refs/heads/master
Commit: 6845ba79835813ec3a37eeedada7da8139821a15
Parents: 3ca17a4
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 21:15:30 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 21:15:30 2017 +0200
----------------------------------------------------------------------
struts2-custom-results-plugin/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/6845ba79/struts2-custom-results-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/pom.xml b/struts2-custom-results-plugin/pom.xml
index e3cc5e7..db8ebb4 100644
--- a/struts2-custom-results-plugin/pom.xml
+++ b/struts2-custom-results-plugin/pom.xml
@@ -96,8 +96,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.6</source>
- <target>1.6</target>
+ <source>1.7</source>
+ <target>1.7</target>
</configuration>
</plugin>
</plugins>
[02/16] struts-extras git commit: used spaces for indentation
Posted by sd...@apache.org.
used spaces for indentation
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/7879bafe
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/7879bafe
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/7879bafe
Branch: refs/heads/master
Commit: 7879bafe58fd7d82d8e31f34dd88736e337f0a12
Parents: 1a64217
Author: Stefaan Dutry <st...@gmail.com>
Authored: Mon Mar 27 23:25:40 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Mon Mar 27 23:25:40 2017 +0200
----------------------------------------------------------------------
.../HttpsOffloadAwareServletRedirectResult.java | 200 +++++++++----------
1 file changed, 100 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/7879bafe/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
index 751e783..b3ee26a 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
@@ -42,105 +42,105 @@ import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.inject.Inject;
public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
- private static final long serialVersionUID = -5384946213381645549L;
- private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
-
- private UrlHelper urlHelper;
-
- @Inject
- public void setUrlHelper(UrlHelper urlHelper) {
- this.urlHelper = urlHelper;
- }
-
- /**
- * Redirects to the location specified by calling
- * {@link HttpServletResponse#sendRedirect(String)}.
- *
- * @param finalLocation
- * the location to redirect to.
- * @param invocation
- * an encapsulation of the action execution state.
- * @throws Exception
- * if an error occurs when redirecting.
- */
- protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
- ActionContext ctx = invocation.getInvocationContext();
- HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
- HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
-
- if (isPathUrl(finalLocation)) {
- if (!finalLocation.startsWith("/")) {
- ActionMapping mapping = actionMapper.getMapping(request,
- Dispatcher.getInstance().getConfigurationManager());
- String namespace = null;
- if (mapping != null) {
- namespace = mapping.getNamespace();
- }
-
- if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
- finalLocation = namespace + "/" + finalLocation;
- } else {
- finalLocation = "/" + finalLocation;
- }
- }
-
- // if the URL's are relative to the servlet context, append the
- // servlet context path
- if (prependServletContext && (request.getContextPath() != null)
- && (request.getContextPath().length() > 0)) {
- finalLocation = request.getContextPath() + finalLocation;
- }
-
- finalLocation = fixSchemeIfNeeded(finalLocation, request);
- }
- ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
- if (resultConfig != null) {
- Map<String, String> resultConfigParams = resultConfig.getParams();
-
- List<String> prohibitedResultParams = getProhibitedResultParams();
- for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
- if (!prohibitedResultParams.contains(e.getKey())) {
- Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
- suppressEmptyParameters);
- if (!suppressEmptyParameters || !values.isEmpty()) {
- requestParameters.put(e.getKey(), values);
- }
- }
- }
- }
-
- StringBuilder tmpLocation = new StringBuilder(finalLocation);
- urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
-
- // add the anchor
- if (anchor != null) {
- tmpLocation.append('#').append(anchor);
- }
-
- finalLocation = response.encodeRedirectURL(tmpLocation.toString());
-
- LOG.debug("Redirecting to finalLocation: {}", finalLocation);
-
- sendRedirect(response, finalLocation);
- }
-
- private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
- if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
- LOG.debug("https offloading happened, fixing redirectlocation");
- StringBuilder fixedLocation = new StringBuilder();
- fixedLocation.append("https");
- fixedLocation.append("://");
- fixedLocation.append(request.getServerName());
- if (request.getServerPort() != 80) {
- fixedLocation.append(':');
- fixedLocation.append(request.getServerPort());
- }
- fixedLocation.append(location);
-
- return fixedLocation.toString();
- } else {
- return location;
- }
- }
+ private static final long serialVersionUID = -5384946213381645549L;
+ private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
+
+ private UrlHelper urlHelper;
+
+ @Inject
+ public void setUrlHelper(UrlHelper urlHelper) {
+ this.urlHelper = urlHelper;
+ }
+
+ /**
+ * Redirects to the location specified by calling
+ * {@link HttpServletResponse#sendRedirect(String)}.
+ *
+ * @param finalLocation
+ * the location to redirect to.
+ * @param invocation
+ * an encapsulation of the action execution state.
+ * @throws Exception
+ * if an error occurs when redirecting.
+ */
+ protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+ ActionContext ctx = invocation.getInvocationContext();
+ HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
+ HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
+
+ if (isPathUrl(finalLocation)) {
+ if (!finalLocation.startsWith("/")) {
+ ActionMapping mapping = actionMapper.getMapping(request,
+ Dispatcher.getInstance().getConfigurationManager());
+ String namespace = null;
+ if (mapping != null) {
+ namespace = mapping.getNamespace();
+ }
+
+ if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
+ finalLocation = namespace + "/" + finalLocation;
+ } else {
+ finalLocation = "/" + finalLocation;
+ }
+ }
+
+ // if the URL's are relative to the servlet context, append the
+ // servlet context path
+ if (prependServletContext && (request.getContextPath() != null)
+ && (request.getContextPath().length() > 0)) {
+ finalLocation = request.getContextPath() + finalLocation;
+ }
+
+ finalLocation = fixSchemeIfNeeded(finalLocation, request);
+ }
+ ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
+ if (resultConfig != null) {
+ Map<String, String> resultConfigParams = resultConfig.getParams();
+
+ List<String> prohibitedResultParams = getProhibitedResultParams();
+ for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
+ if (!prohibitedResultParams.contains(e.getKey())) {
+ Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
+ suppressEmptyParameters);
+ if (!suppressEmptyParameters || !values.isEmpty()) {
+ requestParameters.put(e.getKey(), values);
+ }
+ }
+ }
+ }
+
+ StringBuilder tmpLocation = new StringBuilder(finalLocation);
+ urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
+
+ // add the anchor
+ if (anchor != null) {
+ tmpLocation.append('#').append(anchor);
+ }
+
+ finalLocation = response.encodeRedirectURL(tmpLocation.toString());
+
+ LOG.debug("Redirecting to finalLocation: {}", finalLocation);
+
+ sendRedirect(response, finalLocation);
+ }
+
+ private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
+ if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
+ LOG.debug("https offloading happened, fixing redirectlocation");
+ StringBuilder fixedLocation = new StringBuilder();
+ fixedLocation.append("https");
+ fixedLocation.append("://");
+ fixedLocation.append(request.getServerName());
+ if (request.getServerPort() != 80) {
+ fixedLocation.append(':');
+ fixedLocation.append(request.getServerPort());
+ }
+ fixedLocation.append(location);
+
+ return fixedLocation.toString();
+ } else {
+ return location;
+ }
+ }
}
[16/16] struts-extras git commit: added information on how to
register the Result Types
Posted by sd...@apache.org.
added information on how to register the Result Types
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/c056b516
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/c056b516
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/c056b516
Branch: refs/heads/master
Commit: c056b516acdd518ea4e1fa8b66d950e20299dcee
Parents: d74f9cc
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 21:45:04 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 21:45:04 2017 +0200
----------------------------------------------------------------------
struts2-custom-results-plugin/README.md | 39 ++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/c056b516/struts2-custom-results-plugin/README.md
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/README.md b/struts2-custom-results-plugin/README.md
index f19f2fb..bf1e147 100644
--- a/struts2-custom-results-plugin/README.md
+++ b/struts2-custom-results-plugin/README.md
@@ -40,3 +40,42 @@ Only thing this package does is defining the result types so that they can be us
Merely combines the `struts-default` package and the `ssl-offload` package.
+#### How to use
+
+The requirement for using these Result Types is that they are defined.
+
+This could be done in a couple ways:
+
+*Defining the types manualy in your own package*
+
+The Result Types can be registered in your own package as follows:
+
+```xml
+ <package name="myPackage" extends="struts-default">
+ <result-types>
+ <result-type name="sslOffloadRedirect" class="org.apache.struts2.result.SslOffloadAwareServletRedirectResult"/>
+ <result-type name="sslOffloadRedirectAction" class="org.apache.struts2.result.SslOffloadAwareServletActionRedirectResult"/>
+ </result-types>
+ ...
+ </package>
+```
+
+*Using the ssl-offload package as a parent*
+
+You can also just specify the `ssl-offload` package as a parent your package extends from.
+
+```xml
+ <package name="myPackage" extends="struts-default, ssl-offload">
+ ...
+ </package>
+```
+
+*Using the ssl-offload-default as a parent*
+
+You can also just specify the `ssl-offload-default` package as a parent your package extends from. This should have the same effect as extending both `struts-default` and `ssl-offload`
+
+```xml
+ <package name="myPackage" extends="ssl-offload-default">
+ ...
+ </package>
+```
[03/16] struts-extras git commit: fixed struts version
Posted by sd...@apache.org.
fixed struts version
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/02a1ca68
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/02a1ca68
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/02a1ca68
Branch: refs/heads/master
Commit: 02a1ca6819aa355574930285a0990a8b080bdd4a
Parents: 7879baf
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 08:23:12 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 08:23:12 2017 +0200
----------------------------------------------------------------------
struts2-custom-results-plugin/pom.xml | 2 +-
.../HttpsOffloadAwareServletRedirectResult.java | 146 -------------------
.../HttpsOffloadAwareServletRedirectResult.java | 145 ++++++++++++++++++
3 files changed, 146 insertions(+), 147 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/02a1ca68/struts2-custom-results-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/pom.xml b/struts2-custom-results-plugin/pom.xml
index 44eadde..b0efc2d 100644
--- a/struts2-custom-results-plugin/pom.xml
+++ b/struts2-custom-results-plugin/pom.xml
@@ -70,7 +70,7 @@
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
- <version>2.3.20.1</version>
+ <version>2.5.10.1</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/02a1ca68/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
deleted file mode 100644
index b3ee26a..0000000
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/dispatcher/HttpsOffloadAwareServletRedirectResult.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * $Id$
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.struts2.dispatcher;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.struts2.ServletActionContext;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.ServletRedirectResult;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.views.util.UrlHelper;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.config.entities.ResultConfig;
-import com.opensymphony.xwork2.inject.Inject;
-
-public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
- private static final long serialVersionUID = -5384946213381645549L;
- private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
-
- private UrlHelper urlHelper;
-
- @Inject
- public void setUrlHelper(UrlHelper urlHelper) {
- this.urlHelper = urlHelper;
- }
-
- /**
- * Redirects to the location specified by calling
- * {@link HttpServletResponse#sendRedirect(String)}.
- *
- * @param finalLocation
- * the location to redirect to.
- * @param invocation
- * an encapsulation of the action execution state.
- * @throws Exception
- * if an error occurs when redirecting.
- */
- protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
- ActionContext ctx = invocation.getInvocationContext();
- HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
- HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
-
- if (isPathUrl(finalLocation)) {
- if (!finalLocation.startsWith("/")) {
- ActionMapping mapping = actionMapper.getMapping(request,
- Dispatcher.getInstance().getConfigurationManager());
- String namespace = null;
- if (mapping != null) {
- namespace = mapping.getNamespace();
- }
-
- if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
- finalLocation = namespace + "/" + finalLocation;
- } else {
- finalLocation = "/" + finalLocation;
- }
- }
-
- // if the URL's are relative to the servlet context, append the
- // servlet context path
- if (prependServletContext && (request.getContextPath() != null)
- && (request.getContextPath().length() > 0)) {
- finalLocation = request.getContextPath() + finalLocation;
- }
-
- finalLocation = fixSchemeIfNeeded(finalLocation, request);
- }
- ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
- if (resultConfig != null) {
- Map<String, String> resultConfigParams = resultConfig.getParams();
-
- List<String> prohibitedResultParams = getProhibitedResultParams();
- for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
- if (!prohibitedResultParams.contains(e.getKey())) {
- Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
- suppressEmptyParameters);
- if (!suppressEmptyParameters || !values.isEmpty()) {
- requestParameters.put(e.getKey(), values);
- }
- }
- }
- }
-
- StringBuilder tmpLocation = new StringBuilder(finalLocation);
- urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
-
- // add the anchor
- if (anchor != null) {
- tmpLocation.append('#').append(anchor);
- }
-
- finalLocation = response.encodeRedirectURL(tmpLocation.toString());
-
- LOG.debug("Redirecting to finalLocation: {}", finalLocation);
-
- sendRedirect(response, finalLocation);
- }
-
- private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
- if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
- LOG.debug("https offloading happened, fixing redirectlocation");
- StringBuilder fixedLocation = new StringBuilder();
- fixedLocation.append("https");
- fixedLocation.append("://");
- fixedLocation.append(request.getServerName());
- if (request.getServerPort() != 80) {
- fixedLocation.append(':');
- fixedLocation.append(request.getServerPort());
- }
- fixedLocation.append(location);
-
- return fixedLocation.toString();
- } else {
- return location;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/02a1ca68/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
new file mode 100644
index 0000000..201eb3b
--- /dev/null
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/HttpsOffloadAwareServletRedirectResult.java
@@ -0,0 +1,145 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.struts2.result;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.result.ServletRedirectResult;
+import org.apache.struts2.views.util.UrlHelper;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.inject.Inject;
+
+public class HttpsOffloadAwareServletRedirectResult extends ServletRedirectResult {
+ private static final long serialVersionUID = -5384946213381645549L;
+ private static final Logger LOG = LogManager.getLogger(HttpsOffloadAwareServletRedirectResult.class);
+
+ private UrlHelper urlHelper;
+
+ @Inject
+ public void setUrlHelper(UrlHelper urlHelper) {
+ this.urlHelper = urlHelper;
+ }
+
+ /**
+ * Redirects to the location specified by calling
+ * {@link HttpServletResponse#sendRedirect(String)}.
+ *
+ * @param finalLocation
+ * the location to redirect to.
+ * @param invocation
+ * an encapsulation of the action execution state.
+ * @throws Exception
+ * if an error occurs when redirecting.
+ */
+ protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
+ ActionContext ctx = invocation.getInvocationContext();
+ HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
+ HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
+
+ if (isPathUrl(finalLocation)) {
+ if (!finalLocation.startsWith("/")) {
+ ActionMapping mapping = actionMapper.getMapping(request, Dispatcher.getInstance().getConfigurationManager());
+ String namespace = null;
+ if (mapping != null) {
+ namespace = mapping.getNamespace();
+ }
+
+ if ((namespace != null) && (namespace.length() > 0) && (!"/".equals(namespace))) {
+ finalLocation = namespace + "/" + finalLocation;
+ } else {
+ finalLocation = "/" + finalLocation;
+ }
+ }
+
+ // if the URL's are relative to the servlet context, append the
+ // servlet context path
+ if (prependServletContext && (request.getContextPath() != null)
+ && (request.getContextPath().length() > 0)) {
+ finalLocation = request.getContextPath() + finalLocation;
+ }
+
+ finalLocation = fixSchemeIfNeeded(finalLocation, request);
+ }
+ ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(invocation.getResultCode());
+ if (resultConfig != null) {
+ Map<String, String> resultConfigParams = resultConfig.getParams();
+
+ List<String> prohibitedResultParams = getProhibitedResultParams();
+ for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
+ if (!prohibitedResultParams.contains(e.getKey())) {
+ Collection<String> values = conditionalParseCollection(e.getValue(), invocation,
+ suppressEmptyParameters);
+ if (!suppressEmptyParameters || !values.isEmpty()) {
+ requestParameters.put(e.getKey(), values);
+ }
+ }
+ }
+ }
+
+ StringBuilder tmpLocation = new StringBuilder(finalLocation);
+ urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
+
+ // add the anchor
+ if (anchor != null) {
+ tmpLocation.append('#').append(anchor);
+ }
+
+ finalLocation = response.encodeRedirectURL(tmpLocation.toString());
+
+ LOG.debug("Redirecting to finalLocation: {}", finalLocation);
+
+ sendRedirect(response, finalLocation);
+ }
+
+ private String fixSchemeIfNeeded(String location, HttpServletRequest request) {
+ if ("https".equals(request.getHeader("X-Forwarded-Proto"))) {
+ LOG.debug("https offloading happened, fixing redirectlocation");
+ StringBuilder fixedLocation = new StringBuilder();
+ fixedLocation.append("https");
+ fixedLocation.append("://");
+ fixedLocation.append(request.getServerName());
+ if (request.getServerPort() != 80) {
+ fixedLocation.append(':');
+ fixedLocation.append(request.getServerPort());
+ }
+ fixedLocation.append(location);
+
+ return fixedLocation.toString();
+ } else {
+ return location;
+ }
+ }
+
+}
[15/16] struts-extras git commit: extracted method for
X-Forwarded-Proto header check
Posted by sd...@apache.org.
extracted method for X-Forwarded-Proto header check
Project: http://git-wip-us.apache.org/repos/asf/struts-extras/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-extras/commit/d74f9cc5
Tree: http://git-wip-us.apache.org/repos/asf/struts-extras/tree/d74f9cc5
Diff: http://git-wip-us.apache.org/repos/asf/struts-extras/diff/d74f9cc5
Branch: refs/heads/master
Commit: d74f9cc50e26b0ac82f3c7707893462b0289538a
Parents: 6ac8074
Author: Stefaan Dutry <st...@gmail.com>
Authored: Tue Mar 28 21:23:19 2017 +0200
Committer: Stefaan Dutry <st...@gmail.com>
Committed: Tue Mar 28 21:23:19 2017 +0200
----------------------------------------------------------------------
.../struts2/result/SslOffloadAwareServletRedirectResult.java | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts-extras/blob/d74f9cc5/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
index c540ad0..0955f8a 100644
--- a/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
+++ b/struts2-custom-results-plugin/src/main/java/org/apache/struts2/result/SslOffloadAwareServletRedirectResult.java
@@ -157,7 +157,11 @@ public class SslOffloadAwareServletRedirectResult extends ServletRedirectResult
}
protected boolean shouldFixScheme(HttpServletRequest request) {
- return "https".equals(request.getHeader("X-Forwarded-Proto")) || hasForwardedHeaderWithProtoParamHttps(request);
+ return hasXForwardedProtoHttps(request) || hasForwardedHeaderWithProtoParamHttps(request);
+ }
+
+ protected boolean hasXForwardedProtoHttps(HttpServletRequest request) {
+ return "https".equals(request.getHeader("X-Forwarded-Proto"));
}
protected boolean hasForwardedHeaderWithProtoParamHttps(HttpServletRequest request) {