mirror of
https://github.com/apache/struts.git
synced 2026-08-05 22:56:59 +00:00
WW-3714 Deprecate and migrate AbstractInterceptor and MethodFilterInterceptor
This commit is contained in:
@@ -21,41 +21,23 @@ package com.opensymphony.xwork2.interceptor;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
|
||||
/**
|
||||
* Provides default implementations of optional lifecycle methods
|
||||
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.AbstractInterceptor} instead.
|
||||
*/
|
||||
public abstract class AbstractInterceptor implements ConditionalInterceptor {
|
||||
|
||||
private boolean disabled;
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
*/
|
||||
public void init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
*/
|
||||
public void destroy() {
|
||||
}
|
||||
@Deprecated
|
||||
public abstract class AbstractInterceptor extends org.apache.struts2.interceptor.AbstractInterceptor implements ConditionalInterceptor {
|
||||
|
||||
/**
|
||||
* Override to handle interception
|
||||
*/
|
||||
public abstract String intercept(ActionInvocation invocation) throws Exception;
|
||||
|
||||
/**
|
||||
* Allows to skip executing a given interceptor, just define {@code <param name="disabled">true</param>}
|
||||
* or use other way to override interceptor's parameters, see
|
||||
* <a href="https://struts.apache.org/core-developers/interceptors#interceptor-parameter-overriding">docs</a>.
|
||||
* @param disable if set to true, execution of a given interceptor will be skipped.
|
||||
*/
|
||||
public void setDisabled(String disable) {
|
||||
this.disabled = Boolean.parseBoolean(disable);
|
||||
@Override
|
||||
public String intercept(org.apache.struts2.ActionInvocation invocation) throws Exception {
|
||||
return intercept(ActionInvocation.adapt(invocation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldIntercept(ActionInvocation invocation) {
|
||||
return !this.disabled;
|
||||
return shouldIntercept((org.apache.struts2.ActionInvocation) invocation);
|
||||
}
|
||||
}
|
||||
|
||||
+24
-21
@@ -31,56 +31,59 @@ import java.util.Set;
|
||||
*
|
||||
* <p>
|
||||
* MethodFilterInterceptor is an abstract <code>Interceptor</code> used as
|
||||
* a base class for interceptors that will filter execution based on method
|
||||
* a base class for interceptors that will filter execution based on method
|
||||
* names according to specified included/excluded method lists.
|
||||
*
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* Settable parameters are as follows:
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>excludeMethods - method names to be excluded from interceptor processing</li>
|
||||
* <li>includeMethods - method names to be included in interceptor processing</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* <b>NOTE:</b> If method name are available in both includeMethods and
|
||||
* excludeMethods, it will be considered as an included method:
|
||||
*
|
||||
* <b>NOTE:</b> If method name are available in both includeMethods and
|
||||
* excludeMethods, it will be considered as an included method:
|
||||
* includeMethods takes precedence over excludeMethods.
|
||||
*
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* Interceptors that extends this capability include:
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
* <li>TokenInterceptor</li>
|
||||
* <li>TokenSessionStoreInterceptor</li>
|
||||
* <li>DefaultWorkflowInterceptor</li>
|
||||
* <li>ValidationInterceptor</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* <!-- END SNIPPET: javadoc -->
|
||||
*
|
||||
*
|
||||
* @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
|
||||
* @author Rainer Hermanns
|
||||
*
|
||||
*
|
||||
* @see org.apache.struts2.interceptor.TokenInterceptor
|
||||
* @see org.apache.struts2.interceptor.TokenSessionStoreInterceptor
|
||||
* @see com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor
|
||||
* @see com.opensymphony.xwork2.validator.ValidationInterceptor
|
||||
*
|
||||
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.MethodFilterInterceptor} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class MethodFilterInterceptor extends AbstractInterceptor {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(MethodFilterInterceptor.class);
|
||||
|
||||
|
||||
protected Set<String> excludeMethods = Collections.emptySet();
|
||||
protected Set<String> includeMethods = Collections.emptySet();
|
||||
|
||||
public void setExcludeMethods(String excludeMethods) {
|
||||
this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getExcludeMethodsSet() {
|
||||
return excludeMethods;
|
||||
}
|
||||
@@ -88,7 +91,7 @@ public abstract class MethodFilterInterceptor extends AbstractInterceptor {
|
||||
public void setIncludeMethods(String includeMethods) {
|
||||
this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getIncludeMethodsSet() {
|
||||
return includeMethods;
|
||||
}
|
||||
@@ -97,7 +100,7 @@ public abstract class MethodFilterInterceptor extends AbstractInterceptor {
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
if (applyInterceptor(invocation)) {
|
||||
return doIntercept(invocation);
|
||||
}
|
||||
}
|
||||
return invocation.invoke();
|
||||
}
|
||||
|
||||
@@ -110,14 +113,14 @@ public abstract class MethodFilterInterceptor extends AbstractInterceptor {
|
||||
}
|
||||
return applyMethod;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Subclasses must override to implement the interceptor logic.
|
||||
*
|
||||
*
|
||||
* @param invocation the action invocation
|
||||
* @return the result of invocation
|
||||
* @throws Exception in case of any errors
|
||||
*/
|
||||
protected abstract String doIntercept(ActionInvocation invocation) throws Exception;
|
||||
|
||||
|
||||
}
|
||||
|
||||
+3
-125
@@ -18,131 +18,9 @@
|
||||
*/
|
||||
package com.opensymphony.xwork2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.WildcardHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Utility class contains common methods used by
|
||||
* {@link com.opensymphony.xwork2.interceptor.MethodFilterInterceptor}.
|
||||
*
|
||||
* @author tm_jee
|
||||
* @deprecated since 6.7.0, use {@link org.apache.struts2.interceptor.MethodFilterInterceptorUtil} instead.
|
||||
*/
|
||||
public class MethodFilterInterceptorUtil {
|
||||
|
||||
/**
|
||||
* Static method to decide if the specified <code>method</code> should be
|
||||
* apply (not filtered) depending on the set of <code>excludeMethods</code> and
|
||||
* <code>includeMethods</code>.
|
||||
*
|
||||
* <ul>
|
||||
* <li>
|
||||
* <code>includeMethods</code> takes precedence over <code>excludeMethods</code>
|
||||
* </li>
|
||||
* </ul>
|
||||
* <b>Note:</b> Supports wildcard listings in includeMethods/excludeMethods
|
||||
*
|
||||
* @param excludeMethods list of methods to exclude.
|
||||
* @param includeMethods list of methods to include.
|
||||
* @param method the specified method to check
|
||||
* @return <tt>true</tt> if the method should be applied.
|
||||
*/
|
||||
public static boolean applyMethod(Set<String> excludeMethods, Set<String> includeMethods, String method) {
|
||||
|
||||
// quick check to see if any actual pattern matching is needed
|
||||
boolean needsPatternMatch = false;
|
||||
for (String includeMethod : includeMethods) {
|
||||
if (!"*".equals(includeMethod) && includeMethod.contains("*")) {
|
||||
needsPatternMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (String excludeMethod : excludeMethods) {
|
||||
if (!"*".equals(excludeMethod) && excludeMethod.contains("*")) {
|
||||
needsPatternMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// this section will try to honor the original logic, while
|
||||
// still allowing for wildcards later
|
||||
if (!needsPatternMatch && (includeMethods.contains("*") || includeMethods.size() == 0) ) {
|
||||
if (excludeMethods != null
|
||||
&& excludeMethods.contains(method)
|
||||
&& !includeMethods.contains(method) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// test the methods using pattern matching
|
||||
WildcardHelper wildcard = new WildcardHelper();
|
||||
String methodCopy ;
|
||||
if (method == null ) { // no method specified
|
||||
methodCopy = "";
|
||||
}
|
||||
else {
|
||||
methodCopy = new String(method);
|
||||
}
|
||||
for (String pattern : includeMethods) {
|
||||
if (pattern.contains("*")) {
|
||||
int[] compiledPattern = wildcard.compilePattern(pattern);
|
||||
HashMap<String, String> matchedPatterns = new HashMap<>();
|
||||
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
|
||||
if (matches) {
|
||||
return true; // run it, includeMethods takes precedence
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pattern.equals(methodCopy)) {
|
||||
return true; // run it, includeMethods takes precedence
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excludeMethods.contains("*") ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// CHECK ME: Previous implementation used include method
|
||||
for ( String pattern : excludeMethods) {
|
||||
if (pattern.contains("*")) {
|
||||
int[] compiledPattern = wildcard.compilePattern(pattern);
|
||||
HashMap<String, String> matchedPatterns = new HashMap<>();
|
||||
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
|
||||
if (matches) {
|
||||
// if found, and wasn't included earlier, don't run it
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pattern.equals(methodCopy)) {
|
||||
// if found, and wasn't included earlier, don't run it
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// default fall-back from before changes
|
||||
return includeMethods.size() == 0 || includeMethods.contains(method) || includeMethods.contains("*");
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #applyMethod(Set, Set, String)}, except that <code>excludeMethods</code>
|
||||
* and <code>includeMethods</code> are supplied as comma separated string.
|
||||
*
|
||||
* @param excludeMethods comma seperated string of methods to exclude.
|
||||
* @param includeMethods comma seperated string of methods to include.
|
||||
* @param method the specified method to check
|
||||
* @return <tt>true</tt> if the method should be applied.
|
||||
*/
|
||||
public static boolean applyMethod(String excludeMethods, String includeMethods, String method) {
|
||||
Set<String> includeMethodsSet = TextParseUtil.commaDelimitedStringToSet(includeMethods == null? "" : includeMethods);
|
||||
Set<String> excludeMethodsSet = TextParseUtil.commaDelimitedStringToSet(excludeMethods == null? "" : excludeMethods);
|
||||
|
||||
return applyMethod(excludeMethodsSet, includeMethodsSet, method);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public class MethodFilterInterceptorUtil extends org.apache.struts2.interceptor.MethodFilterInterceptorUtil {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import org.apache.struts2.ActionInvocation;
|
||||
|
||||
/**
|
||||
* Provides default implementations of optional lifecycle methods
|
||||
*/
|
||||
public abstract class AbstractInterceptor implements ConditionalInterceptor {
|
||||
|
||||
private boolean disabled;
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
*/
|
||||
public void init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing
|
||||
*/
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to handle interception
|
||||
*/
|
||||
public abstract String intercept(ActionInvocation invocation) throws Exception;
|
||||
|
||||
/**
|
||||
* Allows to skip executing a given interceptor, just define {@code <param name="disabled">true</param>}
|
||||
* or use other way to override interceptor's parameters, see
|
||||
* <a href="https://struts.apache.org/core-developers/interceptors#interceptor-parameter-overriding">docs</a>.
|
||||
* @param disable if set to true, execution of a given interceptor will be skipped.
|
||||
*/
|
||||
public void setDisabled(String disable) {
|
||||
this.disabled = Boolean.parseBoolean(disable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldIntercept(ActionInvocation invocation) {
|
||||
return !this.disabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ActionInvocation;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: javadoc -->
|
||||
*
|
||||
* <p>
|
||||
* MethodFilterInterceptor is an abstract <code>Interceptor</code> used as
|
||||
* a base class for interceptors that will filter execution based on method
|
||||
* names according to specified included/excluded method lists.
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* Settable parameters are as follows:
|
||||
*
|
||||
* <ul>
|
||||
* <li>excludeMethods - method names to be excluded from interceptor processing</li>
|
||||
* <li>includeMethods - method names to be included in interceptor processing</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
*
|
||||
* <b>NOTE:</b> If method name are available in both includeMethods and
|
||||
* excludeMethods, it will be considered as an included method:
|
||||
* includeMethods takes precedence over excludeMethods.
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* Interceptors that extends this capability include:
|
||||
*
|
||||
* <ul>
|
||||
* <li>TokenInterceptor</li>
|
||||
* <li>TokenSessionStoreInterceptor</li>
|
||||
* <li>DefaultWorkflowInterceptor</li>
|
||||
* <li>ValidationInterceptor</li>
|
||||
* </ul>
|
||||
*
|
||||
* <!-- END SNIPPET: javadoc -->
|
||||
*
|
||||
* @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
|
||||
* @author Rainer Hermanns
|
||||
*
|
||||
* @see TokenInterceptor
|
||||
* @see TokenSessionStoreInterceptor
|
||||
* @see com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor
|
||||
* @see com.opensymphony.xwork2.validator.ValidationInterceptor
|
||||
*/
|
||||
public abstract class MethodFilterInterceptor extends AbstractInterceptor {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(MethodFilterInterceptor.class);
|
||||
|
||||
protected Set<String> excludeMethods = Collections.emptySet();
|
||||
protected Set<String> includeMethods = Collections.emptySet();
|
||||
|
||||
public void setExcludeMethods(String excludeMethods) {
|
||||
this.excludeMethods = TextParseUtil.commaDelimitedStringToSet(excludeMethods);
|
||||
}
|
||||
|
||||
public Set<String> getExcludeMethodsSet() {
|
||||
return excludeMethods;
|
||||
}
|
||||
|
||||
public void setIncludeMethods(String includeMethods) {
|
||||
this.includeMethods = TextParseUtil.commaDelimitedStringToSet(includeMethods);
|
||||
}
|
||||
|
||||
public Set<String> getIncludeMethodsSet() {
|
||||
return includeMethods;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
if (applyInterceptor(invocation)) {
|
||||
return doIntercept(invocation);
|
||||
}
|
||||
return invocation.invoke();
|
||||
}
|
||||
|
||||
protected boolean applyInterceptor(ActionInvocation invocation) {
|
||||
String method = invocation.getProxy().getMethod();
|
||||
// ValidationInterceptor
|
||||
boolean applyMethod = MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);
|
||||
if (!applyMethod) {
|
||||
LOG.debug("Skipping Interceptor... Method [{}] found in exclude list.", method);
|
||||
}
|
||||
return applyMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must override to implement the interceptor logic.
|
||||
*
|
||||
* @param invocation the action invocation
|
||||
* @return the result of invocation
|
||||
* @throws Exception in case of any errors
|
||||
*/
|
||||
protected abstract String doIntercept(ActionInvocation invocation) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.util.TextParseUtil;
|
||||
import com.opensymphony.xwork2.util.WildcardHelper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Utility class contains common methods used by
|
||||
* {@link MethodFilterInterceptor}.
|
||||
*
|
||||
* @author tm_jee
|
||||
*/
|
||||
public class MethodFilterInterceptorUtil {
|
||||
|
||||
/**
|
||||
* Static method to decide if the specified <code>method</code> should be
|
||||
* apply (not filtered) depending on the set of <code>excludeMethods</code> and
|
||||
* <code>includeMethods</code>.
|
||||
*
|
||||
* <ul>
|
||||
* <li>
|
||||
* <code>includeMethods</code> takes precedence over <code>excludeMethods</code>
|
||||
* </li>
|
||||
* </ul>
|
||||
* <b>Note:</b> Supports wildcard listings in includeMethods/excludeMethods
|
||||
*
|
||||
* @param excludeMethods list of methods to exclude.
|
||||
* @param includeMethods list of methods to include.
|
||||
* @param method the specified method to check
|
||||
* @return <tt>true</tt> if the method should be applied.
|
||||
*/
|
||||
public static boolean applyMethod(Set<String> excludeMethods, Set<String> includeMethods, String method) {
|
||||
|
||||
// quick check to see if any actual pattern matching is needed
|
||||
boolean needsPatternMatch = false;
|
||||
for (String includeMethod : includeMethods) {
|
||||
if (!"*".equals(includeMethod) && includeMethod.contains("*")) {
|
||||
needsPatternMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (String excludeMethod : excludeMethods) {
|
||||
if (!"*".equals(excludeMethod) && excludeMethod.contains("*")) {
|
||||
needsPatternMatch = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// this section will try to honor the original logic, while
|
||||
// still allowing for wildcards later
|
||||
if (!needsPatternMatch && (includeMethods.contains("*") || includeMethods.size() == 0) ) {
|
||||
if (excludeMethods != null
|
||||
&& excludeMethods.contains(method)
|
||||
&& !includeMethods.contains(method) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// test the methods using pattern matching
|
||||
WildcardHelper wildcard = new WildcardHelper();
|
||||
String methodCopy ;
|
||||
if (method == null ) { // no method specified
|
||||
methodCopy = "";
|
||||
}
|
||||
else {
|
||||
methodCopy = new String(method);
|
||||
}
|
||||
for (String pattern : includeMethods) {
|
||||
if (pattern.contains("*")) {
|
||||
int[] compiledPattern = wildcard.compilePattern(pattern);
|
||||
HashMap<String, String> matchedPatterns = new HashMap<>();
|
||||
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
|
||||
if (matches) {
|
||||
return true; // run it, includeMethods takes precedence
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pattern.equals(methodCopy)) {
|
||||
return true; // run it, includeMethods takes precedence
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excludeMethods.contains("*") ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// CHECK ME: Previous implementation used include method
|
||||
for ( String pattern : excludeMethods) {
|
||||
if (pattern.contains("*")) {
|
||||
int[] compiledPattern = wildcard.compilePattern(pattern);
|
||||
HashMap<String, String> matchedPatterns = new HashMap<>();
|
||||
boolean matches = wildcard.match(matchedPatterns, methodCopy, compiledPattern);
|
||||
if (matches) {
|
||||
// if found, and wasn't included earlier, don't run it
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pattern.equals(methodCopy)) {
|
||||
// if found, and wasn't included earlier, don't run it
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// default fall-back from before changes
|
||||
return includeMethods.size() == 0 || includeMethods.contains(method) || includeMethods.contains("*");
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #applyMethod(Set, Set, String)}, except that <code>excludeMethods</code>
|
||||
* and <code>includeMethods</code> are supplied as comma separated string.
|
||||
*
|
||||
* @param excludeMethods comma seperated string of methods to exclude.
|
||||
* @param includeMethods comma seperated string of methods to include.
|
||||
* @param method the specified method to check
|
||||
* @return <tt>true</tt> if the method should be applied.
|
||||
*/
|
||||
public static boolean applyMethod(String excludeMethods, String includeMethods, String method) {
|
||||
Set<String> includeMethodsSet = TextParseUtil.commaDelimitedStringToSet(includeMethods == null? "" : includeMethods);
|
||||
Set<String> excludeMethodsSet = TextParseUtil.commaDelimitedStringToSet(excludeMethods == null? "" : excludeMethods);
|
||||
|
||||
return applyMethod(excludeMethodsSet, includeMethodsSet, method);
|
||||
}
|
||||
|
||||
}
|
||||
+3
@@ -61,6 +61,7 @@ public class ConfigurationProviderOgnlAllowlistTest extends XWorkJUnit4TestCase
|
||||
Class.forName("com.opensymphony.xwork2.mock.MockInterceptor"),
|
||||
Class.forName("com.opensymphony.xwork2.Action"),
|
||||
Class.forName("com.opensymphony.xwork2.interceptor.AbstractInterceptor"),
|
||||
Class.forName("org.apache.struts2.interceptor.AbstractInterceptor"),
|
||||
Class.forName("com.opensymphony.xwork2.Result"),
|
||||
Class.forName("com.opensymphony.xwork2.SimpleAction"),
|
||||
Class.forName("org.apache.struts2.interceptor.Interceptor"),
|
||||
@@ -92,6 +93,7 @@ public class ConfigurationProviderOgnlAllowlistTest extends XWorkJUnit4TestCase
|
||||
Class.forName("com.opensymphony.xwork2.mock.MockInterceptor"),
|
||||
Class.forName("com.opensymphony.xwork2.Action"),
|
||||
Class.forName("com.opensymphony.xwork2.interceptor.AbstractInterceptor"),
|
||||
Class.forName("org.apache.struts2.interceptor.AbstractInterceptor"),
|
||||
Class.forName("com.opensymphony.xwork2.Result"),
|
||||
Class.forName("com.opensymphony.xwork2.SimpleAction"),
|
||||
Class.forName("org.apache.struts2.interceptor.Interceptor"),
|
||||
@@ -123,6 +125,7 @@ public class ConfigurationProviderOgnlAllowlistTest extends XWorkJUnit4TestCase
|
||||
Class.forName("com.opensymphony.xwork2.Validateable"),
|
||||
Class.forName("com.opensymphony.xwork2.Action"),
|
||||
Class.forName("com.opensymphony.xwork2.interceptor.AbstractInterceptor"),
|
||||
Class.forName("org.apache.struts2.interceptor.AbstractInterceptor"),
|
||||
Class.forName("com.opensymphony.xwork2.Result"),
|
||||
Class.forName("org.apache.struts2.interceptor.Interceptor"),
|
||||
Class.forName("org.apache.struts2.interceptor.ConditionalInterceptor"),
|
||||
|
||||
Reference in New Issue
Block a user