Search in sources :

Example 21 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition 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 22 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition 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 23 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-security by spring-projects.

the class AuthenticationConfigBuilder method createX509Filter.

void createX509Filter(BeanReference authManager) {
    Element x509Elt = DomUtils.getChildElementByTagName(httpElt, Elements.X509);
    RootBeanDefinition filter = null;
    if (x509Elt != null) {
        BeanDefinitionBuilder filterBuilder = BeanDefinitionBuilder.rootBeanDefinition(X509AuthenticationFilter.class);
        filterBuilder.getRawBeanDefinition().setSource(pc.extractSource(x509Elt));
        filterBuilder.addPropertyValue("authenticationManager", authManager);
        String regex = x509Elt.getAttribute("subject-principal-regex");
        if (StringUtils.hasText(regex)) {
            BeanDefinitionBuilder extractor = BeanDefinitionBuilder.rootBeanDefinition(SubjectDnX509PrincipalExtractor.class);
            extractor.addPropertyValue("subjectDnRegex", regex);
            filterBuilder.addPropertyValue("principalExtractor", extractor.getBeanDefinition());
        }
        injectAuthenticationDetailsSource(x509Elt, filterBuilder);
        filter = (RootBeanDefinition) filterBuilder.getBeanDefinition();
        createPrauthEntryPoint(x509Elt);
        createX509Provider();
    }
    x509Filter = filter;
}
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)

Example 24 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition 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)

Example 25 with RootBeanDefinition

use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-security by spring-projects.

the class AuthenticationConfigBuilder method createPrauthEntryPoint.

private void createPrauthEntryPoint(Element source) {
    if (preAuthEntryPoint == null) {
        preAuthEntryPoint = new RootBeanDefinition(Http403ForbiddenEntryPoint.class);
        preAuthEntryPoint.setSource(pc.extractSource(source));
    }
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Http403ForbiddenEntryPoint(org.springframework.security.web.authentication.Http403ForbiddenEntryPoint)

Aggregations

RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)704 Test (org.junit.Test)522 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)311 TestBean (org.springframework.tests.sample.beans.TestBean)159 ITestBean (org.springframework.tests.sample.beans.ITestBean)143 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)133 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)85 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)80 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)77 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)77 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)47 Element (org.w3c.dom.Element)47 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)46 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)36 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)31 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)30 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)30 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)28 Properties (java.util.Properties)26 ManagedList (org.springframework.beans.factory.support.ManagedList)25