Example usage for org.springframework.beans.factory.parsing BeanComponentDefinition BeanComponentDefinition

List of usage examples for org.springframework.beans.factory.parsing BeanComponentDefinition BeanComponentDefinition

Introduction

In this page you can find the example usage for org.springframework.beans.factory.parsing BeanComponentDefinition BeanComponentDefinition.

Prototype

public BeanComponentDefinition(BeanDefinition beanDefinition, String beanName) 

Source Link

Document

Create a new BeanComponentDefinition for the given bean.

Usage

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

private RuntimeBeanReference createPortResolver(BeanReference portMapper, ParserContext pc) {
    RootBeanDefinition portResolver = new RootBeanDefinition(PortResolverImpl.class);
    portResolver.getPropertyValues().addPropertyValue("portMapper", portMapper);
    String portResolverName = pc.getReaderContext().generateBeanName(portResolver);
    pc.registerBeanComponent(new BeanComponentDefinition(portResolver, portResolverName));
    return new RuntimeBeanReference(portResolverName);
}

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

/**
 * Creates the internal AuthenticationManager bean which uses either the externally
 * registered (global) one as a parent or the bean specified by
 * "authentication-manager-ref".//from ww  w . j a  va 2 s.  c om
 *
 * All the providers registered by this <http> block will be registered with the
 * internal authentication manager.
 */
