Search in sources :

Example 21 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project sharding-jdbc by shardingjdbc.

the class ShardingDataSourceBeanDefinitionParser method parseDataSources.

private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
    Element shardingRuleElement = DomUtils.getChildElementByTagName(element, ShardingDataSourceBeanDefinitionParserTag.SHARDING_RULE_CONFIG_TAG);
    List<String> dataSources = Splitter.on(",").trimResults().splitToList(shardingRuleElement.getAttribute(ShardingDataSourceBeanDefinitionParserTag.DATA_SOURCE_NAMES_TAG));
    Map<String, RuntimeBeanReference> result = new ManagedMap<>(dataSources.size());
    for (String each : dataSources) {
        result.put(each, new RuntimeBeanReference(each));
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 22 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceBeanDefinitionParser method parseDataSources.

private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
    Element shardingRuleElement = DomUtils.getChildElementByTagName(element, ShardingDataSourceBeanDefinitionParserTag.SHARDING_RULE_CONFIG_TAG);
    List<String> dataSources = Splitter.on(",").trimResults().splitToList(shardingRuleElement.getAttribute(ShardingDataSourceBeanDefinitionParserTag.DATA_SOURCE_NAMES_TAG));
    Map<String, RuntimeBeanReference> result = new ManagedMap<>(dataSources.size());
    for (String each : dataSources) {
        result.put(each, new RuntimeBeanReference(each));
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 23 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project mule by mulesoft.

the class PropertyComponentUtils method getPropertyValueFromPropertyComponent.

/**
 * Creates a {@link Pair} from a generic property/ies component in the configuration.
 *
 * @param propertyComponentModel the component model for spring:property, spring:properties or property.
 * @return a {@code PropertyValue} with the parsed content of the component.
 */
public static Pair<String, Object> getPropertyValueFromPropertyComponent(ComponentModel propertyComponentModel) {
    Pair<String, Object> propertyValue;
    String refKey = getReferenceAttributeName(propertyComponentModel.getIdentifier());
    String nameKey = getNameAttributeName(propertyComponentModel.getIdentifier());
    if (propertyComponentModel.getInnerComponents().isEmpty()) {
        Object value;
        if (propertyComponentModel.getParameters().containsKey(refKey)) {
            value = new RuntimeBeanReference(propertyComponentModel.getParameters().get(refKey));
        } else {
            value = propertyComponentModel.getParameters().get(VALUE_PARAMETER_NAME);
        }
        if (!propertyComponentModel.getParameters().containsKey(nameKey)) {
            propertyValue = new Pair<>(PROPERTY_NAME_PROPERTY_ATTRIBUTE, new RuntimeBeanReference(propertyComponentModel.getParameters().get("ref")));
        } else {
            propertyValue = new Pair<>(propertyComponentModel.getParameters().get(nameKey), value);
        }
    } else if (propertyComponentModel.getInnerComponents().get(0).getIdentifier().getName().equals("map")) {
        ComponentModel springMap = propertyComponentModel.getInnerComponents().get(0);
        ManagedMap<String, Object> propertiesMap = new ManagedMap<>();
        springMap.getInnerComponents().stream().forEach(mapEntry -> {
            Object value;
            if (mapEntry.getParameters().containsKey(VALUE_PARAMETER_NAME)) {
                value = mapEntry.getParameters().get(VALUE_PARAMETER_NAME);
            } else {
                value = new RuntimeBeanReference(mapEntry.getParameters().get(REFERENCE_MULE_PROPERTY_ATTRIBUTE));
            }
            propertiesMap.put(mapEntry.getParameters().get(PROPERTY_NAME_MULE_PROPERTY_ATTRIBUTE), value);
        });
        propertyValue = new Pair<>(propertyComponentModel.getNameAttribute(), propertiesMap);
    } else {
        throw new MuleRuntimeException(createStaticMessage("Unrecognized property model identifier: " + propertyComponentModel.getInnerComponents().get(0).getIdentifier()));
    }
    return propertyValue;
}
Also used : MULE_PROPERTY_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTY_IDENTIFIER) ManagedMap(org.springframework.beans.factory.support.ManagedMap) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) Pair(org.mule.runtime.api.util.Pair) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Pair(org.mule.runtime.api.util.Pair)

Example 24 with ManagedMap

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

