Example usage for org.springframework.security.web FilterChainProxy getFilterChains

List of usage examples for org.springframework.security.web FilterChainProxy getFilterChains

Introduction

In this page you can find the example usage for org.springframework.security.web FilterChainProxy getFilterChains.

Prototype

public List<SecurityFilterChain> getFilterChains() 

Source Link

Usage

From source file:org.brutusin.rpc.RpcWebInitializer.java

public void onStartup(final ServletContext ctx) throws ServletException {
    final RpcServlet rpcServlet = registerRpcServlet(ctx);
    final WebsocketFilter websocketFilter = new WebsocketFilter();
    FilterRegistration.Dynamic dynamic = ctx.addFilter(WebsocketFilter.class.getName(), websocketFilter);
    dynamic.addMappingForUrlPatterns(null, false, RpcConfig.getInstance().getPath() + "/wskt");
    JsonCodec.getInstance().registerStringFormat(MetaDataInputStream.class, "inputstream");
    final Bean<RpcSpringContext> rpcCtxBean = new Bean<RpcSpringContext>();
    ctx.addListener(new ServletRequestListener() {

        public void requestDestroyed(ServletRequestEvent sre) {
            GlobalThreadLocal.clear();//w  w w.  j a  va 2s.c om
        }

        public void requestInitialized(ServletRequestEvent sre) {
            GlobalThreadLocal.set(new GlobalThreadLocal((HttpServletRequest) sre.getServletRequest(), null));
        }
    });
    ctx.addListener(new ServletContextListener() {

        public void contextInitialized(ServletContextEvent sce) {
            RpcSpringContext rpcCtx = createRpcSpringContext(ctx);
            rpcCtxBean.setValue(rpcCtx);
            rpcServlet.setRpcCtx(rpcCtx);
            initWebsocketRpcRuntime(ctx, rpcCtx);
            ctx.setAttribute(RpcSpringContext.class.getName(), rpcCtx);
        }

        public void contextDestroyed(ServletContextEvent sce) {
            LOGGER.info("Destroying RPC context");
            if (rpcCtxBean.getValue() != null) {
                rpcCtxBean.getValue().destroy();
            }
        }
    });
    ctx.addListener(new ServletContextAttributeListener() {
        public void attributeAdded(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        public void attributeRemoved(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        public void attributeReplaced(ServletContextAttributeEvent event) {
            if (event.getName().equals(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE)) {
                updateRootContext();
            }
        }

        private void updateRootContext() {
            WebApplicationContext rootCtx = WebApplicationContextUtils.getWebApplicationContext(ctx);
            if (rootCtx != null) {
                if (rpcCtxBean.getValue() != null) {
                    rpcCtxBean.getValue().setParent(rootCtx);
                }
                if (rootCtx.containsBean("springSecurityFilterChain")) {
                    LOGGER.info("Moving WebsocketFilter behind springSecurityFilterChain");
                    websocketFilter.disable();
                    FilterChainProxy fcp = (FilterChainProxy) rootCtx.getBean("springSecurityFilterChain");
                    fcp.getFilterChains().get(0).getFilters().add(new WebsocketFilter());
                }
            }
        }
    });
}

From source file:com.netflix.genie.web.security.saml.SAMLConfigUnitTests.java

/**
 * Make sure we can get a valid SAML security processing filter chain.
 *
 * @throws Exception on any problem/*from w ww  . ja v  a 2s.co  m*/
 */
@Ignore
@Test
public void canGetSAMLFilterChain() throws Exception {
    final FilterChainProxy filterChainProxy = this.config.samlFilter();
    Assert.assertNotNull(filterChainProxy);
    Assert.assertThat(filterChainProxy.getFilterChains().size(), Matchers.is(7));
}

From source file:org.springframework.security.config.http.DefaultFilterChainValidator.java

public void validate(FilterChainProxy fcp) {
    for (SecurityFilterChain filterChain : fcp.getFilterChains()) {
        checkLoginPageIsntProtected(fcp, filterChain.getFilters());
        checkFilterStack(filterChain.getFilters());
    }//from   w w  w . ja va  2s.c  o m

    checkPathOrder(new ArrayList<>(fcp.getFilterChains()));
    checkForDuplicateMatchers(new ArrayList<>(fcp.getFilterChains()));
}