Remove deprecations from previous versions (#8628)

This commit is contained in:
Artem Bilan
2023-05-22 11:19:13 -04:00
committed by GitHub
parent edbaf6d590
commit ba417de680
37 changed files with 22 additions and 1929 deletions

View File

@@ -1,40 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.channel;
import java.util.Collection;
import org.springframework.security.access.ConfigAttribute;
/**
* Interface to encapsulate {@link ConfigAttribute}s for secured channel
* send and receive operations.
*
* @author Oleg Zhurakousky
* @since 2.0
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0")
public interface ChannelAccessPolicy {
Collection<ConfigAttribute> getConfigAttributesForSend();
Collection<ConfigAttribute> getConfigAttributesForReceive();
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.channel;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.util.Assert;
/**
* Secured object for {@link ChannelSecurityInterceptor}. Maintains a reference
* to the original {@link MethodInvocation} instance and provides convenient
* access to the secured {@link MessageChannel}. If the intercepted invocation
* is a <em>send</em> operation, the {@link Message} is also available.
*
* @author Mark Fisher
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0")
public class ChannelInvocation {
private final MessageChannel channel;
private final Message<?> message;
private final MethodInvocation methodInvocation;
/**
* @param methodInvocation the intercepted MethodInvocation instance
*/
public ChannelInvocation(MethodInvocation methodInvocation) {
Assert.notNull(methodInvocation, "MethodInvocation must not be null");
Assert.isAssignable(MessageChannel.class, methodInvocation.getThis().getClass(),
"MethodInvocation must be on a MessageChannel");
this.channel = (MessageChannel) methodInvocation.getThis();
if (methodInvocation.getMethod().getName().equals("send")) {
if (methodInvocation.getArguments().length < 1 || !(methodInvocation.getArguments()[0] instanceof Message<?>)) {
throw new IllegalStateException("expected a Message as the first parameter of the channel's send method");
}
this.message = (Message<?>) methodInvocation.getArguments()[0];
}
else {
this.message = null;
}
this.methodInvocation = methodInvocation;
}
public MessageChannel getChannel() {
return this.channel;
}
public Message<?> getMessage() {
return this.message;
}
public MethodInvocation getMethodInvocation() {
return this.methodInvocation;
}
public boolean isSend() {
return "send".equals(this.methodInvocation.getMethod().getName());
}
public boolean isReceive() {
return "receive".equals(this.methodInvocation.getMethod().getName());
}
}

View File

@@ -1,89 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.channel;
import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.security.access.SecurityMetadataSource;
import org.springframework.security.access.intercept.AbstractSecurityInterceptor;
import org.springframework.security.access.intercept.InterceptorStatusToken;
import org.springframework.util.Assert;
/**
* An AOP interceptor that enforces authorization for MessageChannel send and/or receive calls.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*
* @see SecuredChannel
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}.
* However, the {@link org.springframework.security.messaging.access.intercept.AuthorizationChannelInterceptor}
* can be configured with any {@link org.springframework.security.authorization.AuthorizationManager} implementation.
*/
@Deprecated(since = "6.0")
public final class ChannelSecurityInterceptor extends AbstractSecurityInterceptor implements MethodInterceptor {
private final ChannelSecurityMetadataSource securityMetadataSource;
public ChannelSecurityInterceptor() {
this(new ChannelSecurityMetadataSource());
}
public ChannelSecurityInterceptor(ChannelSecurityMetadataSource securityMetadataSource) {
Assert.notNull(securityMetadataSource, "securityMetadataSource must not be null");
this.securityMetadataSource = securityMetadataSource;
}
@Override
public Class<?> getSecureObjectClass() {
return ChannelInvocation.class;
}
@Override
public Object invoke(MethodInvocation invocation) throws Throwable { // NOSONAR
Method method = invocation.getMethod();
if (method.getName().equals("send") || method.getName().equals("receive")) {
return this.invokeWithAuthorizationCheck(invocation);
}
return invocation.proceed();
}
private Object invokeWithAuthorizationCheck(MethodInvocation methodInvocation) throws Throwable { // NOSONAR
Object returnValue = null;
InterceptorStatusToken token = super.beforeInvocation(new ChannelInvocation(methodInvocation));
try {
returnValue = methodInvocation.proceed();
}
finally {
returnValue = super.afterInvocation(token, returnValue);
}
return returnValue;
}
@Override
public SecurityMetadataSource obtainSecurityMetadataSource() {
return this.securityMetadataSource;
}
}

