diff --git a/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java b/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java index 6d81e0231e..e216108650 100644 --- a/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java +++ b/web/src/main/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolver.java @@ -125,7 +125,7 @@ public FilterChain getChain(ServletRequest request, ServletResponse response, Fi log.trace("Matched path pattern [{}] for requestURI [{}]. " + "Utilizing corresponding filter chain...", pathPattern, Encode.forHtml(requestURINoTrailingSlash)); } - return filterChainManager.proxy(originalChain, requestURINoTrailingSlash); + return filterChainManager.proxy(originalChain, pathPattern); } } } diff --git a/web/src/test/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolverTest.java b/web/src/test/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolverTest.java index db4de61e2d..76bff556ce 100644 --- a/web/src/test/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolverTest.java +++ b/web/src/test/java/org/apache/shiro/web/filter/mgt/PathMatchingFilterChainResolverTest.java @@ -255,4 +255,44 @@ public void testMultipleChainsPathEndsWithSlash() { FilterChain resolved = resolver.getChain(request, response, chain); assertThat(resolved, notNullValue()); } + + /** + * Test asserting SHIRO-825. + */ + @Test + public void testGetChainWhenPathEndsWithSlash() { + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + FilterChain chain = mock(FilterChain.class); + + //ensure at least one chain is defined: + resolver.getFilterChainManager().addToChain("/resource/*/book", "authcBasic"); + + when(request.getServletPath()).thenReturn(""); + when(request.getPathInfo()).thenReturn("/resource/123/book/"); + + FilterChain resolved = resolver.getChain(request, response, chain); + assertNotNull(resolved); + verify(request).getServletPath(); + } + + /** + * Test asserting SHIRO-825. + */ + @Test + public void testGetChainWhenPathDoesNotEndWithSlash() { + HttpServletRequest request = mock(HttpServletRequest.class); + HttpServletResponse response = mock(HttpServletResponse.class); + FilterChain chain = mock(FilterChain.class); + + //ensure at least one chain is defined: + resolver.getFilterChainManager().addToChain("/resource/*/book", "authcBasic"); + + when(request.getServletPath()).thenReturn(""); + when(request.getPathInfo()).thenReturn("/resource/123/book"); + + FilterChain resolved = resolver.getChain(request, response, chain); + assertNotNull(resolved); + verify(request).getServletPath(); + } }