Search in sources :

Example 21 with RuntimeBeanReference

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

the class ClearCredentialsMethodInvokingFactoryBean method createPortResolver.

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

Example 22 with RuntimeBeanReference

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

the class LogoutBeanDefinitionParser method parse.

public BeanDefinition parse(Element element, ParserContext pc) {
    String logoutUrl = null;
    String successHandlerRef = null;
    String logoutSuccessUrl = null;
    String invalidateSession = null;
    String deleteCookies = null;
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(LogoutFilter.class);
    if (element != null) {
        Object source = pc.extractSource(element);
        builder.getRawBeanDefinition().setSource(source);
        logoutUrl = element.getAttribute(ATT_LOGOUT_URL);
        successHandlerRef = element.getAttribute(ATT_LOGOUT_HANDLER);
        WebConfigUtils.validateHttpRedirect(logoutUrl, pc, source);
        logoutSuccessUrl = element.getAttribute(ATT_LOGOUT_SUCCESS_URL);
        WebConfigUtils.validateHttpRedirect(logoutSuccessUrl, pc, source);
        invalidateSession = element.getAttribute(ATT_INVALIDATE_SESSION);
        deleteCookies = element.getAttribute(ATT_DELETE_COOKIES);
    }
    if (!StringUtils.hasText(logoutUrl)) {
        logoutUrl = DEF_LOGOUT_URL;
    }
    builder.addPropertyValue("logoutRequestMatcher", getLogoutRequestMatcher(logoutUrl));
    if (StringUtils.hasText(successHandlerRef)) {
        if (StringUtils.hasText(logoutSuccessUrl)) {
            pc.getReaderContext().error("Use " + ATT_LOGOUT_SUCCESS_URL + " or " + ATT_LOGOUT_HANDLER + ", but not both", pc.extractSource(element));
        }
        builder.addConstructorArgReference(successHandlerRef);
    } else {
        // Use the logout URL if no handler set
        if (!StringUtils.hasText(logoutSuccessUrl)) {
            logoutSuccessUrl = defaultLogoutUrl;
        }
        builder.addConstructorArgValue(logoutSuccessUrl);
    }
    BeanDefinition sclh = new RootBeanDefinition(SecurityContextLogoutHandler.class);
    sclh.getPropertyValues().addPropertyValue("invalidateHttpSession", !"false".equals(invalidateSession));
    logoutHandlers.add(sclh);
    if (rememberMeServices != null) {
        logoutHandlers.add(new RuntimeBeanReference(rememberMeServices));
    }
    if (StringUtils.hasText(deleteCookies)) {
        BeanDefinition cookieDeleter = new RootBeanDefinition(CookieClearingLogoutHandler.class);
        String[] names = StringUtils.tokenizeToStringArray(deleteCookies, ",");
        cookieDeleter.getConstructorArgumentValues().addGenericArgumentValue(names);
        logoutHandlers.add(cookieDeleter);
    }
    builder.addConstructorArgValue(logoutHandlers);
    return builder.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) 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 23 with RuntimeBeanReference

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

the class PasswordEncoderParser method parse.

private void parse(Element element, ParserContext parserContext) {
    String hash = element.getAttribute(ATT_HASH);
    boolean useBase64 = false;
    if (StringUtils.hasText(element.getAttribute(ATT_BASE_64))) {
        useBase64 = Boolean.valueOf(element.getAttribute(ATT_BASE_64)).booleanValue();
    }
    String ref = element.getAttribute(ATT_REF);
    if (StringUtils.hasText(ref)) {
        passwordEncoder = new RuntimeBeanReference(ref);
    } else {
        passwordEncoder = createPasswordEncoderBeanDefinition(hash, useBase64);
        ((RootBeanDefinition) passwordEncoder).setSource(parserContext.extractSource(element));
    }
    Element saltSourceElt = DomUtils.getChildElementByTagName(element, Elements.SALT_SOURCE);
    if (saltSourceElt != null) {
        if (OPT_HASH_BCRYPT.equals(hash)) {
            parserContext.getReaderContext().error(Elements.SALT_SOURCE + " isn't compatible with bcrypt", parserContext.extractSource(saltSourceElt));
        } else {
            saltSource = new SaltSourceBeanDefinitionParser().parse(saltSourceElt, parserContext);
        }
    }
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 24 with RuntimeBeanReference

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

the class AuthenticationConfigBuilder method createRememberMeProvider.

private void createRememberMeProvider(String key) {
    RootBeanDefinition provider = new RootBeanDefinition(RememberMeAuthenticationProvider.class);
    provider.setSource(rememberMeFilter.getSource());
    provider.getConstructorArgumentValues().addGenericArgumentValue(key);
    String id = pc.getReaderContext().generateBeanName(provider);
    pc.registerBeanComponent(new BeanComponentDefinition(provider, id));
    rememberMeProviderRef = new RuntimeBeanReference(id);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 25 with RuntimeBeanReference

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

the class HeadersBeanDefinitionParser method parseHeaderElements.

private void parseHeaderElements(Element element) {
    List<Element> headerElts = element == null ? Collections.<Element>emptyList() : DomUtils.getChildElementsByTagName(element, GENERIC_HEADER_ELEMENT);
    for (Element headerElt : headerElts) {
        String headerFactoryRef = headerElt.getAttribute(ATT_REF);
        if (StringUtils.hasText(headerFactoryRef)) {
            headerWriters.add(new RuntimeBeanReference(headerFactoryRef));
        } else {
            BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(StaticHeadersWriter.class);
            builder.addConstructorArgValue(headerElt.getAttribute(ATT_NAME));
            builder.addConstructorArgValue(headerElt.getAttribute(ATT_VALUE));
            headerWriters.add(builder.getBeanDefinition());
        }
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) 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