Search in sources :

Example 1 with FilterChainManager

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

the class ShiroFilterFactoryBean method createInstance.

/**
 * This implementation:
 * <ol>
 * <li>Ensures the required {@link #setSecurityManager(org.apache.shiro.mgt.SecurityManager) securityManager}
 * property has been set</li>
 * <li>{@link #createFilterChainManager() Creates} a {@link FilterChainManager} instance that reflects the
 * configured {@link #setFilters(java.util.Map) filters} and
 * {@link #setFilterChainDefinitionMap(java.util.Map) filter chain definitions}</li>
 * <li>Wraps the FilterChainManager with a suitable
 * {@link org.apache.shiro.web.filter.mgt.FilterChainResolver FilterChainResolver} since the Shiro Filter
 * implementations do not know of {@code FilterChainManager}s</li>
 * <li>Sets both the {@code SecurityManager} and {@code FilterChainResolver} instances on a new Shiro Filter
 * instance and returns that filter instance.</li>
 * </ol>
 *
 * @return a new Shiro Filter reflecting any configured filters and filter chain definitions.
 * @throws Exception if there is a problem creating the AbstractShiroFilter instance.
 */
protected AbstractShiroFilter createInstance() throws Exception {
    log.debug("Creating Shiro Filter instance.");
    SecurityManager securityManager = getSecurityManager();
    if (securityManager == null) {
        String msg = "SecurityManager property must be set.";
        throw new BeanInitializationException(msg);
    }
    if (!(securityManager instanceof WebSecurityManager)) {
        String msg = "The security manager does not implement the WebSecurityManager interface.";
        throw new BeanInitializationException(msg);
    }
    FilterChainManager manager = createFilterChainManager();
    // Expose the constructed FilterChainManager by first wrapping it in a
    // FilterChainResolver implementation. The AbstractShiroFilter implementations
    // do not know about FilterChainManagers - only resolvers:
    PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
    chainResolver.setFilterChainManager(manager);
    // injection of the SecurityManager and FilterChainResolver:
    return new SpringShiroFilter((WebSecurityManager) securityManager, chainResolver);
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) SecurityManager(org.apache.shiro.mgt.SecurityManager) DefaultFilterChainManager(org.apache.shiro.web.filter.mgt.DefaultFilterChainManager) FilterChainManager(org.apache.shiro.web.filter.mgt.FilterChainManager) PathMatchingFilterChainResolver(org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver)

Example 2 with FilterChainManager

use of org.apache.shiro.web.filter.mgt.FilterChainManager 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

FilterChainManager (org.apache.shiro.web.filter.mgt.FilterChainManager)2 PathMatchingFilterChainResolver (org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver)2 SecurityManager (org.apache.shiro.mgt.SecurityManager)1 DefaultFilterChainManager (org.apache.shiro.web.filter.mgt.DefaultFilterChainManager)1 FilterChainResolver (org.apache.shiro.web.filter.mgt.FilterChainResolver)1 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1