Package org.apache.shiro.util

Examples of org.apache.shiro.util.PatternMatcher


        chainMap.put(chainOne, new Key[]{key1a, key1b});
        chainMap.put(chainTwo, new Key[]{key2a, key2b});
        chainMap.put(chainThree, new Key[]{key3a, key3b});

        PatternMatcher patternMatcher = ctrl.createMock(PatternMatcher.class);
        ServletRequest request = ctrl.createMock(HttpServletRequest.class);
        ServletResponse response = ctrl.createMock(HttpServletResponse.class);
        FilterChain originalChain = ctrl.createMock(FilterChain.class);

        expect(request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE)).andReturn("/context");
        expect(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).andReturn("/mychain");

        expect(request.getCharacterEncoding()).andStubReturn(null);

        expect(patternMatcher.matches(chainOne, "/mychain")).andReturn(false);
        expect(patternMatcher.matches(chainTwo, "/mychain")).andReturn(true);

        Filter filter2a = ctrl.createMock(Filter.class);
        Filter filter2b = ctrl.createMock(Filter.class);

        expect((Filter)injector.getInstance(key2a)).andReturn(filter2a);
        filter2a.doFilter(same(request), same(response), anyObject(FilterChain.class));
        expect((Filter)injector.getInstance(key2b)).andReturn(filter2b);
        filter2b.doFilter(same(request), same(response), anyObject(FilterChain.class));
        originalChain.doFilter(request, response);

        ctrl.replay();

        SimpleFilterChainResolver underTest = new SimpleFilterChainResolver(chainMap, injector, patternMatcher);

        FilterChain got = underTest.getChain(request, response, originalChain);

        got.doFilter(request, response);
        got.doFilter(request, response);
        got.doFilter(request, response);

        ctrl.verify();

        ctrl.reset();

        expect(request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE)).andReturn("/context");
        expect(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).andReturn("/nochain");

        expect(request.getCharacterEncoding()).andStubReturn(null);

        expect(patternMatcher.matches(chainOne, "/nochain")).andReturn(false);
        expect(patternMatcher.matches(chainTwo, "/nochain")).andReturn(false);
        expect(patternMatcher.matches(chainThree, "/nochain")).andReturn(false);

        ctrl.replay();

        assertNull("Expected no chain to match, did not get a null value in return.", underTest.getChain(request, response, originalChain));
View Full Code Here


 
  /**
   * 路径匹配
   */
    protected boolean pathMatches(String pattern, ServletRequest request) {
        PatternMatcher pathMatcher = getPathMatcher();
        if( regexPathMatcher )
          pathMatcher = this.regexMatcher;
       
        String path = getPathWithinApplication(request);
        if( request instanceof HttpServletRequest ){
          String queryString = ((HttpServletRequest)request).getQueryString();
          if( regexPathMatcher && !StringUtils.isEmpty(queryString) )
            path += ("?"+queryString);
        }
       
        String regex = pattern;
        if( regexPathMatcher )
          regex = replacePattern(pattern);
       
        try{
          return pathMatcher.matches(regex, path);
        }catch( PatternSyntaxException e ){
          //配置Ant表达式,容错处理
          if( regexPathMatcher )
            return getPathMatcher().matches(pattern,getPathWithinApplication(request));
        }
View Full Code Here

     * @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);
    }
View Full Code Here

        chainMap.put(chainOne, new Key[]{key1a, key1b});
        chainMap.put(chainTwo, new Key[]{key2a, key2b});
        chainMap.put(chainThree, new Key[]{key3a, key3b});

        PatternMatcher patternMatcher = ctrl.createMock(PatternMatcher.class);
        ServletRequest request = ctrl.createMock(HttpServletRequest.class);
        ServletResponse response = ctrl.createMock(HttpServletResponse.class);
        FilterChain originalChain = ctrl.createMock(FilterChain.class);

        expect(request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE)).andReturn("/context");
        expect(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).andReturn("/mychain");

        expect(request.getCharacterEncoding()).andStubReturn(null);

        expect(patternMatcher.matches(chainOne, "/mychain")).andReturn(false);
        expect(patternMatcher.matches(chainTwo, "/mychain")).andReturn(true);

        Filter filter2a = ctrl.createMock(Filter.class);
        Filter filter2b = ctrl.createMock(Filter.class);

        expect(injector.getInstance(key2a)).andReturn(filter2a);
        filter2a.doFilter(same(request), same(response), anyObject(FilterChain.class));
        expect(injector.getInstance(key2b)).andReturn(filter2b);
        filter2b.doFilter(same(request), same(response), anyObject(FilterChain.class));
        originalChain.doFilter(request, response);

        ctrl.replay();

        SimpleFilterChainResolver underTest = new SimpleFilterChainResolver(chainMap, injector, patternMatcher);

        FilterChain got = underTest.getChain(request, response, originalChain);

        got.doFilter(request, response);
        got.doFilter(request, response);
        got.doFilter(request, response);

        ctrl.verify();

        ctrl.reset();

        expect(request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE)).andReturn("/context");
        expect(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).andReturn("/nochain");

        expect(request.getCharacterEncoding()).andStubReturn(null);

        expect(patternMatcher.matches(chainOne, "/nochain")).andReturn(false);
        expect(patternMatcher.matches(chainTwo, "/nochain")).andReturn(false);
        expect(patternMatcher.matches(chainThree, "/nochain")).andReturn(false);

        ctrl.replay();

        assertNull("Expected no chain to match, did not get a null value in return.", underTest.getChain(request, response, originalChain));
View Full Code Here

    @Test
    public void testGet() throws Exception {

        Injector injector = createMock(Injector.class);
        PatternMatcher patternMatcher = createMock(PatternMatcher.class);

        underTest.injector = injector;
        underTest.setPatternMatcher(patternMatcher);

        FilterChainResolver resolver = underTest.get();
View Full Code Here

TOP

Related Classes of org.apache.shiro.util.PatternMatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.