use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class MessagingGatewayRegistrar method parse.
public BeanDefinitionHolder parse(Map<String, Object> gatewayAttributes) {
String defaultPayloadExpression = (String) gatewayAttributes.get("defaultPayloadExpression");
@SuppressWarnings("unchecked") Map<String, Object>[] defaultHeaders = (Map<String, Object>[]) gatewayAttributes.get("defaultHeaders");
String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel");
String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel");
String errorChannel = (String) gatewayAttributes.get("errorChannel");
String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor");
String mapper = (String) gatewayAttributes.get("mapper");
boolean hasMapper = StringUtils.hasText(mapper);
boolean hasDefaultPayloadExpression = StringUtils.hasText(defaultPayloadExpression);
Assert.state(!hasMapper || !hasDefaultPayloadExpression, "'defaultPayloadExpression' is not allowed when a 'mapper' is provided");
boolean hasDefaultHeaders = !ObjectUtils.isEmpty(defaultHeaders);
Assert.state(!hasMapper || !hasDefaultHeaders, "'defaultHeaders' are not allowed when a 'mapper' is provided");
BeanDefinitionBuilder gatewayProxyBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayProxyFactoryBean.class);
if (hasDefaultHeaders || hasDefaultPayloadExpression) {
BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayMethodMetadata.class);
if (hasDefaultPayloadExpression) {
methodMetadataBuilder.addPropertyValue("payloadExpression", defaultPayloadExpression);
}
Map<String, Object> headerExpressions = new ManagedMap<String, Object>();
for (Map<String, Object> header : defaultHeaders) {
String headerValue = (String) header.get("value");
String headerExpression = (String) header.get("expression");
boolean hasValue = StringUtils.hasText(headerValue);
if (hasValue == StringUtils.hasText(headerExpression)) {
throw new BeanDefinitionStoreException("exactly one of 'value' or 'expression' " + "is required on a gateway's header.");
}
BeanDefinition expressionDef = new RootBeanDefinition(hasValue ? LiteralExpression.class : ExpressionFactoryBean.class);
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(hasValue ? headerValue : headerExpression);
headerExpressions.put((String) header.get("name"), expressionDef);
}
methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
gatewayProxyBuilder.addPropertyValue("globalMethodMetadata", methodMetadataBuilder.getBeanDefinition());
}
if (StringUtils.hasText(defaultRequestChannel)) {
gatewayProxyBuilder.addPropertyValue("defaultRequestChannelName", defaultRequestChannel);
}
if (StringUtils.hasText(defaultReplyChannel)) {
gatewayProxyBuilder.addPropertyValue("defaultReplyChannelName", defaultReplyChannel);
}
if (StringUtils.hasText(errorChannel)) {
gatewayProxyBuilder.addPropertyValue("errorChannelName", errorChannel);
}
if (asyncExecutor == null || AnnotationConstants.NULL.equals(asyncExecutor)) {
gatewayProxyBuilder.addPropertyValue("asyncExecutor", null);
} else if (StringUtils.hasText(asyncExecutor)) {
gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor);
}
if (StringUtils.hasText(mapper)) {
gatewayProxyBuilder.addPropertyReference("mapper", mapper);
}
gatewayProxyBuilder.addPropertyValue("defaultRequestTimeoutExpressionString", gatewayAttributes.get("defaultRequestTimeout"));
gatewayProxyBuilder.addPropertyValue("defaultReplyTimeoutExpressionString", gatewayAttributes.get("defaultReplyTimeout"));
gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods"));
String serviceInterface = (String) gatewayAttributes.get("serviceInterface");
if (!StringUtils.hasText(serviceInterface)) {
serviceInterface = "org.springframework.integration.gateway.RequestReplyExchanger";
}
String id = (String) gatewayAttributes.get("name");
if (!StringUtils.hasText(id)) {
id = Introspector.decapitalize(serviceInterface.substring(serviceInterface.lastIndexOf(".") + 1));
}
gatewayProxyBuilder.addConstructorArgValue(serviceInterface);
AbstractBeanDefinition beanDefinition = gatewayProxyBuilder.getBeanDefinition();
beanDefinition.addMetadataAttribute(new BeanMetadataAttribute(IntegrationConfigUtils.FACTORY_BEAN_OBJECT_TYPE, serviceInterface));
return new BeanDefinitionHolder(beanDefinition, id);
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-security-oauth by spring-projects.
the class ConfigUtils method createSecurityMetadataSource.
public static BeanDefinition createSecurityMetadataSource(Element element, ParserContext pc) {
List<Element> filterPatterns = DomUtils.getChildElementsByTagName(element, "url");
if (filterPatterns.isEmpty()) {
return null;
}
// TODO : add support for lowercase-comparisons
String patternType = element.getAttribute("path-type");
if (!StringUtils.hasText(patternType)) {
patternType = "ant";
}
MatcherType matcherType = MatcherType.valueOf(patternType);
ManagedMap<BeanDefinition, BeanDefinition> invocationDefinitionMap = new ManagedMap<BeanDefinition, BeanDefinition>();
for (Element filterPattern : filterPatterns) {
String path = filterPattern.getAttribute("pattern");
if (!StringUtils.hasText(path)) {
pc.getReaderContext().error("pattern attribute cannot be empty or null", filterPattern);
}
String method = filterPattern.getAttribute("httpMethod");
if (!StringUtils.hasText(method)) {
method = null;
}
String access = filterPattern.getAttribute("resources");
if (StringUtils.hasText(access)) {
BeanDefinition matcher;
if (createMatcherMethod4x != null) {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod4x, matcherType, pc, path, method);
} else {
matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod3x, matcherType, path, method);
}
if (access.equals("none")) {
invocationDefinitionMap.put(matcher, BeanDefinitionBuilder.rootBeanDefinition(Collections.class).setFactoryMethod("emptyList").getBeanDefinition());
} else {
BeanDefinitionBuilder attributeBuilder = BeanDefinitionBuilder.rootBeanDefinition(SecurityConfig.class);
attributeBuilder.addConstructorArgValue(access);
attributeBuilder.setFactoryMethod("createListFromCommaDelimitedString");
if (invocationDefinitionMap.containsKey(matcher)) {
pc.getReaderContext().warning("Duplicate URL defined: " + path + ". The original attribute values will be overwritten", pc.extractSource(filterPattern));
}
invocationDefinitionMap.put(matcher, attributeBuilder.getBeanDefinition());
}
}
}
BeanDefinitionBuilder fidsBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultFilterInvocationSecurityMetadataSource.class);
fidsBuilder.addConstructorArgValue(invocationDefinitionMap);
fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(element));
return fidsBuilder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-security-oauth by spring-projects.
the class ClientDetailsServiceBeanDefinitionParser method doParse.
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
List<Element> clientElements = DomUtils.getChildElementsByTagName(element, "client");
ManagedMap<String, BeanMetadataElement> clients = new ManagedMap<String, BeanMetadataElement>();
for (Element clientElement : clientElements) {
BeanDefinitionBuilder client = BeanDefinitionBuilder.rootBeanDefinition(BaseClientDetails.class);
String clientId = clientElement.getAttribute("client-id");
if (StringUtils.hasText(clientId)) {
client.addConstructorArgValue(clientId);
} else {
parserContext.getReaderContext().error("A client id must be supplied with the definition of a client.", clientElement);
}
String secret = clientElement.getAttribute("secret");
if (StringUtils.hasText(secret)) {
client.addPropertyValue("clientSecret", secret);
}
String resourceIds = clientElement.getAttribute("resource-ids");
if (StringUtils.hasText(clientId)) {
client.addConstructorArgValue(resourceIds);
} else {
client.addConstructorArgValue("");
}
String redirectUri = clientElement.getAttribute("redirect-uri");
String tokenValidity = clientElement.getAttribute("access-token-validity");
if (StringUtils.hasText(tokenValidity)) {
client.addPropertyValue("accessTokenValiditySeconds", tokenValidity);
}
String refreshValidity = clientElement.getAttribute("refresh-token-validity");
if (StringUtils.hasText(refreshValidity)) {
client.addPropertyValue("refreshTokenValiditySeconds", refreshValidity);
}
client.addConstructorArgValue(clientElement.getAttribute("scope"));
client.addConstructorArgValue(clientElement.getAttribute("authorized-grant-types"));
client.addConstructorArgValue(clientElement.getAttribute("authorities"));
if (StringUtils.hasText(redirectUri)) {
client.addConstructorArgValue(redirectUri);
}
client.addPropertyValue("autoApproveScopes", clientElement.getAttribute("autoapprove"));
clients.put(clientId, client.getBeanDefinition());
}
builder.addPropertyValue("clientDetailsStore", clients);
}
use of org.springframework.beans.factory.support.ManagedMap in project mule by mulesoft.
the class FlowRefFactoryBean method processBeanValue.
private void processBeanValue(String rootContainerName, Object value) {
if (value instanceof BeanDefinition) {
updateBeanDefinitionRootContainerName(rootContainerName, (BeanDefinition) value);
} else if (value instanceof ManagedList) {
ManagedList managedList = (ManagedList) value;
for (Object itemValue : managedList) {
if (itemValue instanceof BeanDefinition) {
updateBeanDefinitionRootContainerName(rootContainerName, (BeanDefinition) itemValue);
}
}
} else if (value instanceof ManagedMap) {
ManagedMap managedMap = (ManagedMap) value;
managedMap.forEach((key, mapValue) -> processBeanValue(rootContainerName, mapValue));
}
}
use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.
the class MessagingGatewayRegistrar method parse.
public BeanDefinitionHolder parse(Map<String, Object> gatewayAttributes, BeanDefinitionRegistry registry) {
// NOSONAR complexity
String defaultPayloadExpression = (String) gatewayAttributes.get("defaultPayloadExpression");
@SuppressWarnings("unchecked") Map<String, Object>[] defaultHeaders = (Map<String, Object>[]) gatewayAttributes.get("defaultHeaders");
String defaultRequestChannel = (String) gatewayAttributes.get("defaultRequestChannel");
String defaultReplyChannel = (String) gatewayAttributes.get("defaultReplyChannel");
String errorChannel = (String) gatewayAttributes.get("errorChannel");
String asyncExecutor = (String) gatewayAttributes.get("asyncExecutor");
String mapper = (String) gatewayAttributes.get("mapper");
String proxyDefaultMethods = (String) gatewayAttributes.get(PROXY_DEFAULT_METHODS_ATTR);
boolean hasMapper = StringUtils.hasText(mapper);
boolean hasDefaultPayloadExpression = StringUtils.hasText(defaultPayloadExpression);
Assert.state(!hasMapper || !hasDefaultPayloadExpression, "'defaultPayloadExpression' is not allowed when a 'mapper' is provided");
boolean hasDefaultHeaders = !ObjectUtils.isEmpty(defaultHeaders);
Assert.state(!hasMapper || !hasDefaultHeaders, "'defaultHeaders' are not allowed when a 'mapper' is provided");
ConfigurableBeanFactory beanFactory = obtainBeanFactory(registry);
Class<?> serviceInterface = getServiceInterface((String) gatewayAttributes.get("serviceInterface"), beanFactory);
BeanDefinitionBuilder gatewayProxyBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayProxyFactoryBean.class, () -> new GatewayProxyFactoryBean(serviceInterface));
if (hasDefaultHeaders || hasDefaultPayloadExpression) {
BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayMethodMetadata.class, GatewayMethodMetadata::new);
if (hasDefaultPayloadExpression) {
methodMetadataBuilder.addPropertyValue("payloadExpression", BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class).addConstructorArgValue(defaultPayloadExpression).getBeanDefinition());
}
if (hasDefaultHeaders) {
Map<String, Object> headerExpressions = new ManagedMap<>();
for (Map<String, Object> header : defaultHeaders) {
String headerValue = (String) header.get("value");
String headerExpression = (String) header.get("expression");
boolean hasValue = StringUtils.hasText(headerValue);
if (hasValue == StringUtils.hasText(headerExpression)) {
throw new BeanDefinitionStoreException("exactly one of 'value' or 'expression' " + "is required on a gateway's header.");
}
BeanDefinition expressionDef = new RootBeanDefinition(hasValue ? LiteralExpression.class : ExpressionFactoryBean.class);
expressionDef.getConstructorArgumentValues().addGenericArgumentValue(hasValue ? headerValue : headerExpression);
headerExpressions.put((String) header.get("name"), expressionDef);
}
methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
}
gatewayProxyBuilder.addPropertyValue("globalMethodMetadata", methodMetadataBuilder.getBeanDefinition());
}
if (StringUtils.hasText(defaultRequestChannel)) {
gatewayProxyBuilder.addPropertyValue("defaultRequestChannelName", defaultRequestChannel);
}
if (StringUtils.hasText(defaultReplyChannel)) {
gatewayProxyBuilder.addPropertyValue("defaultReplyChannelName", defaultReplyChannel);
}
if (StringUtils.hasText(errorChannel)) {
gatewayProxyBuilder.addPropertyValue("errorChannelName", errorChannel);
}
if (asyncExecutor == null || AnnotationConstants.NULL.equals(asyncExecutor)) {
gatewayProxyBuilder.addPropertyValue("asyncExecutor", null);
} else if (StringUtils.hasText(asyncExecutor)) {
gatewayProxyBuilder.addPropertyReference("asyncExecutor", asyncExecutor);
}
if (StringUtils.hasText(mapper)) {
gatewayProxyBuilder.addPropertyReference("mapper", mapper);
}
if (StringUtils.hasText(proxyDefaultMethods)) {
gatewayProxyBuilder.addPropertyValue(PROXY_DEFAULT_METHODS_ATTR, proxyDefaultMethods);
}
gatewayProxyBuilder.addPropertyValue("defaultRequestTimeoutExpressionString", gatewayAttributes.get("defaultRequestTimeout"));
gatewayProxyBuilder.addPropertyValue("defaultReplyTimeoutExpressionString", gatewayAttributes.get("defaultReplyTimeout"));
gatewayProxyBuilder.addPropertyValue("methodMetadataMap", gatewayAttributes.get("methods"));
String id = (String) gatewayAttributes.get("name");
if (!StringUtils.hasText(id)) {
String serviceInterfaceName = serviceInterface.getName();
id = Introspector.decapitalize(serviceInterfaceName.substring(serviceInterfaceName.lastIndexOf('.') + 1));
}
gatewayProxyBuilder.addConstructorArgValue(serviceInterface);
AbstractBeanDefinition beanDefinition = gatewayProxyBuilder.getBeanDefinition();
beanDefinition.setAttribute(FactoryBean.OBJECT_TYPE_ATTRIBUTE, serviceInterface);
return new BeanDefinitionHolder(beanDefinition, id);
}
Aggregations