the class HttpConfigurationBuilder method parseInterceptUrlsForChannelSecurity.

/**
 * Parses the intercept-url elements to obtain the map used by channel security. This
 * will be empty unless the <tt>requires-channel</tt> attribute has been used on a URL
 * path.
 */
private ManagedMap<BeanMetadataElement, BeanDefinition> parseInterceptUrlsForChannelSecurity() {
    ManagedMap<BeanMetadataElement, BeanDefinition> channelRequestMap = new ManagedMap<>();
    for (Element urlElt : this.interceptUrls) {
        String path = urlElt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN);
        String method = urlElt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_HTTP_METHOD);
        String matcherRef = urlElt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_REQUEST_MATCHER_REF);
        boolean hasMatcherRef = StringUtils.hasText(matcherRef);
        if (!hasMatcherRef && !StringUtils.hasText(path)) {
            this.pc.getReaderContext().error("pattern attribute cannot be empty or null", urlElt);
        }
        String requiredChannel = urlElt.getAttribute(HttpSecurityBeanDefinitionParser.ATT_REQUIRES_CHANNEL);
        if (StringUtils.hasText(requiredChannel)) {
            BeanMetadataElement matcher = hasMatcherRef ? new RuntimeBeanReference(matcherRef) : this.matcherType.createMatcher(this.pc, path, method);
            RootBeanDefinition channelAttributes = new RootBeanDefinition(ChannelAttributeFactory.class);
            channelAttributes.getConstructorArgumentValues().addGenericArgumentValue(requiredChannel);
            channelAttributes.setFactoryMethodName("createChannelAttributes");
            channelRequestMap.put(matcher, channelAttributes);
        }
    }
    return channelRequestMap;
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) 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) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 25 with ManagedMap

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

the class CsrfBeanDefinitionParser method createAccessDeniedHandler.

/**
 * Creates the {@link AccessDeniedHandler} from the result of
 * {@link #getDefaultAccessDeniedHandler(HttpSecurityBuilder)} and
 * {@link #getInvalidSessionStrategy(HttpSecurityBuilder)}. If
 * {@link #getInvalidSessionStrategy(HttpSecurityBuilder)} is non-null, then a
 * {@link DelegatingAccessDeniedHandler} is used in combination with
 * {@link InvalidSessionAccessDeniedHandler} and the
 * {@link #getDefaultAccessDeniedHandler(HttpSecurityBuilder)}. Otherwise, only
 * {@link #getDefaultAccessDeniedHandler(HttpSecurityBuilder)} is used.
 * @param invalidSessionStrategy the {@link InvalidSessionStrategy} to use
 * @param defaultDeniedHandler the {@link AccessDeniedHandler} to use
 * @return the {@link BeanMetadataElement} that is the {@link AccessDeniedHandler} to
 * populate on the {@link CsrfFilter}
 */
private BeanMetadataElement createAccessDeniedHandler(BeanDefinition invalidSessionStrategy, BeanMetadataElement defaultDeniedHandler) {
    if (invalidSessionStrategy == null) {
        return defaultDeniedHandler;
    }
    ManagedMap<Class<? extends AccessDeniedException>, BeanDefinition> handlers = new ManagedMap<>();
    BeanDefinitionBuilder invalidSessionHandlerBldr = BeanDefinitionBuilder.rootBeanDefinition(InvalidSessionAccessDeniedHandler.class);
    invalidSessionHandlerBldr.addConstructorArgValue(invalidSessionStrategy);
    handlers.put(MissingCsrfTokenException.class, invalidSessionHandlerBldr.getBeanDefinition());
    BeanDefinitionBuilder deniedBldr = BeanDefinitionBuilder.rootBeanDefinition(DelegatingAccessDeniedHandler.class);
    deniedBldr.addConstructorArgValue(handlers);
    deniedBldr.addConstructorArgValue(defaultDeniedHandler);
    return deniedBldr.getBeanDefinition();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Aggregations

ManagedMap (org.springframework.beans.factory.support.ManagedMap)63 Element (org.w3c.dom.Element)37 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)25 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)25 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)24 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)23 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)11 Map (java.util.Map)10 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)9 HashMap (java.util.HashMap)6 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 Node (org.w3c.dom.Node)6 ManagedList (org.springframework.beans.factory.support.ManagedList)5 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 GroovyObject (groovy.lang.GroovyObject)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)3