Example usage for org.springframework.security.config BeanIds FILTER_CHAINS

List of usage examples for org.springframework.security.config BeanIds FILTER_CHAINS

Introduction

In this page you can find the example usage for org.springframework.security.config BeanIds FILTER_CHAINS.

Prototype

String FILTER_CHAINS

To view the source code for org.springframework.security.config BeanIds FILTER_CHAINS.

Click Source Link

Usage

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

/**
 * The aim of this method is to build the list of filters which have been defined by
 * the namespace elements and attributes within the <http> configuration, along
 * with any custom-filter's linked to user-defined filter beans.
 * <p>//  w ww  . ja  v a2 s .  c o  m
 * By the end of this method, the default <tt>FilterChainProxy</tt> bean should have
 * been registered and will have the map of filter chains defined, with the
 * "universal" match pattern mapped to the list of beans which have been parsed here.
 */
@SuppressWarnings({ "unchecked" })
@Override
public BeanDefinition parse(Element element, ParserContext pc) {
    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
            pc.extractSource(element));
    pc.pushContainingComponent(compositeDef);

    registerFilterChainProxyIfNecessary(pc, pc.extractSource(element));

    // Obtain the filter chains and add the new chain to it
    BeanDefinition listFactoryBean = pc.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS);
    List<BeanReference> filterChains = (List<BeanReference>) listFactoryBean.getPropertyValues()
            .getPropertyValue("sourceList").getValue();

    filterChains.add(createFilterChain(element, pc));

    pc.popAndRegisterContainingComponent();
    return null;
}

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

static void registerFilterChainProxyIfNecessary(ParserContext pc, Object source) {
    if (pc.getRegistry().containsBeanDefinition(BeanIds.FILTER_CHAIN_PROXY)) {
        return;/*from   w  ww . j av  a 2s.  c om*/
    }
    // Not already registered, so register the list of filter chains and the
    // FilterChainProxy
    BeanDefinition listFactoryBean = new RootBeanDefinition(ListFactoryBean.class);
    listFactoryBean.getPropertyValues().add("sourceList", new ManagedList());
    pc.registerBeanComponent(new BeanComponentDefinition(listFactoryBean, BeanIds.FILTER_CHAINS));

    BeanDefinitionBuilder fcpBldr = BeanDefinitionBuilder.rootBeanDefinition(FilterChainProxy.class);
    fcpBldr.getRawBeanDefinition().setSource(source);
    fcpBldr.addConstructorArgReference(BeanIds.FILTER_CHAINS);
    fcpBldr.addPropertyValue("filterChainValidator", new RootBeanDefinition(DefaultFilterChainValidator.class));
    BeanDefinition fcpBean = fcpBldr.getBeanDefinition();
    pc.registerBeanComponent(new BeanComponentDefinition(fcpBean, BeanIds.FILTER_CHAIN_PROXY));
    pc.getRegistry().registerAlias(BeanIds.FILTER_CHAIN_PROXY, BeanIds.SPRING_SECURITY_FILTER_CHAIN);
}