Example usage for org.springframework.security.config.http MatcherType fromElement

List of usage examples for org.springframework.security.config.http MatcherType fromElement

Introduction

In this page you can find the example usage for org.springframework.security.config.http MatcherType fromElement.

Prototype

static MatcherType fromElement(Element elt) 

Source Link

Usage

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

static RootBeanDefinition createSecurityMetadataSource(List<Element> interceptUrls, boolean addAllAuth,
        Element httpElt, ParserContext pc) {
    MatcherType matcherType = MatcherType.fromElement(httpElt);
    boolean useExpressions = isUseExpressions(httpElt);

    ManagedMap<BeanMetadataElement, BeanDefinition> requestToAttributesMap = parseInterceptUrlsForFilterInvocationRequestMap(
            matcherType, interceptUrls, useExpressions, addAllAuth, pc);
    BeanDefinitionBuilder fidsBuilder;// w w w .j a v  a 2s .  c  o  m

    if (useExpressions) {
        Element expressionHandlerElt = DomUtils.getChildElementByTagName(httpElt, Elements.EXPRESSION_HANDLER);
        String expressionHandlerRef = expressionHandlerElt == null ? null
                : expressionHandlerElt.getAttribute("ref");

        if (StringUtils.hasText(expressionHandlerRef)) {
            logger.info("Using bean '" + expressionHandlerRef
                    + "' as web SecurityExpressionHandler implementation");
        } else {
            expressionHandlerRef = registerDefaultExpressionHandler(pc);
        }

        fidsBuilder = BeanDefinitionBuilder
                .rootBeanDefinition(ExpressionBasedFilterInvocationSecurityMetadataSource.class);
        fidsBuilder.addConstructorArgValue(requestToAttributesMap);
        fidsBuilder.addConstructorArgReference(expressionHandlerRef);
    } else {
        fidsBuilder = BeanDefinitionBuilder
                .rootBeanDefinition(DefaultFilterInvocationSecurityMetadataSource.class);
        fidsBuilder.addConstructorArgValue(requestToAttributesMap);
    }

    fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(httpElt));

    return (RootBeanDefinition) fidsBuilder.getBeanDefinition();
}

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

private BeanReference createSecurityFilterChainBean(Element element, ParserContext pc, List<?> filterChain) {
    BeanMetadataElement filterChainMatcher;

    String requestMatcherRef = element.getAttribute(ATT_REQUEST_MATCHER_REF);
    String filterChainPattern = element.getAttribute(ATT_PATH_PATTERN);

    if (StringUtils.hasText(requestMatcherRef)) {
        if (StringUtils.hasText(filterChainPattern)) {
            pc.getReaderContext().error(
                    "You can't define a pattern and a request-matcher-ref for the " + "same filter chain",
                    pc.extractSource(element));
        }//from   w ww .j  a  va  2  s.c  o  m
        filterChainMatcher = new RuntimeBeanReference(requestMatcherRef);

    } else if (StringUtils.hasText(filterChainPattern)) {
        filterChainMatcher = MatcherType.fromElement(element).createMatcher(pc, filterChainPattern, null);
    } else {
        filterChainMatcher = new RootBeanDefinition(AnyRequestMatcher.class);
    }

    BeanDefinitionBuilder filterChainBldr = BeanDefinitionBuilder
            .rootBeanDefinition(DefaultSecurityFilterChain.class);
    filterChainBldr.addConstructorArgValue(filterChainMatcher);
    filterChainBldr.addConstructorArgValue(filterChain);

    BeanDefinition filterChainBean = filterChainBldr.getBeanDefinition();

    String id = element.getAttribute("name");
    if (!StringUtils.hasText(id)) {
        id = element.getAttribute("id");
        if (!StringUtils.hasText(id)) {
            id = pc.getReaderContext().generateBeanName(filterChainBean);
        }
    }

    pc.registerBeanComponent(new BeanComponentDefinition(filterChainBean, id));

    return new RuntimeBeanReference(id);
}