View File

@@ -1,110 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.channel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.springframework.integration.support.context.NamedComponent;
import org.springframework.messaging.MessageChannel;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityMetadataSource;
import org.springframework.util.Assert;
/**
* The {@link SecurityMetadataSource} implementation for secured {@link MessageChannel}s.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0")
public class ChannelSecurityMetadataSource implements SecurityMetadataSource {
private final Map<Pattern, ChannelAccessPolicy> patternMappings;
public ChannelSecurityMetadataSource() {
this(null);
}
public ChannelSecurityMetadataSource(Map<Pattern, ChannelAccessPolicy> patternMappings) {
this.patternMappings = (patternMappings != null) ? patternMappings
: new LinkedHashMap<Pattern, ChannelAccessPolicy>();
}
public void addPatternMapping(Pattern pattern, ChannelAccessPolicy accessPolicy) {
this.patternMappings.put(pattern, accessPolicy);
}
public Set<Pattern> getPatterns() {
return this.patternMappings.keySet();
}
public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
Assert.isAssignable(ChannelInvocation.class, object.getClass());
ChannelInvocation invocation = (ChannelInvocation) object;
MessageChannel channel = invocation.getChannel();
Assert.isAssignable(NamedComponent.class, channel.getClass());
String channelName = ((NamedComponent) channel).getComponentName();
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();
for (Map.Entry<Pattern, ChannelAccessPolicy> mapping : this.patternMappings.entrySet()) {
Pattern pattern = mapping.getKey();
ChannelAccessPolicy accessPolicy = mapping.getValue();
if (pattern.matcher(channelName).matches()) {
if (invocation.isSend()) {
Collection<ConfigAttribute> definition = accessPolicy.getConfigAttributesForSend();
if (definition != null) {
attributes.addAll(definition);
}
}
else if (invocation.isReceive()) {
Collection<ConfigAttribute> definition = accessPolicy.getConfigAttributesForReceive();
if (definition != null) {
attributes.addAll(definition);
}
}
}
}
return attributes;
}
public Collection<ConfigAttribute> getAllConfigAttributes() {
Set<ConfigAttribute> allAttributes = new HashSet<ConfigAttribute>();
for (ChannelAccessPolicy policy : this.patternMappings.values()) {
Collection<ConfigAttribute> receiveAttributes = policy.getConfigAttributesForReceive();
allAttributes.addAll(receiveAttributes);
Collection<ConfigAttribute> sendAttributes = policy.getConfigAttributesForSend();
allAttributes.addAll(sendAttributes);
}
return allAttributes;
}
public boolean supports(Class<?> clazz) {
return ChannelInvocation.class.isAssignableFrom(clazz);
}
}

View File

@@ -1,127 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.channel;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* Creates the {@link ConfigAttribute}s for secured channel
* send and receive operations based on simple String values.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Artem Bilan
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0")
public class DefaultChannelAccessPolicy implements ChannelAccessPolicy {
private final Collection<ConfigAttribute> configAttributeDefinitionForSend;
private final Collection<ConfigAttribute> configAttributeDefinitionForReceive;
/**
* Create an access policy instance. The provided 'sendAccess' and 'receiveAccess'
* values may be a single String or a comma-delimited list of values. All whitespace
* will be trimmed. A <code>null</code> value indicates that the policy does not
* apply for either send or receive access type. At most one of the values may be null.
* @param sendAccess The send access value(s).
* @param receiveAccess The receive access value(s).
*/
public DefaultChannelAccessPolicy(String sendAccess, String receiveAccess) {
boolean sendAccessDefined = StringUtils.hasText(sendAccess);
boolean receiveAccessDefined = StringUtils.hasText(receiveAccess);
Assert.isTrue(sendAccessDefined || receiveAccessDefined,
"At least one of 'sendAccess' and 'receiveAccess' must not be null and have at least one entry.");
if (sendAccessDefined) {
String[] sendAccessValues = StringUtils.commaDelimitedListToStringArray(sendAccess);
this.configAttributeDefinitionForSend = new HashSet<ConfigAttribute>();
for (String sendAccessValue : sendAccessValues) {
this.configAttributeDefinitionForSend.add(new SecurityConfig(StringUtils.trimAllWhitespace(sendAccessValue)));
}
}
else {
this.configAttributeDefinitionForSend = Collections.emptySet();
}
if (receiveAccessDefined) {
String[] receiveAccessValues = StringUtils.commaDelimitedListToStringArray(receiveAccess);
this.configAttributeDefinitionForReceive = new HashSet<ConfigAttribute>();
for (String receiveAccessValue : receiveAccessValues) {
this.configAttributeDefinitionForReceive.add(new SecurityConfig(StringUtils.trimAllWhitespace(receiveAccessValue)));
}
}
else {
this.configAttributeDefinitionForReceive = Collections.emptySet();
}
}
/**
* Create an access policy instance. A <code>null</code> value indicates that the policy does not
* apply for either send or receive access type. At most one of the values may be null.
* Typically is used for the values from the {@link SecuredChannel}
* @param sendAccess The send access values.
* @param receiveAccess The receive access values.
* @since 4.2
*/
public DefaultChannelAccessPolicy(String[] sendAccess, String[] receiveAccess) {
boolean sendAccessDefined = !ObjectUtils.isEmpty(sendAccess);
boolean receiveAccessDefined = !ObjectUtils.isEmpty(receiveAccess);
Assert.isTrue(sendAccessDefined || receiveAccessDefined,
"At least one of 'sendAccess' and 'receiveAccess' must not be null.");
if (sendAccessDefined) {
this.configAttributeDefinitionForSend = new HashSet<ConfigAttribute>();
for (String sendAccessValue : sendAccess) {
this.configAttributeDefinitionForSend.add(new SecurityConfig(sendAccessValue));
}
}
else {
this.configAttributeDefinitionForSend = Collections.emptySet();
}
if (receiveAccessDefined) {
this.configAttributeDefinitionForReceive = new HashSet<ConfigAttribute>();
for (String receiveAccessValue : receiveAccess) {
this.configAttributeDefinitionForReceive.add(new SecurityConfig(receiveAccessValue));
}
}
else {
this.configAttributeDefinitionForReceive = Collections.emptySet();
}
}
@Override
public Collection<ConfigAttribute> getConfigAttributesForSend() {
return this.configAttributeDefinitionForSend;
}
@Override
public Collection<ConfigAttribute> getConfigAttributesForReceive() {
return this.configAttributeDefinitionForReceive;
}
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright 2015-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.channel;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* An annotation to be applied for the {@link org.springframework.messaging.MessageChannel} bean definition
* from JavaConfig - on {@code @Bean} method level.
* <p>
* Applies the {@link ChannelSecurityInterceptor}(s) using provided {@link #interceptor()} bean name(s).
* <p>
* The {@link #sendAccess()} and {@link #receiveAccess()} policies are populated to the
* {@link ChannelSecurityInterceptor}(s) from the {@code ChannelSecurityInterceptorBeanPostProcessor}.
*
* @author Artem Bilan
* @since 4.2
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0")
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SecuredChannel {
String[] interceptor();
String[] sendAccess() default {};
String[] receiveAccess() default {};
}

View File

@@ -1,119 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.springframework.aop.Advisor;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator;
import org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.security.channel.ChannelAccessPolicy;
import org.springframework.integration.security.channel.ChannelSecurityInterceptor;
import org.springframework.integration.security.channel.ChannelSecurityMetadataSource;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
/**
* A {@link org.springframework.beans.factory.config.BeanPostProcessor} that proxies
* {@link MessageChannel}s to apply a {@link ChannelSecurityInterceptor}.
*
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Gary Russell
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0")
@SuppressWarnings("serial")
public class ChannelSecurityInterceptorBeanPostProcessor extends AbstractAutoProxyCreator {
private final Map<String, Set<Pattern>> securityInterceptorMappings;
private final Map<String, Map<Pattern, ChannelAccessPolicy>> accessPolicyMapping;
public ChannelSecurityInterceptorBeanPostProcessor(Map<String, Set<Pattern>> securityInterceptorMappings) {
this(securityInterceptorMappings, null);
}
public ChannelSecurityInterceptorBeanPostProcessor(Map<String, Set<Pattern>> securityInterceptorMappings,
Map<String, Map<Pattern, ChannelAccessPolicy>> accessPolicyMapping) {
this.securityInterceptorMappings = securityInterceptorMappings; //NOSONAR (inconsistent sync)
this.accessPolicyMapping = accessPolicyMapping; //NOSONAR (inconsistent sync)
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
if (this.accessPolicyMapping != null
&& bean instanceof ChannelSecurityInterceptor
&& this.accessPolicyMapping.containsKey(beanName)) {
Map<Pattern, ChannelAccessPolicy> accessPolicies = this.accessPolicyMapping.get(beanName);
ChannelSecurityMetadataSource securityMetadataSource =
(ChannelSecurityMetadataSource) ((ChannelSecurityInterceptor) bean).obtainSecurityMetadataSource();
for (Map.Entry<Pattern, ChannelAccessPolicy> entry : accessPolicies.entrySet()) {
securityMetadataSource.addPatternMapping(entry.getKey(), entry.getValue());
}
}
return bean;
}
@Override
@Nullable
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String beanName,
@Nullable TargetSource customTargetSource) throws BeansException {
if (MessageChannel.class.isAssignableFrom(beanClass)) {
List<Advisor> interceptors = new ArrayList<>();
for (Map.Entry<String, Set<Pattern>> entry : this.securityInterceptorMappings.entrySet()) {
if (isMatch(beanName, entry.getValue())) {
DefaultBeanFactoryPointcutAdvisor channelSecurityInterceptor =
new DefaultBeanFactoryPointcutAdvisor();
channelSecurityInterceptor.setAdviceBeanName(entry.getKey());
BeanFactory beanFactory = getBeanFactory();
if (beanFactory != null) {
channelSecurityInterceptor.setBeanFactory(beanFactory);
}
interceptors.add(channelSecurityInterceptor);
}
}
if (!interceptors.isEmpty()) {
return interceptors.toArray();
}
}
return DO_NOT_PROXY;
}
private boolean isMatch(String beanName, Set<Pattern> patterns) {
for (Pattern pattern : patterns) {
if (pattern.matcher(beanName).matches()) {
return true;
}
}
return false;
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.config;
import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;
/**
* Namespace handler for the security namespace.
*
* @author Jonas Partner
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0", forRemoval = true)
public class IntegrationSecurityNamespaceHandler extends AbstractIntegrationNamespaceHandler {
public void init() {
registerBeanDefinitionParser("secured-channels", new SecuredChannelsParser());
}
}

View File

@@ -1,90 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.config;
import java.util.List;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.security.channel.ChannelSecurityInterceptor;
import org.springframework.integration.security.channel.ChannelSecurityMetadataSource;
import org.springframework.integration.security.channel.DefaultChannelAccessPolicy;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
* Creates a {@link org.springframework.integration.security.channel.ChannelSecurityInterceptor}
* to control send and receive access, and creates a bean post-processor to apply the
* interceptor to {@link org.springframework.messaging.MessageChannel}s
* whose names match the specified patterns.
*
* @author Jonas Partner
* @author Mark Fisher
* @author Artem Bilan
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0")
public class SecuredChannelsParser extends AbstractSingleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return ChannelSecurityInterceptor.class;
}
@Override
protected boolean shouldGenerateId() {
return true;
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
builder.addConstructorArgValue(this.parseSecurityMetadataSource(element, parserContext));
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "authentication-manager");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "access-decision-manager");
}
private BeanDefinition parseSecurityMetadataSource(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ChannelSecurityMetadataSource.class);
List<Element> accessPolicyElements = DomUtils.getChildElementsByTagName(element, "access-policy");
ManagedMap<String, BeanDefinition> patternMappings = new ManagedMap<String, BeanDefinition>();
for (Element accessPolicyElement : accessPolicyElements) {
String sendAccess = accessPolicyElement.getAttribute("send-access");
String receiveAccess = accessPolicyElement.getAttribute("receive-access");
if (!StringUtils.hasText(sendAccess) && !StringUtils.hasText(receiveAccess)) {
parserContext.getReaderContext().error(
"At least one of 'send-access' or 'receive-access' must be provided.", accessPolicyElement);
}
BeanDefinitionBuilder accessPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultChannelAccessPolicy.class);
accessPolicyBuilder.addConstructorArgValue(sendAccess);
accessPolicyBuilder.addConstructorArgValue(receiveAccess);
accessPolicyBuilder.getBeanDefinition().setRole(BeanDefinition.ROLE_SUPPORT);
patternMappings.put(accessPolicyElement.getAttribute("pattern"), accessPolicyBuilder.getBeanDefinition());
}
builder.addConstructorArgValue(patternMappings);
return builder.getBeanDefinition();
}
}

View File

@@ -1,151 +0,0 @@
/*
* Copyright 2014-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.security.config;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.ManagedSet;
import org.springframework.core.type.MethodMetadata;
import org.springframework.integration.config.IntegrationConfigurationInitializer;
import org.springframework.integration.security.channel.ChannelAccessPolicy;
import org.springframework.integration.security.channel.ChannelSecurityInterceptor;
import org.springframework.integration.security.channel.DefaultChannelAccessPolicy;
import org.springframework.integration.security.channel.SecuredChannel;
/**
* The Integration Security infrastructure {@code beanFactory} initializer.
*
* @author Artem Bilan
*
* @since 4.0
*
* @deprecated since 6.0 in favor of literally
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
*/
@Deprecated(since = "6.0", forRemoval = true)
public class SecurityIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
private static final String CHANNEL_SECURITY_INTERCEPTOR_BPP_BEAN_NAME =
ChannelSecurityInterceptorBeanPostProcessor.class.getName();
@Override
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
Map<String, Set<String>> securityInterceptors = new ManagedMap<>();
Map<String, Map<Pattern, ChannelAccessPolicy>> policies = new HashMap<>();
for (String beanName : registry.getBeanDefinitionNames()) {
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
if (ChannelSecurityInterceptor.class.getName().equals(beanDefinition.getBeanClassName())) {
collectPatternsFromInterceptor(securityInterceptors, beanName, beanDefinition);
}
else if (beanDefinition instanceof AnnotatedBeanDefinition) {
Object beanSource = beanDefinition.getSource();
if (beanSource instanceof MethodMetadata) {
collectInterceptorsAndPoliciesBySecuredChannel(securityInterceptors, policies, beanName,
(MethodMetadata) beanSource);
}
}
}
if (!securityInterceptors.isEmpty()) {
BeanDefinitionBuilder builder =
BeanDefinitionBuilder.rootBeanDefinition(ChannelSecurityInterceptorBeanPostProcessor.class)
.addConstructorArgValue(securityInterceptors);
if (!policies.isEmpty()) {
builder.addConstructorArgValue(policies);
}
registry.registerBeanDefinition(CHANNEL_SECURITY_INTERCEPTOR_BPP_BEAN_NAME, builder.getBeanDefinition());
}
}
@SuppressWarnings("unchecked")
private void collectPatternsFromInterceptor(Map<String, Set<String>> securityInterceptors, String beanName,
BeanDefinition beanDefinition) {
ConstructorArgumentValues.ValueHolder metadataSourceValueHolder =
beanDefinition
.getConstructorArgumentValues()
.getIndexedArgumentValue(0, BeanDefinition.class);
if (metadataSourceValueHolder != null) {
BeanDefinition metadataSource = (BeanDefinition) metadataSourceValueHolder.getValue();
if (metadataSource != null) {
ConstructorArgumentValues.ValueHolder patternMappingsValueHolder =
metadataSource
.getConstructorArgumentValues()
.getIndexedArgumentValue(0, Map.class);
if (patternMappingsValueHolder != null) {
Map<String, ?> patternsToAdd = (Map<String, ?>) patternMappingsValueHolder.getValue();
Set<String> patterns = new ManagedSet<>();
if (!securityInterceptors.containsKey(beanName)) {
securityInterceptors.put(beanName, patterns);
}
else {
patterns = securityInterceptors.get(beanName);
}
if (patternsToAdd != null) {
patterns.addAll(patternsToAdd.keySet());
}
}
}
}
}
private void collectInterceptorsAndPoliciesBySecuredChannel(Map<String, Set<String>> securityInterceptors,
Map<String, Map<Pattern, ChannelAccessPolicy>> policies, String beanName, MethodMetadata beanMethod) {
Map<String, Object> securedAttributes = beanMethod.getAnnotationAttributes(SecuredChannel.class.getName());
if (securedAttributes != null) {
String[] interceptors = (String[]) securedAttributes.get("interceptor");
String[] sendAccess = (String[]) securedAttributes.get("sendAccess");
String[] receiveAccess = (String[]) securedAttributes.get("receiveAccess");
ChannelAccessPolicy accessPolicy = new DefaultChannelAccessPolicy(sendAccess, receiveAccess);
for (String interceptor : interceptors) {
Set<String> patterns = new ManagedSet<>();
if (!securityInterceptors.containsKey(interceptor)) {
securityInterceptors.put(interceptor, patterns);
}
else {
patterns = securityInterceptors.get(interceptor);
}
patterns.add(beanName);
Map<Pattern, ChannelAccessPolicy> mapping = new HashMap<>();
if (!policies.containsKey(interceptor)) {
policies.put(interceptor, mapping);
}
else {
mapping = policies.get(interceptor);
}
mapping.put(Pattern.compile(beanName), accessPolicy);
}
}
}
}

