Skip to content

Commit 64f0e73

Browse files
GH-3897: Deprecate ChannelSecurityInterceptor (#3915)
* GH-3897: Deprecate `ChannelSecurityInterceptor` Fixes #3897 Spring Security has deprecated `AccessDecisionManager` and all its infrastructure in favor of `AuthorizationManager` * Deprecate and AOP `ChannelSecurityInterceptor` and all its infrastructure, including `@SecuredChannel` and respective XML configuration. The `AuthorizationChannelInterceptor` added to respective channels for security or configured as a global channel interceptor fully covers the previous AOP configuration * Fix deprecation warnings in other tests with security * Fix language in docs Co-authored-by: Gary Russell <[email protected]> * * Remove `forRemoval` attr from `@Deprecated` markers for Security classes: looks like to mark `@Deprecated` and even `@SuppressWarnings("deprecation")` don't silence warnings on compilation Co-authored-by: Gary Russell <[email protected]>
1 parent ff076b6 commit 64f0e73

26 files changed

+249
-682
lines changed

build.gradle

+7-6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ allprojects {
169169
mavenBom "org.apache.camel:camel-bom:$camelVersion"
170170
mavenBom "org.testcontainers:testcontainers-bom:$testcontainersVersion"
171171
mavenBom "org.apache.groovy:groovy-bom:$groovyVersion"
172+
mavenBom "org.springframework.security:spring-security-bom:$springSecurityVersion"
172173
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:$kotlinCoroutinesVersion"
173174
}
174175

@@ -675,10 +676,10 @@ project('spring-integration-http') {
675676

676677
testImplementation project(':spring-integration-security')
677678
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
678-
testImplementation("org.springframework.security:spring-security-config:$springSecurityVersion") {
679+
testImplementation('org.springframework.security:spring-security-config') {
679680
exclude group: 'org.springframework'
680681
}
681-
testImplementation("org.springframework.security:spring-security-test:$springSecurityVersion") {
682+
testImplementation('org.springframework.security:spring-security-test') {
682683
exclude group: 'org.springframework'
683684
}
684685
testImplementation 'com.fasterxml.jackson.core:jackson-databind'
@@ -879,11 +880,11 @@ project('spring-integration-security') {
879880
description = 'Spring Integration Security Support'
880881
dependencies {
881882
api project(':spring-integration-core')
882-
api("org.springframework.security:spring-security-core:$springSecurityVersion") {
883+
api('org.springframework.security:spring-security-messaging') {
883884
exclude group: 'org.springframework'
884885
}
885886

886-
testImplementation("org.springframework.security:spring-security-config:$springSecurityVersion") {
887+
testImplementation('org.springframework.security:spring-security-config') {
887888
exclude group: 'org.springframework'
888889
}
889890
}
@@ -971,10 +972,10 @@ project('spring-integration-webflux') {
971972
testImplementation "jakarta.servlet:jakarta.servlet-api:$servletApiVersion"
972973
testImplementation "org.hamcrest:hamcrest-core:$hamcrestVersion"
973974
testImplementation 'org.springframework:spring-webmvc'
974-
testImplementation("org.springframework.security:spring-security-config:$springSecurityVersion") {
975+
testImplementation('org.springframework.security:spring-security-config') {
975976
exclude group: 'org.springframework'
976977
}
977-
testImplementation("org.springframework.security:spring-security-test:$springSecurityVersion") {
978+
testImplementation('org.springframework.security:spring-security-test') {
978979
exclude group: 'org.springframework'
979980
}
980981
testImplementation 'com.fasterxml.jackson.core:jackson-databind'

spring-integration-http/src/test/java/org/springframework/integration/http/dsl/HttpDslTests.java

+6-24
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.nio.charset.Charset;
2929
import java.nio.charset.StandardCharsets;
30-
import java.util.Collections;
3130
import java.util.List;
3231
import java.util.Map;
3332

@@ -52,22 +51,18 @@
5251
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
5352
import org.springframework.integration.http.multipart.UploadedMultipartFile;
5453
import org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler;
55-
import org.springframework.integration.security.channel.ChannelSecurityInterceptor;
56-
import org.springframework.integration.security.channel.SecuredChannel;
5754
import org.springframework.messaging.Message;
5855
import org.springframework.messaging.MessageChannel;
5956
import org.springframework.messaging.PollableChannel;
6057
import org.springframework.messaging.support.ErrorMessage;
6158
import org.springframework.mock.web.MockPart;
62-
import org.springframework.security.access.AccessDecisionManager;
63-
import org.springframework.security.access.vote.AffirmativeBased;
64-
import org.springframework.security.access.vote.RoleVoter;
65-
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
59+
import org.springframework.security.authorization.AuthorityAuthorizationManager;
6660
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
6761
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
6862
import org.springframework.security.core.userdetails.User;
6963
import org.springframework.security.core.userdetails.UserDetailsService;
7064
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
65+
import org.springframework.security.messaging.access.intercept.AuthorizationChannelInterceptor;
7166
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
7267
import org.springframework.security.web.SecurityFilterChain;
7368
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
@@ -335,9 +330,11 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
335330
}
336331

337332
@Bean
338-
@SecuredChannel(interceptor = "channelSecurityInterceptor", sendAccess = "ROLE_ADMIN")
339333
public MessageChannel transformSecuredChannel() {
340-
return new DirectChannel();
334+
DirectChannel directChannel = new DirectChannel();
335+
directChannel.addInterceptor(
336+
new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasRole("ADMIN")));
337+
return directChannel;
341338
}
342339

343340
@Bean
@@ -393,21 +390,6 @@ public MultipartResolver multipartResolver() {
393390
return new StandardServletMultipartResolver();
394391
}
395392

396-
@Bean
397-
public AccessDecisionManager accessDecisionManager() {
398-
return new AffirmativeBased(Collections.singletonList(new RoleVoter()));
399-
}
400-
401-
@Bean
402-
public ChannelSecurityInterceptor channelSecurityInterceptor(AccessDecisionManager accessDecisionManager,
403-
AuthenticationManagerBuilder authenticationManagerBuilder) {
404-
405-
ChannelSecurityInterceptor channelSecurityInterceptor = new ChannelSecurityInterceptor();
406-
channelSecurityInterceptor.setAuthenticationManager(authenticationManagerBuilder.getOrBuild());
407-
channelSecurityInterceptor.setAccessDecisionManager(accessDecisionManager);
408-
return channelSecurityInterceptor;
409-
}
410-
411393
@Bean
412394
public Validator customValidator() {
413395
return new TestModelValidator();

spring-integration-http/src/test/java/org/springframework/integration/http/outbound/CookieTests.java

-6
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ public HttpMethod getMethod() {
111111
return null;
112112
}
113113

114-
@Override
115-
@Deprecated
116-
public String getMethodValue() {
117-
return null;
118-
}
119-
120114
public ClientHttpResponse execute() {
121115
allHeaders.add(headers);
122116
return new ClientHttpResponse() {

spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelAccessPolicy.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,11 @@
2626
*
2727
* @author Oleg Zhurakousky
2828
* @since 2.0
29+
*
30+
* @deprecated since 6.0 in favor of literally
31+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
2932
*/
33+
@Deprecated(since = "6.0")
3034
public interface ChannelAccessPolicy {
3135

3236
Collection<ConfigAttribute> getConfigAttributesForSend();

spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelInvocation.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,11 @@
2929
* is a <em>send</em> operation, the {@link Message} is also available.
3030
*
3131
* @author Mark Fisher
32+
*
33+
* @deprecated since 6.0 in favor of literally
34+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
3235
*/
36+
@Deprecated(since = "6.0")
3337
public class ChannelInvocation {
3438

3539
private final MessageChannel channel;

spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelSecurityInterceptor.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,8 +31,15 @@
3131
*
3232
* @author Mark Fisher
3333
* @author Oleg Zhurakousky
34+
*
3435
* @see SecuredChannel
36+
*
37+
* @deprecated since 6.0 in favor of literally
38+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}.
39+
* However, the {@link org.springframework.security.messaging.access.intercept.AuthorizationChannelInterceptor}
40+
* can be configured with any {@link org.springframework.security.authorization.AuthorizationManager} implementation.
3541
*/
42+
@Deprecated(since = "6.0")
3643
public final class ChannelSecurityInterceptor extends AbstractSecurityInterceptor implements MethodInterceptor {
3744

3845
private final ChannelSecurityMetadataSource securityMetadataSource;

spring-integration-security/src/main/java/org/springframework/integration/security/channel/ChannelSecurityMetadataSource.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,7 +36,11 @@
3636
*
3737
* @author Mark Fisher
3838
* @author Oleg Zhurakousky
39+
*
40+
* @deprecated since 6.0 in favor of literally
41+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
3942
*/
43+
@Deprecated(since = "6.0")
4044
public class ChannelSecurityMetadataSource implements SecurityMetadataSource {
4145

4246
private final Map<Pattern, ChannelAccessPolicy> patternMappings;

spring-integration-security/src/main/java/org/springframework/integration/security/channel/DefaultChannelAccessPolicy.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,11 @@
3333
* @author Mark Fisher
3434
* @author Oleg Zhurakousky
3535
* @author Artem Bilan
36+
*
37+
* @deprecated since 6.0 in favor of literally
38+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
3639
*/
40+
@Deprecated(since = "6.0")
3741
public class DefaultChannelAccessPolicy implements ChannelAccessPolicy {
3842

3943
private final Collection<ConfigAttribute> configAttributeDefinitionForSend;

spring-integration-security/src/main/java/org/springframework/integration/security/channel/SecuredChannel.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,11 @@
3333
*
3434
* @author Artem Bilan
3535
* @since 4.2
36+
*
37+
* @deprecated since 6.0 in favor of literally
38+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
3639
*/
40+
@Deprecated(since = "6.0")
3741
@Target(ElementType.METHOD)
3842
@Retention(RetentionPolicy.RUNTIME)
3943
@Documented

spring-integration-security/src/main/java/org/springframework/integration/security/config/ChannelSecurityInterceptorBeanPostProcessor.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,11 @@
4242
* @author Oleg Zhurakousky
4343
* @author Artem Bilan
4444
* @author Gary Russell
45+
46+
* @deprecated since 6.0 in favor of literally
47+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
4548
*/
49+
@Deprecated(since = "6.0")
4650
@SuppressWarnings("serial")
4751
public class ChannelSecurityInterceptorBeanPostProcessor extends AbstractAutoProxyCreator {
4852

spring-integration-security/src/main/java/org/springframework/integration/security/config/IntegrationSecurityNamespaceHandler.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,11 @@
2222
* Namespace handler for the security namespace.
2323
*
2424
* @author Jonas Partner
25+
*
26+
* @deprecated since 6.0 in favor of literally
27+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
2528
*/
29+
@Deprecated(since = "6.0", forRemoval = true)
2630
public class IntegrationSecurityNamespaceHandler extends AbstractIntegrationNamespaceHandler {
2731

2832
public void init() {

spring-integration-security/src/main/java/org/springframework/integration/security/config/SecuredChannelsParser.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,11 @@
4141
* @author Jonas Partner
4242
* @author Mark Fisher
4343
* @author Artem Bilan
44+
*
45+
* @deprecated since 6.0 in favor of literally
46+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
4447
*/
48+
@Deprecated(since = "6.0")
4549
public class SecuredChannelsParser extends AbstractSingleBeanDefinitionParser {
4650

4751
@Override

spring-integration-security/src/main/java/org/springframework/integration/security/config/SecurityIntegrationConfigurationInitializer.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,7 +43,11 @@
4343
* @author Artem Bilan
4444
*
4545
* @since 4.0
46+
*
47+
* @deprecated since 6.0 in favor of literally
48+
* {@code new AuthorizationChannelInterceptor(AuthorityAuthorizationManager.hasAnyRole())}
4649
*/
50+
@Deprecated(since = "6.0", forRemoval = true)
4751
public class SecurityIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer {
4852

4953
private static final String CHANNEL_SECURITY_INTERCEPTOR_BPP_BEAN_NAME =

spring-integration-security/src/test/java/org/springframework/integration/security/MockAuthenticationManager.java

-43
This file was deleted.

0 commit comments

Comments
 (0)