mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-4457 Uses dedicated type to match content type of uploaded files
This commit is contained in:
@@ -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";
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
* <td>request</td>
|
||||
* <td>Used across different interceptors to check if given string matches one of the accepted patterns</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>org.apache.struts2.util.ContentTypeMatcher</td>
|
||||
* <td>struts.contentTypeMatcher</td>
|
||||
* <td>singleton</td>
|
||||
* <td>Matches content type of uploaded files (since 2.3.22)</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <!-- END SNIPPET: extensionPoints -->
|
||||
@@ -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);
|
||||
|
||||
@@ -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<String> allowedTypesSet = Collections.emptySet();
|
||||
protected Set<String> 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 extends Object> {
|
||||
|
||||
E compilePattern(String data);
|
||||
|
||||
boolean match(Map<String,String> map, String data, E expr);
|
||||
|
||||
}
|
||||
@@ -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<int[]> {
|
||||
|
||||
private PatternMatcher<int[]> matcher = new WildcardHelper();
|
||||
|
||||
public int[] compilePattern(String data) {
|
||||
return matcher.compilePattern(data);
|
||||
}
|
||||
|
||||
public boolean match(Map<String, String> map, String data, int[] expr) {
|
||||
return matcher.match(map, data, expr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,6 +74,8 @@
|
||||
<bean type="com.opensymphony.xwork2.util.PatternMatcher" name="namedVariable" class="com.opensymphony.xwork2.util.NamedVariablePatternMatcher"/>
|
||||
<bean type="com.opensymphony.xwork2.util.PatternMatcher" name="regex" class="org.apache.struts2.util.RegexPatternMatcher"/>
|
||||
|
||||
<bean type="org.apache.struts2.util.ContentTypeMatcher" name="struts" class="org.apache.struts2.util.DefaultContentTypeMatcher"/>
|
||||
|
||||
<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="struts" class="org.apache.struts2.dispatcher.mapper.DefaultActionMapper" />
|
||||
<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="composite" class="org.apache.struts2.dispatcher.mapper.CompositeActionMapper" />
|
||||
<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="restful" class="org.apache.struts2.dispatcher.mapper.RestfulActionMapper" />
|
||||
|
||||
Reference in New Issue
Block a user