Search in sources :

Example 76 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-security by spring-projects.

the class HttpConfigurationBuilder method createConcurrencyControlFilterAndSessionRegistry.

private void createConcurrencyControlFilterAndSessionRegistry(Element element) {
    final String ATT_EXPIRY_URL = "expired-url";
    final String ATT_EXPIRED_SESSION_STRATEGY_REF = "expired-session-strategy-ref";
    final String ATT_SESSION_REGISTRY_ALIAS = "session-registry-alias";
    final String ATT_SESSION_REGISTRY_REF = "session-registry-ref";
    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), pc.extractSource(element));
    pc.pushContainingComponent(compositeDef);
    BeanDefinitionRegistry beanRegistry = pc.getRegistry();
    String sessionRegistryId = element.getAttribute(ATT_SESSION_REGISTRY_REF);
    if (!StringUtils.hasText(sessionRegistryId)) {
        // Register an internal SessionRegistryImpl if no external reference supplied.
        RootBeanDefinition sessionRegistry = new RootBeanDefinition(SessionRegistryImpl.class);
        sessionRegistryId = pc.getReaderContext().registerWithGeneratedName(sessionRegistry);
        pc.registerComponent(new BeanComponentDefinition(sessionRegistry, sessionRegistryId));
    }
    String registryAlias = element.getAttribute(ATT_SESSION_REGISTRY_ALIAS);
    if (StringUtils.hasText(registryAlias)) {
        beanRegistry.registerAlias(sessionRegistryId, registryAlias);
    }
    BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.rootBeanDefinition(ConcurrentSessionFilter.class);
    filterBuilder.addConstructorArgReference(sessionRegistryId);
    Object source = pc.extractSource(element);
    filterBuilder.getRawBeanDefinition().setSource(source);
    filterBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    String expiryUrl = element.getAttribute(ATT_EXPIRY_URL);
    String expiredSessionStrategyRef = element.getAttribute(ATT_EXPIRED_SESSION_STRATEGY_REF);
    if (StringUtils.hasText(expiryUrl) && StringUtils.hasText(expiredSessionStrategyRef)) {
        pc.getReaderContext().error("Cannot use 'expired-url' attribute and 'expired-session-strategy-ref'" + " attribute together.", source);
    }
    if (StringUtils.hasText(expiryUrl)) {
        BeanDefinitionBuilder expiredSessionBldr = BeanDefinitionBuilder.rootBeanDefinition(SimpleRedirectSessionInformationExpiredStrategy.class);
        expiredSessionBldr.addConstructorArgValue(expiryUrl);
        filterBuilder.addConstructorArgValue(expiredSessionBldr.getBeanDefinition());
    } else if (StringUtils.hasText(expiredSessionStrategyRef)) {
        filterBuilder.addConstructorArgReference(expiredSessionStrategyRef);
    }
    pc.popAndRegisterContainingComponent();
    concurrentSessionFilter = filterBuilder.getBeanDefinition();
    sessionRegistryRef = new RuntimeBeanReference(sessionRegistryId);
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 77 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-security by spring-projects.

the class ClearCredentialsMethodInvokingFactoryBean method createSecurityFilterChainBean.

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));
        }
        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);
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 78 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project jetcache by alibaba.

the class CacheAnnotationParser method doParse.

private synchronized void doParse(Element element, ParserContext parserContext) {
    String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute("base-package"), ",; \t\n");
    AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
    if (!parserContext.getRegistry().containsBeanDefinition(CacheAdvisor.CACHE_ADVISOR_BEAN_NAME)) {
        Object eleSource = parserContext.extractSource(element);
        RootBeanDefinition configMapDef = new RootBeanDefinition(ConcurrentHashMap.class);
        configMapDef.setSource(eleSource);
        configMapDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String configMapName = parserContext.getReaderContext().registerWithGeneratedName(configMapDef);
        RootBeanDefinition interceptorDef = new RootBeanDefinition(JetCacheInterceptor.class);
        interceptorDef.setSource(eleSource);
        interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        interceptorDef.getPropertyValues().addPropertyValue(new PropertyValue("cacheConfigMap", new RuntimeBeanReference(configMapName)));
        String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);
        RootBeanDefinition advisorDef = new RootBeanDefinition(CacheAdvisor.class);
        advisorDef.setSource(eleSource);
        advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("adviceBeanName", interceptorName));
        advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("cacheConfigMap", new RuntimeBeanReference(configMapName)));
        advisorDef.getPropertyValues().addPropertyValue(new PropertyValue("basePackages", basePackages));
        parserContext.getRegistry().registerBeanDefinition(CacheAdvisor.CACHE_ADVISOR_BEAN_NAME, advisorDef);
        CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
        compositeDef.addNestedComponent(new BeanComponentDefinition(configMapDef, configMapName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
        compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheAdvisor.CACHE_ADVISOR_BEAN_NAME));
        parserContext.registerComponent(compositeDef);
    }
}
Also used : CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) PropertyValue(org.springframework.beans.PropertyValue) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 79 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project leopard by tanhaichao.

the class RegisterComponentUtil method registerComponent.

public static BeanDefinition registerComponent(ParserContext parserContext, BeanDefinitionBuilder builder, String id) {
    BeanDefinition definition = builder.getBeanDefinition();
    if (!parserContext.isNested()) {
        String[] aliases = new String[0];
        BeanDefinitionHolder holder = new BeanDefinitionHolder(definition, id, aliases);
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, parserContext.getRegistry());
        BeanComponentDefinition componentDefinition = new BeanComponentDefinition(holder);
        parserContext.registerComponent(componentDefinition);
    }
    return definition;
}
Also used : BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 80 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterParser method getValidator.

private RuntimeBeanReference getValidator(Object source, ParserContext parserContext) {
    if (!JSR_303_PRESENT) {
        return null;
    }
    RootBeanDefinition validatorDef = new RootBeanDefinition("org.springframework.validation.beanvalidation.LocalValidatorFactoryBean");
    validatorDef.setSource(source);
    validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
    String validatorName = parserContext.getReaderContext().registerWithGeneratedName(validatorDef);
    parserContext.registerBeanComponent(new BeanComponentDefinition(validatorDef, validatorName));
    return new RuntimeBeanReference(validatorName);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Aggregations

BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)82 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)53 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)33 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)28 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)24 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)17 Element (org.w3c.dom.Element)16 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)11 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)11 ManagedList (org.springframework.beans.factory.support.ManagedList)10 Test (org.junit.Test)7 ComponentDefinition (org.springframework.beans.factory.parsing.ComponentDefinition)7 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)6 ManagedMap (org.springframework.beans.factory.support.ManagedMap)4 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)3 BeanComponentDefinitionBuilder (org.springframework.data.config.BeanComponentDefinitionBuilder)3 Method (java.lang.reflect.Method)2 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)2 PropertyValue (org.springframework.beans.PropertyValue)2 BeanReference (org.springframework.beans.factory.config.BeanReference)2