private BeanReference createAuthenticationManager(Element element, ParserContext pc,
        ManagedList<BeanReference> authenticationProviders) {
    String parentMgrRef = element.getAttribute(ATT_AUTHENTICATION_MANAGER_REF);
    BeanDefinitionBuilder authManager = BeanDefinitionBuilder.rootBeanDefinition(ProviderManager.class);
    authManager.addConstructorArgValue(authenticationProviders);

    if (StringUtils.hasText(parentMgrRef)) {
        RuntimeBeanReference parentAuthManager = new RuntimeBeanReference(parentMgrRef);
        authManager.addConstructorArgValue(parentAuthManager);
        RootBeanDefinition clearCredentials = new RootBeanDefinition(
                ClearCredentialsMethodInvokingFactoryBean.class);
        clearCredentials.getPropertyValues().addPropertyValue("targetObject", parentAuthManager);
        clearCredentials.getPropertyValues().addPropertyValue("targetMethod",
                "isEraseCredentialsAfterAuthentication");

        authManager.addPropertyValue("eraseCredentialsAfterAuthentication", clearCredentials);
    } else {
        RootBeanDefinition amfb = new RootBeanDefinition(AuthenticationManagerFactoryBean.class);
        amfb.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String amfbId = pc.getReaderContext().generateBeanName(amfb);
        pc.registerBeanComponent(new BeanComponentDefinition(amfb, amfbId));
        RootBeanDefinition clearCredentials = new RootBeanDefinition(MethodInvokingFactoryBean.class);
        clearCredentials.getPropertyValues().addPropertyValue("targetObject", new RuntimeBeanReference(amfbId));
        clearCredentials.getPropertyValues().addPropertyValue("targetMethod",
                "isEraseCredentialsAfterAuthentication");

        authManager.addConstructorArgValue(new RuntimeBeanReference(amfbId));
        authManager.addPropertyValue("eraseCredentialsAfterAuthentication", clearCredentials);
    }

    authManager.getRawBeanDefinition().setSource(pc.extractSource(element));
    BeanDefinition authMgrBean = authManager.getBeanDefinition();
    String id = pc.getReaderContext().generateBeanName(authMgrBean);
    pc.registerBeanComponent(new BeanComponentDefinition(authMgrBean, id));

    return new RuntimeBeanReference(id);
}

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;/* w w  w  . j  a  va2  s .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);
}

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

public BeanDefinition parse(Element element, ParserContext pc) {
    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
            pc.extractSource(element));//from  w w  w.j ava  2  s.  c o  m
    pc.pushContainingComponent(compositeDef);

    String tokenRepository = element.getAttribute(ATT_TOKEN_REPOSITORY);
    String dataSource = element.getAttribute(ATT_DATA_SOURCE);
    String userServiceRef = element.getAttribute(ATT_USER_SERVICE_REF);
    String successHandlerRef = element.getAttribute(ATT_SUCCESS_HANDLER_REF);
    String rememberMeServicesRef = element.getAttribute(ATT_SERVICES_REF);
    String tokenValiditySeconds = element.getAttribute(ATT_TOKEN_VALIDITY);
    String useSecureCookie = element.getAttribute(ATT_SECURE_COOKIE);
    String remembermeParameter = element.getAttribute(ATT_FORM_REMEMBERME_PARAMETER);
    String remembermeCookie = element.getAttribute(ATT_REMEMBERME_COOKIE);
    Object source = pc.extractSource(element);

    RootBeanDefinition services = null;

    boolean dataSourceSet = StringUtils.hasText(dataSource);
    boolean tokenRepoSet = StringUtils.hasText(tokenRepository);
    boolean servicesRefSet = StringUtils.hasText(rememberMeServicesRef);
    boolean userServiceSet = StringUtils.hasText(userServiceRef);
    boolean useSecureCookieSet = StringUtils.hasText(useSecureCookie);
    boolean tokenValiditySet = StringUtils.hasText(tokenValiditySeconds);
    boolean remembermeParameterSet = StringUtils.hasText(remembermeParameter);
    boolean remembermeCookieSet = StringUtils.hasText(remembermeCookie);

    if (servicesRefSet && (dataSourceSet || tokenRepoSet || userServiceSet || tokenValiditySet
            || useSecureCookieSet || remembermeParameterSet || remembermeCookieSet)) {
        pc.getReaderContext()
                .error(ATT_SERVICES_REF + " can't be used in combination with attributes "
                        + ATT_TOKEN_REPOSITORY + "," + ATT_DATA_SOURCE + ", " + ATT_USER_SERVICE_REF + ", "
                        + ATT_TOKEN_VALIDITY + ", " + ATT_SECURE_COOKIE + ", " + ATT_FORM_REMEMBERME_PARAMETER
                        + " or " + ATT_REMEMBERME_COOKIE, source);
    }

    if (dataSourceSet && tokenRepoSet) {
        pc.getReaderContext()
                .error("Specify " + ATT_TOKEN_REPOSITORY + " or " + ATT_DATA_SOURCE + " but not both", source);
    }

    boolean isPersistent = dataSourceSet | tokenRepoSet;

    if (isPersistent) {
        Object tokenRepo;
        services = new RootBeanDefinition(PersistentTokenBasedRememberMeServices.class);

        if (tokenRepoSet) {
            tokenRepo = new RuntimeBeanReference(tokenRepository);
        } else {
            tokenRepo = new RootBeanDefinition(JdbcTokenRepositoryImpl.class);
            ((BeanDefinition) tokenRepo).getPropertyValues().addPropertyValue("dataSource",
                    new RuntimeBeanReference(dataSource));
        }
        services.getConstructorArgumentValues().addIndexedArgumentValue(2, tokenRepo);
    } else if (!servicesRefSet) {
        services = new RootBeanDefinition(TokenBasedRememberMeServices.class);
    }

    String servicesName;

    if (services != null) {
        RootBeanDefinition uds = new RootBeanDefinition();
        uds.setFactoryBeanName(BeanIds.USER_DETAILS_SERVICE_FACTORY);
        uds.setFactoryMethodName("cachingUserDetailsService");
        uds.getConstructorArgumentValues().addGenericArgumentValue(userServiceRef);

        services.getConstructorArgumentValues().addGenericArgumentValue(key);
        services.getConstructorArgumentValues().addGenericArgumentValue(uds);
        // tokenRepo is already added if it is a
        // PersistentTokenBasedRememberMeServices

        if (useSecureCookieSet) {
            services.getPropertyValues().addPropertyValue("useSecureCookie", Boolean.valueOf(useSecureCookie));
        }

        if (tokenValiditySet) {
            boolean isTokenValidityNegative = tokenValiditySeconds.startsWith("-");
            if (isTokenValidityNegative && isPersistent) {
                pc.getReaderContext().error(ATT_TOKEN_VALIDITY + " cannot be negative if using"
                        + " a persistent remember-me token repository", source);
            }
            services.getPropertyValues().addPropertyValue("tokenValiditySeconds", tokenValiditySeconds);
        }

        if (remembermeParameterSet) {
            services.getPropertyValues().addPropertyValue("parameter", remembermeParameter);
        }

        if (remembermeCookieSet) {
            services.getPropertyValues().addPropertyValue("cookieName", remembermeCookie);
        }

        services.setSource(source);
        servicesName = pc.getReaderContext().generateBeanName(services);
        pc.registerBeanComponent(new BeanComponentDefinition(services, servicesName));
    } else {
        servicesName = rememberMeServicesRef;
    }

    if (StringUtils.hasText(element.getAttribute(ATT_SERVICES_ALIAS))) {
        pc.getRegistry().registerAlias(servicesName, element.getAttribute(ATT_SERVICES_ALIAS));
    }

    this.rememberMeServicesId = servicesName;

    BeanDefinitionBuilder filter = BeanDefinitionBuilder
            .rootBeanDefinition(RememberMeAuthenticationFilter.class);
    filter.getRawBeanDefinition().setSource(source);

    if (StringUtils.hasText(successHandlerRef)) {
        filter.addPropertyReference("authenticationSuccessHandler", successHandlerRef);
    }

    filter.addConstructorArgValue(authenticationManager);
    filter.addConstructorArgReference(servicesName);

    pc.popAndRegisterContainingComponent();

    return filter.getBeanDefinition();
}

From source file:org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext pc) {
    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(),
            pc.extractSource(element));/*from  ww  w  .  j  a v a 2 s .co  m*/
    pc.pushContainingComponent(compositeDef);

    Object source = pc.extractSource(element);
    // The list of method metadata delegates
    ManagedList<BeanMetadataElement> delegates = new ManagedList<>();

    boolean jsr250Enabled = "enabled".equals(element.getAttribute(ATT_USE_JSR250));
    boolean useSecured = "enabled".equals(element.getAttribute(ATT_USE_SECURED));
    boolean prePostAnnotationsEnabled = "enabled".equals(element.getAttribute(ATT_USE_PREPOST));
    boolean useAspectJ = "aspectj".equals(element.getAttribute(ATT_MODE));

    BeanDefinition preInvocationVoter = null;
    ManagedList<BeanMetadataElement> afterInvocationProviders = new ManagedList<>();

    // Check for an external SecurityMetadataSource, which takes priority over other
    // sources
    String metaDataSourceId = element.getAttribute(ATT_META_DATA_SOURCE_REF);

    if (StringUtils.hasText(metaDataSourceId)) {
        delegates.add(new RuntimeBeanReference(metaDataSourceId));
    }

    if (prePostAnnotationsEnabled) {
        Element prePostElt = DomUtils.getChildElementByTagName(element, INVOCATION_HANDLING);
        Element expressionHandlerElt = DomUtils.getChildElementByTagName(element, EXPRESSION_HANDLER);

        if (prePostElt != null && expressionHandlerElt != null) {
            pc.getReaderContext().error(
                    INVOCATION_HANDLING + " and " + EXPRESSION_HANDLER + " cannot be used together ", source);
        }

        BeanDefinitionBuilder preInvocationVoterBldr = BeanDefinitionBuilder
                .rootBeanDefinition(PreInvocationAuthorizationAdviceVoter.class);
        // After-invocation provider to handle post-invocation filtering and
        // authorization expression annotations.
        BeanDefinitionBuilder afterInvocationBldr = BeanDefinitionBuilder
                .rootBeanDefinition(PostInvocationAdviceProvider.class);
        // The metadata source for the security interceptor
        BeanDefinitionBuilder mds = BeanDefinitionBuilder
                .rootBeanDefinition(PrePostAnnotationSecurityMetadataSource.class);

        if (prePostElt != null) {
            // Customized override of expression handling system
            String attributeFactoryRef = DomUtils
                    .getChildElementByTagName(prePostElt, INVOCATION_ATTRIBUTE_FACTORY).getAttribute("ref");
            String preAdviceRef = DomUtils.getChildElementByTagName(prePostElt, PRE_INVOCATION_ADVICE)
                    .getAttribute("ref");
            String postAdviceRef = DomUtils.getChildElementByTagName(prePostElt, POST_INVOCATION_ADVICE)
                    .getAttribute("ref");

            mds.addConstructorArgReference(attributeFactoryRef);
            preInvocationVoterBldr.addConstructorArgReference(preAdviceRef);
            afterInvocationBldr.addConstructorArgReference(postAdviceRef);
        } else {
            // The default expression-based system
            String expressionHandlerRef = expressionHandlerElt == null ? null
                    : expressionHandlerElt.getAttribute("ref");

            if (StringUtils.hasText(expressionHandlerRef)) {
                logger.info(
                        "Using bean '" + expressionHandlerRef + "' as method ExpressionHandler implementation");
                RootBeanDefinition lazyInitPP = new RootBeanDefinition(
                        LazyInitBeanDefinitionRegistryPostProcessor.class);
                lazyInitPP.getConstructorArgumentValues().addGenericArgumentValue(expressionHandlerRef);
                pc.getReaderContext().registerWithGeneratedName(lazyInitPP);

                BeanDefinitionBuilder lazyMethodSecurityExpressionHandlerBldr = BeanDefinitionBuilder
                        .rootBeanDefinition(LazyInitTargetSource.class);
                lazyMethodSecurityExpressionHandlerBldr.addPropertyValue("targetBeanName",
                        expressionHandlerRef);

                BeanDefinitionBuilder expressionHandlerProxyBldr = BeanDefinitionBuilder
                        .rootBeanDefinition(ProxyFactoryBean.class);
                expressionHandlerProxyBldr.addPropertyValue("targetSource",
                        lazyMethodSecurityExpressionHandlerBldr.getBeanDefinition());
                expressionHandlerProxyBldr.addPropertyValue("proxyInterfaces",
                        MethodSecurityExpressionHandler.class);

                expressionHandlerRef = pc.getReaderContext()
                        .generateBeanName(expressionHandlerProxyBldr.getBeanDefinition());

                pc.registerBeanComponent(new BeanComponentDefinition(
                        expressionHandlerProxyBldr.getBeanDefinition(), expressionHandlerRef));
            } else {
                RootBeanDefinition expressionHandler = registerWithDefaultRolePrefix(pc,
                        DefaultMethodSecurityExpressionHandlerBeanFactory.class);

                expressionHandlerRef = pc.getReaderContext().generateBeanName(expressionHandler);
                pc.registerBeanComponent(new BeanComponentDefinition(expressionHandler, expressionHandlerRef));
                logger.info(
                        "Expressions were enabled for method security but no SecurityExpressionHandler was configured. "
                                + "All hasPermision() expressions will evaluate to false.");
            }

            BeanDefinitionBuilder expressionPreAdviceBldr = BeanDefinitionBuilder
                    .rootBeanDefinition(ExpressionBasedPreInvocationAdvice.class);
            expressionPreAdviceBldr.addPropertyReference("expressionHandler", expressionHandlerRef);
            preInvocationVoterBldr.addConstructorArgValue(expressionPreAdviceBldr.getBeanDefinition());

            BeanDefinitionBuilder expressionPostAdviceBldr = BeanDefinitionBuilder
                    .rootBeanDefinition(ExpressionBasedPostInvocationAdvice.class);
            expressionPostAdviceBldr.addConstructorArgReference(expressionHandlerRef);
            afterInvocationBldr.addConstructorArgValue(expressionPostAdviceBldr.getBeanDefinition());

            BeanDefinitionBuilder annotationInvocationFactory = BeanDefinitionBuilder
                    .rootBeanDefinition(ExpressionBasedAnnotationAttributeFactory.class);
            annotationInvocationFactory.addConstructorArgReference(expressionHandlerRef);
            mds.addConstructorArgValue(annotationInvocationFactory.getBeanDefinition());
        }

        preInvocationVoter = preInvocationVoterBldr.getBeanDefinition();
        afterInvocationProviders.add(afterInvocationBldr.getBeanDefinition());
        delegates.add(mds.getBeanDefinition());
    }

    if (useSecured) {
        delegates.add(BeanDefinitionBuilder.rootBeanDefinition(SecuredAnnotationSecurityMetadataSource.class)
                .getBeanDefinition());
    }

    if (jsr250Enabled) {
        RootBeanDefinition jsrMetadataSource = registerWithDefaultRolePrefix(pc,
                Jsr250MethodSecurityMetadataSourceBeanFactory.class);
        delegates.add(jsrMetadataSource);
    }

    // Now create a Map<String, ConfigAttribute> for each <protect-pointcut>
    // sub-element
    Map<String, List<ConfigAttribute>> pointcutMap = parseProtectPointcuts(pc,
            DomUtils.getChildElementsByTagName(element, PROTECT_POINTCUT));

    if (pointcutMap.size() > 0) {
        if (useAspectJ) {
            pc.getReaderContext().error("You can't use AspectJ mode with protect-pointcut definitions", source);
        }
        // Only add it if there are actually any pointcuts defined.
        BeanDefinition mapBasedMetadataSource = new RootBeanDefinition(
                MapBasedMethodSecurityMetadataSource.class);
        BeanReference ref = new RuntimeBeanReference(
                pc.getReaderContext().generateBeanName(mapBasedMetadataSource));

        delegates.add(ref);
        pc.registerBeanComponent(new BeanComponentDefinition(mapBasedMetadataSource, ref.getBeanName()));
        registerProtectPointcutPostProcessor(pc, pointcutMap, ref, source);
    }

    BeanReference metadataSource = registerDelegatingMethodSecurityMetadataSource(pc, delegates, source);

    // Check for additional after-invocation-providers..
    List<Element> afterInvocationElts = DomUtils.getChildElementsByTagName(element,
            Elements.AFTER_INVOCATION_PROVIDER);

    for (Element elt : afterInvocationElts) {
        afterInvocationProviders.add(new RuntimeBeanReference(elt.getAttribute(ATT_REF)));
    }

    String accessManagerId = element.getAttribute(ATT_ACCESS_MGR);

    if (!StringUtils.hasText(accessManagerId)) {
        accessManagerId = registerAccessManager(pc, jsr250Enabled, preInvocationVoter);
    }

    String authMgrRef = element.getAttribute(ATT_AUTHENTICATION_MANAGER_REF);

    String runAsManagerId = element.getAttribute(ATT_RUN_AS_MGR);
    BeanReference interceptor = registerMethodSecurityInterceptor(pc, authMgrRef, accessManagerId,
            runAsManagerId, metadataSource, afterInvocationProviders, source, useAspectJ);

    if (useAspectJ) {
        BeanDefinitionBuilder aspect = BeanDefinitionBuilder.rootBeanDefinition(
                "org.springframework.security.access.intercept.aspectj.aspect.AnnotationSecurityAspect");
        aspect.setFactoryMethod("aspectOf");
        aspect.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        aspect.addPropertyValue("securityInterceptor", interceptor);
        String id = pc.getReaderContext().registerWithGeneratedName(aspect.getBeanDefinition());
        pc.registerBeanComponent(new BeanComponentDefinition(aspect.getBeanDefinition(), id));
    } else {
        registerAdvisor(pc, interceptor, metadataSource, source, element.getAttribute(ATT_ADVICE_ORDER));
        AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(pc, element);
    }

    pc.popAndRegisterContainingComponent();

    return null;
}

