Search in sources :

Example 11 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-security by spring-projects.

the class FilterChainMapBeanDefinitionDecorator method decorate.

@SuppressWarnings("unchecked")
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder holder, ParserContext parserContext) {
    BeanDefinition filterChainProxy = holder.getBeanDefinition();
    ManagedList<BeanMetadataElement> securityFilterChains = new ManagedList<BeanMetadataElement>();
    Element elt = (Element) node;
    MatcherType matcherType = MatcherType.fromElement(elt);
    List<Element> filterChainElts = DomUtils.getChildElementsByTagName(elt, Elements.FILTER_CHAIN);
    for (Element chain : filterChainElts) {
        String path = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN);
        String filters = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_FILTERS);
        if (!StringUtils.hasText(path)) {
            parserContext.getReaderContext().error("The attribute '" + HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN + "' must not be empty", elt);
        }
        if (!StringUtils.hasText(filters)) {
            parserContext.getReaderContext().error("The attribute '" + HttpSecurityBeanDefinitionParser.ATT_FILTERS + "'must not be empty", elt);
        }
        BeanDefinition matcher = matcherType.createMatcher(parserContext, path, null);
        if (filters.equals(HttpSecurityBeanDefinitionParser.OPT_FILTERS_NONE)) {
            securityFilterChains.add(createSecurityFilterChain(matcher, new ManagedList(0)));
        } else {
            String[] filterBeanNames = StringUtils.tokenizeToStringArray(filters, ",");
            ManagedList filterChain = new ManagedList(filterBeanNames.length);
            for (String name : filterBeanNames) {
                filterChain.add(new RuntimeBeanReference(name));
            }
            securityFilterChains.add(createSecurityFilterChain(matcher, filterChain));
        }
    }
    filterChainProxy.getConstructorArgumentValues().addGenericArgumentValue(securityFilterChains);
    return holder;
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 12 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-security by spring-projects.

the class LdapUserServiceBeanDefinitionParser method parseUserDetailsClassOrUserMapperRef.

static BeanMetadataElement parseUserDetailsClassOrUserMapperRef(Element elt, ParserContext parserContext) {
    String userDetailsClass = elt.getAttribute(ATT_USER_CLASS);
    String userMapperRef = elt.getAttribute(ATT_USER_CONTEXT_MAPPER_REF);
    if (StringUtils.hasText(userDetailsClass) && StringUtils.hasText(userMapperRef)) {
        parserContext.getReaderContext().error("Attributes " + ATT_USER_CLASS + " and " + ATT_USER_CONTEXT_MAPPER_REF + " cannot be used together.", parserContext.extractSource(elt));
    }
    if (StringUtils.hasText(userMapperRef)) {
        return new RuntimeBeanReference(userMapperRef);
    }
    RootBeanDefinition mapper;
    if (OPT_PERSON.equals(userDetailsClass)) {
        mapper = new RootBeanDefinition(PERSON_MAPPER_CLASS, null, null);
    } else if (OPT_INETORGPERSON.equals(userDetailsClass)) {
        mapper = new RootBeanDefinition(INET_ORG_PERSON_MAPPER_CLASS, null, null);
    } else {
        mapper = new RootBeanDefinition(LDAP_USER_MAPPER_CLASS, null, null);
    }
    mapper.setSource(parserContext.extractSource(elt));
    return mapper;
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 13 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-security by spring-projects.

the class GlobalMethodSecurityBeanDefinitionParser method registerMethodSecurityInterceptor.

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);
    }
    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);
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AfterInvocationProviderManager(org.springframework.security.access.intercept.AfterInvocationProviderManager) AspectJMethodSecurityInterceptor(org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AspectJMethodSecurityInterceptor(org.springframework.security.access.intercept.aspectj.AspectJMethodSecurityInterceptor) MethodSecurityInterceptor(org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 14 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-security by spring-projects.

the class AuthenticationConfigBuilder method getLogoutHandlers.

@SuppressWarnings({ "rawtypes", "unchecked" })
ManagedList getLogoutHandlers() {
    if (logoutHandlers == null && rememberMeProviderRef != null) {
        logoutHandlers = new ManagedList();
        if (csrfLogoutHandler != null) {
            logoutHandlers.add(csrfLogoutHandler);
        }
        logoutHandlers.add(new RuntimeBeanReference(rememberMeServicesId));
        logoutHandlers.add(new RootBeanDefinition(SecurityContextLogoutHandler.class));
    }
    return logoutHandlers;
}
Also used : SecurityContextLogoutHandler(org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedList(org.springframework.beans.factory.support.ManagedList) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 15 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-security by spring-projects.

the class AuthenticationConfigBuilder method createOpenIDProvider.

private void createOpenIDProvider() {
    Element openIDLoginElt = DomUtils.getChildElementByTagName(httpElt, Elements.OPENID_LOGIN);
    BeanDefinitionBuilder openIDProviderBuilder = BeanDefinitionBuilder.rootBeanDefinition(OPEN_ID_AUTHENTICATION_PROVIDER_CLASS);
    RootBeanDefinition uds = new RootBeanDefinition();
    uds.setFactoryBeanName(BeanIds.USER_DETAILS_SERVICE_FACTORY);
    uds.setFactoryMethodName("authenticationUserDetailsService");
    uds.getConstructorArgumentValues().addGenericArgumentValue(openIDLoginElt.getAttribute(ATT_USER_SERVICE_REF));
    openIDProviderBuilder.addPropertyValue("authenticationUserDetailsService", uds);
    BeanDefinition openIDProvider = openIDProviderBuilder.getBeanDefinition();
    openIDProviderRef = new RuntimeBeanReference(pc.getReaderContext().registerWithGeneratedName(openIDProvider));
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Aggregations

RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)156 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)86 Element (org.w3c.dom.Element)47 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)39 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)33 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)32 ManagedList (org.springframework.beans.factory.support.ManagedList)27 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)24 Test (org.junit.Test)21 ManagedMap (org.springframework.beans.factory.support.ManagedMap)20 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)16 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)15 GroovyObject (groovy.lang.GroovyObject)12 TestBean (org.springframework.tests.sample.beans.TestBean)12 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)11 Map (java.util.Map)10 Node (org.w3c.dom.Node)10 HashMap (java.util.HashMap)9 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)8