Adds support to define allowed methods as regex

This commit is contained in:
Lukasz Lenart
2015-09-04 09:04:37 +02:00
parent e4fc8528b8
commit e38d4657c6
3 changed files with 19 additions and 9 deletions
@@ -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());
}
@@ -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;