use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.
the class FilterConfigTest method testSimple.
@Test
public void testSimple() throws Exception {
FilterChainResolver resolver = setupResolver();
HttpServletResponse response = createNiceMock(HttpServletResponse.class);
FilterChain chain = createNiceMock(FilterChain.class);
HttpServletRequest request = createMockRequest("/index.html");
FilterChain resolved = resolver.getChain(request, response, chain);
assertNotNull(resolved);
verify(request);
}
use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.
the class GuiceShiroFilterTest method testConstructor.
@Test
public void testConstructor() {
WebSecurityManager securityManager = createMock(WebSecurityManager.class);
FilterChainResolver filterChainResolver = createMock(FilterChainResolver.class);
GuiceShiroFilter underTest = new GuiceShiroFilter(securityManager, filterChainResolver);
assertSame(securityManager, underTest.getSecurityManager());
assertSame(filterChainResolver, underTest.getFilterChainResolver());
}
use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.
the class ShiroWebModuleTest method testAddFilterChainGuice3Only.
/**
* @since 1.4
*/
@Test
public void testAddFilterChainGuice3Only() {
Assume.assumeTrue("This test only runs agains Guice 3.x", ShiroWebModule.isGuiceVersion3());
final ShiroModuleTest.MockRealm mockRealm = createMock(ShiroModuleTest.MockRealm.class);
ServletContext servletContext = createMock(ServletContext.class);
HttpServletRequest request = createMock(HttpServletRequest.class);
servletContext.setAttribute(eq(EnvironmentLoader.ENVIRONMENT_ATTRIBUTE_KEY), EasyMock.anyObject());
expect(request.getAttribute("javax.servlet.include.context_path")).andReturn("").anyTimes();
expect(request.getCharacterEncoding()).andReturn("UTF-8").anyTimes();
expect(request.getAttribute("javax.servlet.include.request_uri")).andReturn("/test_authc");
expect(request.getAttribute("javax.servlet.include.request_uri")).andReturn("/test_custom_filter");
expect(request.getAttribute("javax.servlet.include.request_uri")).andReturn("/test_perms");
expect(request.getAttribute("javax.servlet.include.request_uri")).andReturn("/multiple_configs");
replay(servletContext, request);
Injector injector = Guice.createInjector(new ShiroWebModule(servletContext) {
@Override
protected void configureShiroWeb() {
bindRealm().to(ShiroModuleTest.MockRealm.class);
expose(FilterChainResolver.class);
this.addFilterChain("/test_authc/**", AUTHC);
this.addFilterChain("/test_custom_filter/**", Key.get(CustomFilter.class));
this.addFilterChain("/test_perms/**", config(PERMS, "remote:invoke:lan,wan"));
this.addFilterChain("/multiple_configs/**", AUTHC, config(ROLES, "b2bClient"), config(PERMS, "remote:invoke:lan,wan"));
}
@Provides
public ShiroModuleTest.MockRealm createRealm() {
return mockRealm;
}
});
FilterChainResolver resolver = injector.getInstance(FilterChainResolver.class);
assertThat(resolver, instanceOf(SimpleFilterChainResolver.class));
SimpleFilterChainResolver simpleFilterChainResolver = (SimpleFilterChainResolver) resolver;
// test the /test_authc resource
FilterChain filterChain = simpleFilterChainResolver.getChain(request, null, null);
assertThat(filterChain, instanceOf(SimpleFilterChain.class));
Filter nextFilter = getNextFilter((SimpleFilterChain) filterChain);
assertThat(nextFilter, instanceOf(FormAuthenticationFilter.class));
// test the /test_custom_filter resource
filterChain = simpleFilterChainResolver.getChain(request, null, null);
assertThat(filterChain, instanceOf(SimpleFilterChain.class));
nextFilter = getNextFilter((SimpleFilterChain) filterChain);
assertThat(nextFilter, instanceOf(CustomFilter.class));
// test the /test_perms resource
filterChain = simpleFilterChainResolver.getChain(request, null, null);
assertThat(filterChain, instanceOf(SimpleFilterChain.class));
nextFilter = getNextFilter((SimpleFilterChain) filterChain);
assertThat(nextFilter, instanceOf(PermissionsAuthorizationFilter.class));
// test the /multiple_configs resource
filterChain = simpleFilterChainResolver.getChain(request, null, null);
assertThat(filterChain, instanceOf(SimpleFilterChain.class));
assertThat(getNextFilter((SimpleFilterChain) filterChain), instanceOf(FormAuthenticationFilter.class));
assertThat(getNextFilter((SimpleFilterChain) filterChain), instanceOf(RolesAuthorizationFilter.class));
assertThat(getNextFilter((SimpleFilterChain) filterChain), instanceOf(PermissionsAuthorizationFilter.class));
verify(servletContext, request);
}
use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.
the class IniFilterChainResolverFactory method createInstance.
protected FilterChainResolver createInstance(Ini ini) {
FilterChainResolver filterChainResolver = createDefaultInstance();
if (filterChainResolver instanceof PathMatchingFilterChainResolver) {
PathMatchingFilterChainResolver resolver = (PathMatchingFilterChainResolver) filterChainResolver;
FilterChainManager manager = resolver.getFilterChainManager();
buildChains(manager, ini);
}
return filterChainResolver;
}
Aggregations