美文网首页
sping filter urlPatterns 检查逻辑

sping filter urlPatterns 检查逻辑

作者: youpd | 来源:发表于2021-05-20 13:46 被阅读0次

sping filter urlPatterns 检查逻辑
org.apache.catalina.core.ApplicationFilterFactory#matchFiltersURL(java.lang.String, java.lang.String)

private static boolean matchFiltersURL(String testPath, String requestPath) {

        if (testPath == null)
            return false;

        // Case 1 - Exact Match 如果访问对的路径相同则加入过滤器
        if (testPath.equals(requestPath))
            return true;

        // Case 2 - Path Match ("/.../*")如果访问的路径是/*
        if (testPath.equals("/*"))
            return true;
        if (testPath.endsWith("/*")) {
            if (testPath.regionMatches(0, requestPath, 0,
                                       testPath.length() - 2)) {
                if (requestPath.length() == (testPath.length() - 2)) {
                    return true;
                } else if ('/' == requestPath.charAt(testPath.length() - 2)) {
                    return true;
                }
            }
            return false;
        }

        // Case 3 - Extension Match
        if (testPath.startsWith("*.")) {
            int slash = requestPath.lastIndexOf('/');
            int period = requestPath.lastIndexOf('.');
            if ((slash >= 0) && (period > slash)
                && (period != requestPath.length() - 1)
                && ((requestPath.length() - period)
                    == (testPath.length() - 1))) {
                return testPath.regionMatches(2, requestPath, period + 1,
                                               testPath.length() - 2);
            }
        }

        // Case 4 - "Default" Match
        return false; // NOTE - Not relevant for selecting filters

    }

相关文章

网友评论

      本文标题:sping filter urlPatterns 检查逻辑

      本文链接:https://www.haomeiwen.com/subject/hkbvjltx.html