mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
Adds support to define allowed methods as regex
This commit is contained in:
@@ -43,6 +43,7 @@ public class ActionConfig extends Located implements Serializable {
|
||||
|
||||
public static final String DEFAULT_METHOD = "execute";
|
||||
public static final String WILDCARD = "*";
|
||||
public static final String REGEX_WILDCARD = "regex:.*";
|
||||
|
||||
protected List<InterceptorMapping> interceptors; // a list of interceptorMapping Objects eg. List<InterceptorMapping>
|
||||
protected Map<String,String> params;
|
||||
|
||||
@@ -32,8 +32,11 @@ public class AllowedMethods {
|
||||
ret.append(c);
|
||||
}
|
||||
}
|
||||
if (isPattern) {
|
||||
if (isPattern && !method.startsWith("regex:")) {
|
||||
return new PatternAllowedMethod(ret.toString(), method);
|
||||
} else if (method.startsWith("regex:")) {
|
||||
String pattern = method.substring(method.indexOf(":") + 1);
|
||||
return new PatternAllowedMethod(pattern, method);
|
||||
} else {
|
||||
return new LiteralAllowedMethod(ret.toString());
|
||||
}
|
||||
|
||||
+14
-8
@@ -845,17 +845,23 @@ public class XmlConfigurationProvider implements ConfigurationProvider {
|
||||
protected Set<String> buildAllowedMethods(Element element, PackageConfig.Builder packageContext) {
|
||||
NodeList allowedMethodsEls = element.getElementsByTagName("allowed-methods");
|
||||
|
||||
Set<String> allowedMethods = packageContext.getGlobalAllowedMethods();
|
||||
Set<String> allowedMethods;
|
||||
if (packageContext.isStrictMethodInvocation()) {
|
||||
allowedMethods = packageContext.getGlobalAllowedMethods();
|
||||
|
||||
if (allowedMethodsEls.getLength() > 0) {
|
||||
allowedMethods = new HashSet<>();
|
||||
Node n = allowedMethodsEls.item(0).getFirstChild();
|
||||
if (n != null) {
|
||||
String s = n.getNodeValue().trim();
|
||||
if (s.length() > 0) {
|
||||
allowedMethods = TextParseUtil.commaDelimitedStringToSet(s);
|
||||
if (allowedMethodsEls.getLength() > 0) {
|
||||
allowedMethods = new HashSet<>();
|
||||
Node n = allowedMethodsEls.item(0).getFirstChild();
|
||||
if (n != null) {
|
||||
String s = n.getNodeValue().trim();
|
||||
if (s.length() > 0) {
|
||||
allowedMethods = TextParseUtil.commaDelimitedStringToSet(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
allowedMethods = new HashSet<>();
|
||||
allowedMethods.add(ActionConfig.REGEX_WILDCARD);
|
||||
}
|
||||
|
||||
return allowedMethods;
|
||||
|
||||
Reference in New Issue
Block a user