Example usage for org.apache.shiro.web.filter.mgt PathMatchingFilterChainResolver setFilterChainManager

List of usage examples for org.apache.shiro.web.filter.mgt PathMatchingFilterChainResolver setFilterChainManager

Introduction

In this page you can find the example usage for org.apache.shiro.web.filter.mgt PathMatchingFilterChainResolver setFilterChainManager.

Prototype

@SuppressWarnings({ "UnusedDeclaration" })
    public void setFilterChainManager(FilterChainManager filterChainManager) 

Source Link

Usage

From source file:com.centfor.frame.shiro.FrameShiroFilterFactoryBean.java

License:Apache License

/**
 * This implementation://from w  w  w.j a v  a 2  s . c o m
 * <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);

    //Now create a concrete ShiroFilter instance and apply the acquired SecurityManager and built
    //FilterChainResolver.  It doesn't matter that the instance is an anonymous inner class
    //here - we're just using it because it is a concrete AbstractShiroFilter instance that accepts
    //injection of the SecurityManager and FilterChainResolver:
    return new SpringShiroFilter((WebSecurityManager) securityManager, chainResolver);
}

From source file:com.freedomotic.plugins.devices.restapiv3.auth.FDWebEnvironment.java

License:Open Source License

public FDWebEnvironment() {
    BasicHttpAuthenticationFilter authc = new CorsBasicHttpAuthenticationFilter();
    LogoutFilter logout = new LogoutFilter();
    logout.setRedirectUrl("http://www.freedomotic.com/");

    FilterChainManager fcMan = new DefaultFilterChainManager();
    fcMan.addFilter("authc", authc);
    fcMan.addFilter("logout", logout);
    fcMan.createChain("/auth/logout", "logout");
    fcMan.createChain("/v3/**", "authc");

    PathMatchingFilterChainResolver resolver = new PathMatchingFilterChainResolver();
    resolver.setFilterChainManager(fcMan);

    setFilterChainResolver(resolver);//w  w w. j  av  a  2 s .co m
    setWebSecurityManager(RestAPIv3.defaultWebSecurityManager);
}

From source file:com.oakeel.shiro.PtpIniWebEnvironment.java

@Override
protected FilterChainResolver createFilterChainResolver() {
    // FilterChainResolver
    //1? FilterChainResolver
    PathMatchingFilterChainResolver filterChainResolver = new PathMatchingFilterChainResolver();
    //2? FilterChainManager
    DefaultFilterChainManager filterChainManager = new DefaultFilterChainManager();
    //3? Filter/*from w  w  w  .java  2  s  .co  m*/
    DefaultFilter[] filters = DefaultFilter.values();

    for (DefaultFilter filter : filters) {
        filterChainManager.addFilter(filter.name(), (Filter) ClassUtils.newInstance(filter.getFilterClass()));
    }
    //4? URL-Filter 
    filterChainManager.addToChain("/log.xhtml", "authc");
    filterChainManager.addToChain("/unauthorized.xhtml", "anon");
    filterChainManager.addToChain("/**", "authc");
    filterChainManager.addToChain("/**", "roles", "admin");
    //5? Filter 
    FormAuthenticationFilter authcFilter = (FormAuthenticationFilter) filterChainManager.getFilter("authc");

    authcFilter.setLoginUrl("/login.jsp");
    RolesAuthorizationFilter rolesFilter = (RolesAuthorizationFilter) filterChainManager.getFilter("roles");

    rolesFilter.setUnauthorizedUrl("/unauthorized.jsp");
    filterChainResolver.setFilterChainManager(filterChainManager);
    return filterChainResolver;
}

From source file:io.bootique.shiro.web.MappedShiroFilterFactory.java

License:Apache License

protected FilterChainResolver createChainResolver(Map<String, Filter> chainFilters) {
    DefaultFilterChainManager chainManager = new DefaultFilterChainManager();

    // load filters
    chainFilters.forEach((name, filter) -> chainManager.addFilter(name, filter));

    if (urls != null) {
        urls.forEach((url, value) -> {
            LOGGER.info("Loading url chain {} -> {}", url, value);
            chainManager.createChain(url, value);
        });/*from w  w w.j  a v  a 2 s.c  o m*/
    }

    PathMatchingFilterChainResolver resolver = new PathMatchingFilterChainResolver();
    resolver.setFilterChainManager(chainManager);
    return resolver;
}

From source file:myStuff.rest.shiro.ShiroHelper.java

License:Apache License

public static FilterChainResolver getFilterChainResolver() {
    if (filterChainResolver == null) {
        BasicHttpAuthenticationFilter authcBasic = new MyFilter();
        authcBasic.setEnabled(true);//from  w ww  .  j av  a  2s  .c o m

        FilterChainManager fcMan = new DefaultFilterChainManager();
        fcMan.addFilter("authcBasic[permissive]", authcBasic);
        fcMan.createChain("/**", "authcBasic[permissive]");

        PathMatchingFilterChainResolver resolver = new PathMatchingFilterChainResolver();
        resolver.setFilterChainManager(fcMan);
        filterChainResolver = resolver;
    }
    return filterChainResolver;
}

From source file:org.base.frame.shiro.FrameShiroFilterFactoryBean.java

License:Apache License

/**
 * This implementation://from   ww  w . ja v  a  2s .co m
 * <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);

    //Now create a concrete ShiroFilter instance and apply the acquired SecurityManager and built
    //FilterChainResolver.  It doesn't matter that the instance is an anonymous inner class
    //here - we're just using it because it is a concrete AbstractShiroFilter instance that accepts
    //injection of the SecurityManager and FilterChainResolver:
    return new SpringShiroFilter((WebSecurityManager) securityManager, chainResolver);
}

From source file:org.panifex.security.shiro.env.ModularWebEnvironment.java

License:Open Source License

@Override
protected FilterChainResolver createFilterChainResolver() {
    PathMatchingFilterChainResolver resolver = (PathMatchingFilterChainResolver) super.createFilterChainResolver();
    if (resolver == null) {
        Ini ini = getIni();/*from w w  w .  ja v a  2 s .  co  m*/
        IniFilterChainResolverFactory factory = new IniFilterChainResolverFactory(ini, objects);
        resolver = (PathMatchingFilterChainResolver) factory.getInstance();

        resolver.setFilterChainManager(filterChainManager);
    }
    return resolver;
}

From source file:zcu.xutil.misc.ShiroFilterFactory.java

License:Apache License

public AbstractShiroFilter getShiroFilter() {
    DefaultFilterChainManager manager = new DefaultFilterChainManager();
    for (Filter filter : manager.getFilters().values())
        applyGlobalPropertiesIfNecessary(filter);
    for (Map.Entry<String, Filter> entry : filters.entrySet()) {
        applyGlobalPropertiesIfNecessary(entry.getValue());
        manager.addFilter(entry.getKey(), entry.getValue());
    }/*from  w  w w  .  j  a  v  a2 s . c  om*/
    Ini ini = new Ini();
    ini.load(definitions);
    Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS);
    if (CollectionUtils.isEmpty(section))
        section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
    for (Map.Entry<String, String> entry : section.entrySet())
        manager.createChain(entry.getKey(), entry.getValue());
    PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
    chainResolver.setFilterChainManager(manager);
    return new XSFilter((WebSecurityManager) securityManager, chainResolver);
}