Skip to content

GH-3897: Deprecate ChannelSecurityInterceptor #3915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ allprojects {
mavenBom "org.apache.camel:camel-bom:$camelVersion"
mavenBom "org.testcontainers:testcontainers-bom:$testcontainersVersion"
mavenBom "org.apache.groovy:groovy-bom:$groovyVersion"
mavenBom "org.springframework.security:spring-security-bom:$springSecurityVersion"
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:$kotlinCoroutinesVersion"
}

Expand Down Expand Up @@ -675,10 +676,10 @@ project('spring-integration-http') {

testImplementation project(':spring-integration-security')
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
testImplementation("org.springframework.security:spring-security-config:$springSecurityVersion") {
testImplementation('org.springframework.security:spring-security-config') {
exclude group: 'org.springframework'
}
testImplementation("org.springframework.security:spring-security-test:$springSecurityVersion") {
testImplementation('org.springframework.security:spring-security-test') {
exclude group: 'org.springframework'
}
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
Expand Down Expand Up @@ -879,11 +880,11 @@ project('spring-integration-security') {
description = 'Spring Integration Security Support'
dependencies {
api project(':spring-integration-core')
api("org.springframework.security:spring-security-core:$springSecurityVersion") {
api('org.springframework.security:spring-security-messaging') {
exclude group: 'org.springframework'
}

testImplementation("org.springframework.security:spring-security-config:$springSecurityVersion") {
testImplementation('org.springframework.security:spring-security-config') {
exclude group: 'org.springframework'
}
}
Expand Down Expand Up @@ -971,10 +972,10 @@ project('spring-integration-webflux') {
testImplementation "jakarta.servlet:jakarta.servlet-api:$servletApiVersion"
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
testImplementation 'org.springframework:spring-webmvc'
testImplementation("org.springframework.security:spring-security-config:$springSecurityVersion") {
testImplementation('org.springframework.security:spring-security-config') {
exclude group: 'org.springframework'
}
testImplementation("org.springframework.security:spring-security-test:$springSecurityVersion") {
testImplementation('org.springframework.security:spring-security-test') {
exclude group: 'org.springframework'
}
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand All @@ -52,22 +51,18 @@
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.http.multipart.UploadedMultipartFile;
import org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler;
import org.springframework.integration.security.channel.ChannelSecurityInterceptor;
import org.springframework.integration.security.channel.SecuredChannel;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.mock.web.MockPart;
import org.springframework.security.access.AccessDecisionManager;
import org.springframework.security.access.vote.AffirmativeBased;
import org.springframework.security.access.vote.RoleVoter;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.authorization.AuthorityAuthorizationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.messaging.access.intercept.AuthorizationChannelInterceptor;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
Expand Down Expand Up @@ -335,9 +330,11 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
}

@Bean
@SecuredChannel(interceptor = "channelSecurityInterceptor", sendAccess = "ROLE_ADMIN")
public MessageChannel transformSecuredChannel() {
return new DirectChannel();
DirectChannel directChannel = new DirectChannel();
directChannel.addInterceptor(
new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasRole("ADMIN")));
return directChannel;
}

@Bean
Expand Down Expand Up @@ -393,21 +390,6 @@ public MultipartResolver multipartResolver() {
return new StandardServletMultipartResolver();
}

@Bean
public AccessDecisionManager accessDecisionManager() {
return new AffirmativeBased(Collections.singletonList(new RoleVoter()));
}

@Bean
public ChannelSecurityInterceptor channelSecurityInterceptor(AccessDecisionManager accessDecisionManager,
AuthenticationManagerBuilder authenticationManagerBuilder) {

ChannelSecurityInterceptor channelSecurityInterceptor = new ChannelSecurityInterceptor();
channelSecurityInterceptor.setAuthenticationManager(authenticationManagerBuilder.getOrBuild());
channelSecurityInterceptor.setAccessDecisionManager(accessDecisionManager);
return channelSecurityInterceptor;
}

@Bean
public Validator customValidator() {
return new TestModelValidator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ public HttpMethod getMethod() {
return null;
}

@Override
@Deprecated
public String getMethodValue() {
return null;
}

public ClientHttpResponse execute() {
allHeaders.add(headers);
return new ClientHttpResponse() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand All @@ -26,7 +26,11 @@
*
* @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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -29,7 +29,11 @@
* 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -31,8 +31,15 @@
*
* @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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -36,7 +36,11 @@
*
* @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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -33,7 +33,11 @@
* @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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -33,7 +33,11 @@
*
* @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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -42,7 +42,11 @@
* @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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand All @@ -22,7 +22,11 @@
* 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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -41,7 +41,11 @@
* @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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* 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.
Expand Down Expand Up @@ -43,7 +43,11 @@
* @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 =
Expand Down

This file was deleted.

Loading