/** * Returns <code>true</code> if the <code>path</code> matches the specified <code>pattern</code> string, * <code>false</code> otherwise. * <p/> * Simply delegates to * <b><code>this.pathMatcher.{@link PatternMatcher#matches(String, String) matches(pattern,path)}</code></b>, * but can be overridden by subclasses for custom matching behavior. * * @param pattern the pattern to match against * @param path the value to match with the specified <code>pattern</code> * @return <code>true</code> if the <code>path</code> matches the specified <code>pattern</code> string, * <code>false</code> otherwise. */ protected boolean pathsMatch(String pattern, String path) { return pathMatcher.matches(pattern, path); }
/** * Returns {@code true} if an incoming request path (the {@code path} argument) * matches a configured filter chain path (the {@code pattern} argument), {@code false} otherwise. * <p/> * Simply delegates to * <b><code>{@link #getPathMatcher() getPathMatcher()}.{@link org.apache.shiro.util.PatternMatcher#matches(String, String) matches(pattern,path)}</code></b>. * Subclass implementors should think carefully before overriding this method, as typically a custom * {@code PathMatcher} should be configured for custom path matching behavior instead. Favor OO composition * rather than inheritance to limit your exposure to Shiro implementation details which may change over time. * * @param pattern the pattern to match against * @param path the value to match with the specified {@code pattern} * @return {@code true} if the request {@code path} matches the specified filter chain url {@code pattern}, * {@code false} otherwise. */ protected boolean pathMatches(String pattern, String path) { PatternMatcher pathMatcher = getPathMatcher(); return pathMatcher.matches(pattern, path); }
public FilterChain getChain(ServletRequest request, ServletResponse response, final FilterChain originalChain) { String path = WebUtils.getPathWithinApplication(WebUtils.toHttp(request)); for (final String pathPattern : chains.keySet()) { if (patternMatcher.matches(pathPattern, path)) { final Iterator<Key<? extends Filter>> chain = Arrays.asList(chains.get(pathPattern)).iterator(); return new SimpleFilterChain(originalChain, new Iterator<Filter>() { public boolean hasNext() { return chain.hasNext(); } public Filter next() { return injector.getInstance(chain.next()); } public void remove() { throw new UnsupportedOperationException(); } }); } } return null; }
@Test public void testSimplePattern() { PatternMatcher pm = new RegExPatternMatcher(); String pattern = "a*b"; String test = "aaaaaaab"; //not necessary for the test, but Idea performs auto validation when it sees this: Pattern.compile(pattern); assertTrue(pm.matches(pattern, test)); }
expect(patternMatcher.matches(chainOne, "/mychain")).andReturn(false); expect(patternMatcher.matches(chainTwo, "/mychain")).andReturn(true); expect(patternMatcher.matches(chainOne, "/nochain")).andReturn(false); expect(patternMatcher.matches(chainTwo, "/nochain")).andReturn(false); expect(patternMatcher.matches(chainThree, "/nochain")).andReturn(false);
protected boolean pathMatches(String pattern, String path) { return pathMatcher.matches(pattern, path); } }
public FilterChain getChain(ServletRequest request, ServletResponse response, final FilterChain originalChain) { String path = WebUtils.getPathWithinApplication(WebUtils.toHttp(request)); for (final String pathPattern : chains.keySet()) { if (patternMatcher.matches(pathPattern, path)) { final Iterator<Key<? extends Filter>> chain = Arrays.asList(chains.get(pathPattern)).iterator(); return new SimpleFilterChain(originalChain, new Iterator<Filter>() { public boolean hasNext() { return chain.hasNext(); } public Filter next() { return injector.getInstance(chain.next()); } public void remove() { throw new UnsupportedOperationException(); } }); } } return null; }