Example usage for org.springframework.security.config Elements OPENID_ATTRIBUTE_EXCHANGE

List of usage examples for org.springframework.security.config Elements OPENID_ATTRIBUTE_EXCHANGE

Introduction

In this page you can find the example usage for org.springframework.security.config Elements OPENID_ATTRIBUTE_EXCHANGE.

Prototype

String OPENID_ATTRIBUTE_EXCHANGE

To view the source code for org.springframework.security.config Elements OPENID_ATTRIBUTE_EXCHANGE.

Click Source Link

Usage

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

void createOpenIDLoginFilter(BeanReference sessionStrategy, BeanReference authManager) {
    Element openIDLoginElt = DomUtils.getChildElementByTagName(httpElt, Elements.OPENID_LOGIN);
    RootBeanDefinition openIDFilter = null;

    if (openIDLoginElt != null) {
        FormLoginBeanDefinitionParser parser = new FormLoginBeanDefinitionParser("/login/openid", null,
                OPEN_ID_AUTHENTICATION_PROCESSING_FILTER_CLASS, requestCache, sessionStrategy,
                allowSessionCreation, portMapper, portResolver);

        parser.parse(openIDLoginElt, pc);
        openIDFilter = parser.getFilterBean();
        openIDEntryPoint = parser.getEntryPointBean();
        openidLoginProcessingUrl = parser.getLoginProcessingUrl();
        openIDLoginPage = parser.getLoginPage();

        List<Element> attrExElts = DomUtils.getChildElementsByTagName(openIDLoginElt,
                Elements.OPENID_ATTRIBUTE_EXCHANGE);

        if (!attrExElts.isEmpty()) {
            // Set up the consumer with the required attribute list
            BeanDefinitionBuilder consumerBldr = BeanDefinitionBuilder
                    .rootBeanDefinition(OPEN_ID_CONSUMER_CLASS);
            BeanDefinitionBuilder axFactory = BeanDefinitionBuilder
                    .rootBeanDefinition(OPEN_ID_ATTRIBUTE_FACTORY_CLASS);
            ManagedMap<String, ManagedList<BeanDefinition>> axMap = new ManagedMap<String, ManagedList<BeanDefinition>>();

            for (Element attrExElt : attrExElts) {
                String identifierMatch = attrExElt.getAttribute("identifier-match");

                if (!StringUtils.hasText(identifierMatch)) {
                    if (attrExElts.size() > 1) {
                        pc.getReaderContext()
                                .error("You must supply an identifier-match attribute if using more"
                                        + " than one " + Elements.OPENID_ATTRIBUTE_EXCHANGE + " element",
                                        attrExElt);
                    }/*from   w  w  w . j  a  va2s  .  c  o  m*/
                    // Match anything
                    identifierMatch = ".*";
                }

                axMap.put(identifierMatch, parseOpenIDAttributes(attrExElt));
            }
            axFactory.addConstructorArgValue(axMap);

            consumerBldr.addConstructorArgValue(axFactory.getBeanDefinition());
            openIDFilter.getPropertyValues().addPropertyValue("consumer", consumerBldr.getBeanDefinition());
        }
    }

    if (openIDFilter != null) {
        openIDFilter.getPropertyValues().addPropertyValue("allowSessionCreation", allowSessionCreation);
        openIDFilter.getPropertyValues().addPropertyValue("authenticationManager", authManager);
        // Required by login page filter
        openIDFilterId = pc.getReaderContext().generateBeanName(openIDFilter);
        pc.registerBeanComponent(new BeanComponentDefinition(openIDFilter, openIDFilterId));
        injectRememberMeServicesRef(openIDFilter, rememberMeServicesId);

        createOpenIDProvider();
    }
}