diff --git a/core/src/main/java/org/apache/struts2/StrutsConstants.java b/core/src/main/java/org/apache/struts2/StrutsConstants.java
index 03287d663..4671eb1ab 100644
--- a/core/src/main/java/org/apache/struts2/StrutsConstants.java
+++ b/core/src/main/java/org/apache/struts2/StrutsConstants.java
@@ -299,4 +299,6 @@ public final class StrutsConstants {
public static final String STRUTS_ADDITIONAL_EXCLUDED_PATTERNS = "struts.additional.excludedPatterns";
public static final String STRUTS_ADDITIONAL_ACCEPTED_PATTERNS = "struts.additional.acceptedPatterns";
+ public static final String STRUTS_CONTENT_TYPE_MATCHER = "struts.contentTypeMatcher";
+
}
diff --git a/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java b/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
index f9729796a..3a6deb2fc 100644
--- a/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
+++ b/core/src/main/java/org/apache/struts2/config/DefaultBeanSelectionProvider.java
@@ -67,6 +67,7 @@ import org.apache.struts2.dispatcher.DispatcherErrorHandler;
import org.apache.struts2.dispatcher.StaticContentLoader;
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
+import org.apache.struts2.util.ContentTypeMatcher;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.util.UrlHelper;
import org.apache.struts2.views.velocity.VelocityManager;
@@ -327,6 +328,12 @@ import java.util.StringTokenizer;
*
request |
* Used across different interceptors to check if given string matches one of the accepted patterns |
*
+ *
+ * | org.apache.struts2.util.ContentTypeMatcher |
+ * struts.contentTypeMatcher |
+ * singleton |
+ * Matches content type of uploaded files (since 2.3.22) |
+ *
*
*
*
@@ -391,6 +398,7 @@ public class DefaultBeanSelectionProvider extends AbstractBeanSelectionProvider
alias(ReflectionProvider.class, StrutsConstants.STRUTS_REFLECTIONPROVIDER, builder, props);
alias(ReflectionContextFactory.class, StrutsConstants.STRUTS_REFLECTIONCONTEXTFACTORY, builder, props);
alias(PatternMatcher.class, StrutsConstants.STRUTS_PATTERNMATCHER, builder, props);
+ alias(ContentTypeMatcher.class, StrutsConstants.STRUTS_CONTENT_TYPE_MATCHER, builder, props);
alias(StaticContentLoader.class, StrutsConstants.STRUTS_STATIC_CONTENT_LOADER, builder, props);
alias(UnknownHandlerManager.class, StrutsConstants.STRUTS_UNKNOWN_HANDLER_MANAGER, builder, props);
alias(UrlHelper.class, StrutsConstants.STRUTS_URL_HELPER, builder, props);
diff --git a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
index 0ce91bc6c..78970a02e 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/FileUploadInterceptor.java
@@ -31,12 +31,12 @@ import com.opensymphony.xwork2.ValidationAware;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
-import com.opensymphony.xwork2.util.PatternMatcher;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
+import org.apache.struts2.util.ContentTypeMatcher;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
@@ -195,11 +195,11 @@ public class FileUploadInterceptor extends AbstractInterceptor {
protected Set allowedTypesSet = Collections.emptySet();
protected Set allowedExtensionsSet = Collections.emptySet();
- private PatternMatcher matcher;
+ private ContentTypeMatcher matcher;
private Container container;
@Inject
- public void setMatcher(PatternMatcher matcher) {
+ public void setMatcher(ContentTypeMatcher matcher) {
this.matcher = matcher;
}
diff --git a/core/src/main/java/org/apache/struts2/util/ContentTypeMatcher.java b/core/src/main/java/org/apache/struts2/util/ContentTypeMatcher.java
new file mode 100644
index 000000000..0e21b7a70
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/util/ContentTypeMatcher.java
@@ -0,0 +1,16 @@
+package org.apache.struts2.util;
+
+import java.util.Map;
+
+/**
+ * Matches content type of uploaded files, similar to {@link com.opensymphony.xwork2.util.PatternMatcher}
+ *
+ * @since 2.3.22
+ */
+public interface ContentTypeMatcher {
+
+ E compilePattern(String data);
+
+ boolean match(Map map, String data, E expr);
+
+}
diff --git a/core/src/main/java/org/apache/struts2/util/DefaultContentTypeMatcher.java b/core/src/main/java/org/apache/struts2/util/DefaultContentTypeMatcher.java
new file mode 100644
index 000000000..6160675a8
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/util/DefaultContentTypeMatcher.java
@@ -0,0 +1,20 @@
+package org.apache.struts2.util;
+
+import com.opensymphony.xwork2.util.PatternMatcher;
+import com.opensymphony.xwork2.util.WildcardHelper;
+
+import java.util.Map;
+
+public class DefaultContentTypeMatcher implements ContentTypeMatcher {
+
+ private PatternMatcher matcher = new WildcardHelper();
+
+ public int[] compilePattern(String data) {
+ return matcher.compilePattern(data);
+ }
+
+ public boolean match(Map map, String data, int[] expr) {
+ return matcher.match(map, data, expr);
+ }
+
+}
diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml
index c6eec3496..88b6e13b4 100644
--- a/core/src/main/resources/struts-default.xml
+++ b/core/src/main/resources/struts-default.xml
@@ -74,6 +74,8 @@
+
+