From source file:org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser.java

/**
 * Register the default AccessDecisionManager. Adds the special JSR 250 voter jsr-250
 * is enabled and an expression voter if expression-based access control is enabled.
 * @return/*from www . j  a v a 2  s  .c o  m*/
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private String registerAccessManager(ParserContext pc, boolean jsr250Enabled, BeanDefinition expressionVoter) {

    BeanDefinitionBuilder accessMgrBuilder = BeanDefinitionBuilder.rootBeanDefinition(AffirmativeBased.class);
    ManagedList voters = new ManagedList(4);

    if (expressionVoter != null) {
        voters.add(expressionVoter);
    }
    voters.add(new RootBeanDefinition(RoleVoter.class));
    voters.add(new RootBeanDefinition(AuthenticatedVoter.class));

    if (jsr250Enabled) {
        voters.add(new RootBeanDefinition(Jsr250Voter.class));
    }

    accessMgrBuilder.addConstructorArgValue(voters);

    BeanDefinition accessManager = accessMgrBuilder.getBeanDefinition();
    String id = pc.getReaderContext().generateBeanName(accessManager);
    pc.registerBeanComponent(new BeanComponentDefinition(accessManager, id));

    return id;
}

From source file:org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser.java

@SuppressWarnings("rawtypes")
private BeanReference registerDelegatingMethodSecurityMetadataSource(ParserContext pc, ManagedList delegates,
        Object source) {/*from w w w.  ja  v a  2s . c o m*/
    RootBeanDefinition delegatingMethodSecurityMetadataSource = new RootBeanDefinition(
            DelegatingMethodSecurityMetadataSource.class);
    delegatingMethodSecurityMetadataSource.setSource(source);
    delegatingMethodSecurityMetadataSource.getConstructorArgumentValues().addGenericArgumentValue(delegates);

    String id = pc.getReaderContext().generateBeanName(delegatingMethodSecurityMetadataSource);
    pc.registerBeanComponent(new BeanComponentDefinition(delegatingMethodSecurityMetadataSource, id));

    return new RuntimeBeanReference(id);
}

