Search in sources :

Example 11 with FilterChainResolver

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test) ShiroModuleTest(org.apache.shiro.guice.ShiroModuleTest)

Example 12 with FilterChainResolver

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());
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) Test(org.junit.Test)

Example 13 with FilterChainResolver

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);
}
Also used : FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) FormAuthenticationFilter(org.apache.shiro.web.filter.authc.FormAuthenticationFilter) FilterChain(javax.servlet.FilterChain) Provides(com.google.inject.Provides) HttpServletRequest(javax.servlet.http.HttpServletRequest) BasicHttpAuthenticationFilter(org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter) RolesAuthorizationFilter(org.apache.shiro.web.filter.authz.RolesAuthorizationFilter) Filter(javax.servlet.Filter) PermissionsAuthorizationFilter(org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter) FormAuthenticationFilter(org.apache.shiro.web.filter.authc.FormAuthenticationFilter) Injector(com.google.inject.Injector) ServletContext(javax.servlet.ServletContext) RolesAuthorizationFilter(org.apache.shiro.web.filter.authz.RolesAuthorizationFilter) ShiroModuleTest(org.apache.shiro.guice.ShiroModuleTest) PermissionsAuthorizationFilter(org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter) Test(org.junit.Test) ShiroModuleTest(org.apache.shiro.guice.ShiroModuleTest)

Example 14 with FilterChainResolver

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;
}
Also used : FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) PathMatchingFilterChainResolver(org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver) FilterChainManager(org.apache.shiro.web.filter.mgt.FilterChainManager) PathMatchingFilterChainResolver(org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver)

Aggregations

FilterChainResolver (org.apache.shiro.web.filter.mgt.FilterChainResolver)14 Test (org.junit.Test)7 FilterChain (javax.servlet.FilterChain)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 ShiroModuleTest (org.apache.shiro.guice.ShiroModuleTest)4 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)4 Injector (com.google.inject.Injector)3 Filter (javax.servlet.Filter)3 ServletContext (javax.servlet.ServletContext)3 Provides (com.google.inject.Provides)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Ini (org.apache.shiro.config.Ini)2 IniFilterChainResolverFactory (org.apache.shiro.web.config.IniFilterChainResolverFactory)2 BasicHttpAuthenticationFilter (org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter)2 FormAuthenticationFilter (org.apache.shiro.web.filter.authc.FormAuthenticationFilter)2 PermissionsAuthorizationFilter (org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter)2 RolesAuthorizationFilter (org.apache.shiro.web.filter.authz.RolesAuthorizationFilter)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 IniFactorySupport (org.apache.shiro.config.IniFactorySupport)1