public static boolean applyMethod()

in core/src/main/java/org/apache/struts2/interceptor/MethodFilterInterceptorUtil.java [53:123]


    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.isEmpty()) ) {
            if (excludeMethods.contains(method) && !includeMethods.contains(method)) {
                return false;
            }
        }

        // test the methods using pattern matching
        WildcardHelper wildcard = new WildcardHelper();
        String methodCopy = requireNonNullElse(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.isEmpty() || includeMethods.contains(method) || includeMethods.contains("*");
    }