From source file:org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser.java

private BeanReference registerMethodSecurityInterceptor(ParserContext pc, String authMgrRef,
        String accessManagerId, String runAsManagerId, BeanReference metadataSource,
        List<BeanMetadataElement> afterInvocationProviders, Object source, boolean useAspectJ) {
    BeanDefinitionBuilder bldr = BeanDefinitionBuilder.rootBeanDefinition(
            useAspectJ ? AspectJMethodSecurityInterceptor.class : MethodSecurityInterceptor.class);
    bldr.getRawBeanDefinition().setSource(source);
    bldr.addPropertyReference("accessDecisionManager", accessManagerId);
    RootBeanDefinition authMgr = new RootBeanDefinition(AuthenticationManagerDelegator.class);
    authMgr.getConstructorArgumentValues().addGenericArgumentValue(authMgrRef);
    bldr.addPropertyValue("authenticationManager", authMgr);
    bldr.addPropertyValue("securityMetadataSource", metadataSource);

    if (StringUtils.hasText(runAsManagerId)) {
        bldr.addPropertyReference("runAsManager", runAsManagerId);
    }/*from   ww w . j  a va2s.c o m*/

    if (!afterInvocationProviders.isEmpty()) {
        BeanDefinition afterInvocationManager;
        afterInvocationManager = new RootBeanDefinition(AfterInvocationProviderManager.class);
        afterInvocationManager.getPropertyValues().addPropertyValue("providers", afterInvocationProviders);
        bldr.addPropertyValue("afterInvocationManager", afterInvocationManager);
    }

    BeanDefinition bean = bldr.getBeanDefinition();
    String id = pc.getReaderContext().generateBeanName(bean);
    pc.registerBeanComponent(new BeanComponentDefinition(bean, id));

    return new RuntimeBeanReference(id);
}

