Java Code Examples for org.apache.shiro.web.filter.mgt.FilterChainManager#proxy()
The following examples show how to use
org.apache.shiro.web.filter.mgt.FilterChainManager#proxy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IamPathMatchingFilterChainResolver.java From super-cloudops with Apache License 2.0 | 5 votes |
/** * Follow the Maximum Matching Principle <br/> * {@link org.springframework.web.servlet.handler.AbstractUrlHandlerMapping#lookupHandler} */ @Override public FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain) { FilterChainManager chainManager = getFilterChainManager(); state(chainManager.hasChains(), "Shiro filter chain must be implemented"); // Current request URI String requestURI = getPathWithinApplication(request); // Candidate matching pattern list. List<String> candidateMatchingPatterns = new ArrayList<>(4); /* * the 'chain names' in this implementation are actually path patterns * defined by the user. We just use them as the chain name for the * FilterChainManager's requirements */ for (String registeredPattern : chainManager.getChainNames()) { if (pathMatches(registeredPattern, requestURI)) { log.trace("Matched path pattern:[{}] for requestURI:[{}]. Utilizing corresponding filter chain...", registeredPattern, requestURI); candidateMatchingPatterns.add(registeredPattern); } } Collections.sort(candidateMatchingPatterns, new AntPatternComparator(requestURI)); String bestMatch = candidateMatchingPatterns.get(0); // Best return chainManager.proxy(originalChain, bestMatch); }
Example 2
Source File: RestPathMatchingFilterChainResolver.java From Shiro-Action with MIT License | 5 votes |
@Override public FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain) { FilterChainManager filterChainManager = getFilterChainManager(); if (!filterChainManager.hasChains()) { return null; } String requestURI = getPathWithinApplication(request); // the 'chain names' in this implementation are actually path patterns defined by the user. We just use them // as the chain name for the FilterChainManager's requirements for (String pathPattern : filterChainManager.getChainNames()) { String[] pathPatternArray = pathPattern.split("=="); boolean httpMethodMatchFlag = true; if (pathPatternArray.length > 1) { httpMethodMatchFlag = pathPatternArray[1].equals(WebHelper.getRequestHTTPMethod()); } // 只用过滤器链的 URL 部分与请求的 URL 进行匹配 if (pathMatches(pathPatternArray[0], requestURI) && httpMethodMatchFlag) { if (log.isTraceEnabled()) { log.trace("Matched path pattern [" + pathPattern + "] for requestURI [" + requestURI + "]. " + "Utilizing corresponding filter chain..."); } return filterChainManager.proxy(originalChain, pathPattern); } } return null; }
Example 3
Source File: RestPathMatchingFilterChainResolver.java From bootshiro with MIT License | 4 votes |
/** * description TODO 重写filterChain匹配 * * @param request 1 * @param response 2 * @param originalChain 3 * @return javax.servlet.FilterChain */ @Override public FilterChain getChain(ServletRequest request, ServletResponse response, FilterChain originalChain) { FilterChainManager filterChainManager = this.getFilterChainManager(); if (!filterChainManager.hasChains()) { return null; } else { String requestURI = this.getPathWithinApplication(request); if (requestURI != null && requestURI.endsWith(DEFAULT_PATH_SEPARATOR)) { requestURI = requestURI.substring(0, requestURI.length() - 1); } Iterator var6 = filterChainManager.getChainNames().iterator(); String pathPattern; boolean flag = true; String[] strings = null; do { if (!var6.hasNext()) { return null; } pathPattern = (String)var6.next(); strings = pathPattern.split("=="); if (strings.length == NUM_2) { // 分割出url+httpMethod,判断httpMethod和request请求的method是否一致,不一致直接false if (WebUtils.toHttp(request).getMethod().toUpperCase().equals(strings[1].toUpperCase())) { flag = false; } else { flag = true; } } else { flag = false; } pathPattern = strings[0]; if (pathPattern != null && pathPattern.endsWith(DEFAULT_PATH_SEPARATOR)) { pathPattern = pathPattern.substring(0, pathPattern.length() -1); } } while(!this.pathMatches(pathPattern, requestURI) || flag); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Matched path pattern [" + pathPattern + "] for requestURI [" + requestURI + "]. Utilizing corresponding filter chain..."); } if (strings.length == NUM_2) { pathPattern = pathPattern.concat("==").concat(WebUtils.toHttp(request).getMethod().toUpperCase()); } return filterChainManager.proxy(originalChain, pathPattern); } }