View File

@@ -1,4 +0,0 @@
/**
* Provides classes for configuration - parsers, namespace handlers, bean post processors.
*/
package org.springframework.integration.security.config;

View File

@@ -1,2 +0,0 @@
org.springframework.integration.config.IntegrationConfigurationInitializer=\
org.springframework.integration.security.config.SecurityIntegrationConfigurationInitializer

View File

@@ -1 +0,0 @@
http\://www.springframework.org/schema/integration/security=org.springframework.integration.security.config.IntegrationSecurityNamespaceHandler

View File

@@ -1,24 +0,0 @@
http\://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-2.1.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-2.2.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-3.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-4.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-4.1.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-4.2.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-4.3.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-5.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-5.1.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security-5.2.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
http\://www.springframework.org/schema/integration/security/spring-integration-security.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-2.1.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-2.2.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-3.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-4.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-4.1.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-4.2.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-4.3.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-5.0.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-5.1.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security-5.2.xsd=org/springframework/integration/security/config/spring-integration-security.xsd
https\://www.springframework.org/schema/integration/security/spring-integration-security.xsd=org/springframework/integration/security/config/spring-integration-security.xsd

View File

@@ -1,4 +0,0 @@
# Tooling related information for the integration security namespace
http\://www.springframework.org/schema/integration/security@name=integration security Namespace
http\://www.springframework.org/schema/integration/security@prefix=int-security
http\://www.springframework.org/schema/integration/security@icon=org/springframework/integration/security/config/spring-integration-security.gif

View File

@@ -1,56 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.springframework.org/schema/integration/security"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tool="http://www.springframework.org/schema/tool"
targetNamespace="http://www.springframework.org/schema/integration/security"
elementFormDefault="qualified">
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
<xsd:element name="secured-channels">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>
Defines a 'org.springframework.integration.security.channel.ChannelSecurityInterceptor' security
requirements for one or more Message Channels.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="access-policy" type="accessPolicyType" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="authentication-manager" type="xsd:string" default="authenticationManager">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.security.authentication.AuthenticationManager"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="access-decision-manager" type="xsd:string" default="accessDecisionManager">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.security.access.AccessDecisionManager"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="accessPolicyType">
<xsd:annotation>
<xsd:documentation>
Defines the security access policy for send and/or receive invocations based on a Message Channel name
pattern.
</xsd:documentation>
</xsd:annotation>
<xsd:attribute name="pattern" type="xsd:string" use="required"/>
<xsd:attribute name="send-access" type="xsd:string"/>
<xsd:attribute name="receive-access" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>