From source file:org.springframework.yarn.config.ConfiguringBeanFactoryPostProcessor.java

/**
 * Register task scheduler.//from w ww.j  av a 2s  .com
 *
 * @param registry the registry
 */
private void registerTaskScheduler(BeanDefinitionRegistry registry) {
    if (log.isInfoEnabled()) {
        log.info("No bean named '" + YarnContextUtils.TASK_SCHEDULER_BEAN_NAME
                + "' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.");
    }
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ThreadPoolTaskScheduler.class);
    builder.addPropertyValue("poolSize", 10);
    builder.addPropertyValue("threadNamePrefix", "task-scheduler-");
    builder.addPropertyValue("rejectedExecutionHandler", new CallerRunsPolicy());
    BeanComponentDefinition schedulerComponent = new BeanComponentDefinition(builder.getBeanDefinition(),
            YarnContextUtils.TASK_SCHEDULER_BEAN_NAME);
    BeanDefinitionReaderUtils.registerBeanDefinition(schedulerComponent, registry);
}

From source file:org.springframework.yarn.config.ConfiguringBeanFactoryPostProcessor.java

/**
 * Register task executor.//  www  .ja  v a 2s .  c o m
 *
 * @param registry the registry
 */
private void registerTaskExecutor(BeanDefinitionRegistry registry) {
    if (log.isInfoEnabled()) {
        log.info("No bean named '" + YarnContextUtils.TASK_EXECUTOR_BEAN_NAME
                + "' has been explicitly defined. Therefore, a default SyncTaskExecutor will be created.");
    }
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SyncTaskExecutor.class);
    BeanComponentDefinition schedulerComponent = new BeanComponentDefinition(builder.getBeanDefinition(),
            YarnContextUtils.TASK_EXECUTOR_BEAN_NAME);
    BeanDefinitionReaderUtils.registerBeanDefinition(schedulerComponent, registry);
}