Search in sources :

Example 6 with FilterChainResolver

use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.

the class FilterChainResolverProviderTest method testGet.

@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();
    Field chainsField = SimpleFilterChainResolver.class.getDeclaredField("chains");
    chainsField.setAccessible(true);
    Field injectorField = SimpleFilterChainResolver.class.getDeclaredField("injector");
    injectorField.setAccessible(true);
    Field patternMatcherField = SimpleFilterChainResolver.class.getDeclaredField("patternMatcher");
    patternMatcherField.setAccessible(true);
    assertSame(chains, chainsField.get(resolver));
    assertSame(injector, injectorField.get(resolver));
    assertSame(patternMatcher, patternMatcherField.get(resolver));
}
Also used : Field(java.lang.reflect.Field) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) Injector(com.google.inject.Injector) PatternMatcher(org.apache.shiro.util.PatternMatcher) Test(org.junit.Test)

Example 7 with FilterChainResolver

use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.

the class IniWebEnvironment method configure.

protected void configure() {
    this.objects.clear();
    WebSecurityManager securityManager = createWebSecurityManager();
    setWebSecurityManager(securityManager);
    FilterChainResolver resolver = createFilterChainResolver();
    if (resolver != null) {
        setFilterChainResolver(resolver);
    }
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver)

Example 8 with FilterChainResolver

use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.

the class IniWebEnvironment method createFilterChainResolver.

protected FilterChainResolver createFilterChainResolver() {
    FilterChainResolver resolver = null;
    Ini ini = getIni();
    if (!CollectionUtils.isEmpty(ini)) {
        // only create a resolver if the 'filters' or 'urls' sections are defined:
        Ini.Section urls = ini.getSection(IniFilterChainResolverFactory.URLS);
        Ini.Section filters = ini.getSection(IniFilterChainResolverFactory.FILTERS);
        if (!CollectionUtils.isEmpty(urls) || !CollectionUtils.isEmpty(filters)) {
            // either the urls section or the filters section was defined.  Go ahead and create the resolver:
            Factory<FilterChainResolver> factory = (Factory<FilterChainResolver>) this.objects.get(FILTER_CHAIN_RESOLVER_NAME);
            if (factory instanceof IniFactorySupport) {
                IniFactorySupport iniFactory = (IniFactorySupport) factory;
                iniFactory.setIni(ini);
                iniFactory.setDefaults(this.objects);
            }
            resolver = factory.getInstance();
        }
    }
    return resolver;
}
Also used : FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) Ini(org.apache.shiro.config.Ini) LoggerFactory(org.slf4j.LoggerFactory) WebIniSecurityManagerFactory(org.apache.shiro.web.config.WebIniSecurityManagerFactory) IniFilterChainResolverFactory(org.apache.shiro.web.config.IniFilterChainResolverFactory) IniFactorySupport(org.apache.shiro.config.IniFactorySupport)

Example 9 with FilterChainResolver

use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.

the class IniShiroFilter method applyFilterChainResolver.

protected void applyFilterChainResolver(Ini ini, Map<String, ?> defaults) {
    if (ini == null || ini.isEmpty()) {
        // always used).
        return;
    }
    // only create a resolver if the 'filters' or 'urls' sections are defined:
    Ini.Section urls = ini.getSection(IniFilterChainResolverFactory.URLS);
    Ini.Section filters = ini.getSection(IniFilterChainResolverFactory.FILTERS);
    if ((urls != null && !urls.isEmpty()) || (filters != null && !filters.isEmpty())) {
        // either the urls section or the filters section was defined.  Go ahead and create the resolver
        // and set it:
        IniFilterChainResolverFactory filterChainResolverFactory = new IniFilterChainResolverFactory(ini, defaults);
        filterChainResolverFactory.setFilterConfig(getFilterConfig());
        FilterChainResolver resolver = filterChainResolverFactory.getInstance();
        setFilterChainResolver(resolver);
    }
}
Also used : Ini(org.apache.shiro.config.Ini) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver) IniFilterChainResolverFactory(org.apache.shiro.web.config.IniFilterChainResolverFactory)

Example 10 with FilterChainResolver

use of org.apache.shiro.web.filter.mgt.FilterChainResolver in project shiro by apache.

the class ShiroFilter method init.

/**
 * Configures this instance based on the existing {@link org.apache.shiro.web.env.WebEnvironment} instance
 * available to the currently accessible {@link #getServletContext() servletContext}.
 *
 * @see org.apache.shiro.web.env.EnvironmentLoaderListener
 * @since 1.2
 */
@Override
public void init() throws Exception {
    WebEnvironment env = WebUtils.getRequiredWebEnvironment(getServletContext());
    setSecurityManager(env.getWebSecurityManager());
    FilterChainResolver resolver = env.getFilterChainResolver();
    if (resolver != null) {
        setFilterChainResolver(resolver);
    }
}
Also used : WebEnvironment(org.apache.shiro.web.env.WebEnvironment) FilterChainResolver(org.apache.shiro.web.filter.mgt.FilterChainResolver)

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