From 25feedb8701ddac92a239376ccbcf634f54707e2 Mon Sep 17 00:00:00 2001 From: Marcus Da Coregio Date: Thu, 18 Nov 2021 11:30:04 -0300 Subject: [PATCH] Fix removal of framework deprecated code Issue https://github.com/spring-projects/spring-framework/issues/27686 --- .../config/annotation/web/builders/HttpSecurity.java | 4 +++- ...ractSecurityWebSocketMessageBrokerConfigurer.java | 12 ++++++------ ...rityWebSocketMessageBrokerConfigurerDocTests.java | 4 ++-- .../security/integration/UserDetailsServiceImpl.java | 4 +--- .../OAuth2LoginAuthenticationWebFilterTests.java | 2 +- .../security/web/server/WebFilterChainProxy.java | 5 ++--- ...irectServerAuthenticationFailureHandlerTests.java | 4 +++- .../server/context/ReactorContextWebFilterTests.java | 5 ++++- ...curityContextServerWebExchangeWebFilterTests.java | 9 ++++++--- 9 files changed, 28 insertions(+), 21 deletions(-) diff --git a/config/src/main/java/org/springframework/security/config/annotation/web/builders/HttpSecurity.java b/config/src/main/java/org/springframework/security/config/annotation/web/builders/HttpSecurity.java index 25368167da..0c0663cc96 100644 --- a/config/src/main/java/org/springframework/security/config/annotation/web/builders/HttpSecurity.java +++ b/config/src/main/java/org/springframework/security/config/annotation/web/builders/HttpSecurity.java @@ -3234,7 +3234,9 @@ public final class HttpSecurity extends AbstractConfiguredSecurityBuilder exchange.getResponse().setComplete())); + new DefaultWebFilterChain((exchange) -> exchange.getResponse().setComplete(), Collections.emptyList())); given(this.authorizedClientRepository.saveAuthorizedClient(any(), any(), any())).willReturn(Mono.empty()); } diff --git a/web/src/main/java/org/springframework/security/web/server/WebFilterChainProxy.java b/web/src/main/java/org/springframework/security/web/server/WebFilterChainProxy.java index f4654ab25f..33704a096f 100644 --- a/web/src/main/java/org/springframework/security/web/server/WebFilterChainProxy.java +++ b/web/src/main/java/org/springframework/security/web/server/WebFilterChainProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 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. @@ -26,7 +26,6 @@ import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; import org.springframework.web.server.handler.DefaultWebFilterChain; -import org.springframework.web.server.handler.FilteringWebHandler; /** * Used to delegate to a List of {@link SecurityWebFilterChain} instances. @@ -52,7 +51,7 @@ public class WebFilterChainProxy implements WebFilter { .filterWhen((securityWebFilterChain) -> securityWebFilterChain.matches(exchange)).next() .switchIfEmpty(chain.filter(exchange).then(Mono.empty())) .flatMap((securityWebFilterChain) -> securityWebFilterChain.getWebFilters().collectList()) - .map((filters) -> new FilteringWebHandler(chain::filter, filters)).map(DefaultWebFilterChain::new) + .map((filters) -> new DefaultWebFilterChain(chain::filter, filters)) .flatMap((securedChain) -> securedChain.filter(exchange)); } diff --git a/web/src/test/java/org/springframework/security/web/server/authentication/RedirectServerAuthenticationFailureHandlerTests.java b/web/src/test/java/org/springframework/security/web/server/authentication/RedirectServerAuthenticationFailureHandlerTests.java index 499cdb2e2d..720b257537 100644 --- a/web/src/test/java/org/springframework/security/web/server/authentication/RedirectServerAuthenticationFailureHandlerTests.java +++ b/web/src/test/java/org/springframework/security/web/server/authentication/RedirectServerAuthenticationFailureHandlerTests.java @@ -16,6 +16,8 @@ package org.springframework.security.web.server.authentication; +import java.util.Collections; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; @@ -95,7 +97,7 @@ public class RedirectServerAuthenticationFailureHandlerTests { private WebFilterExchange createExchange() { return new WebFilterExchange(MockServerWebExchange.from(MockServerHttpRequest.get("/").build()), - new DefaultWebFilterChain((e) -> Mono.empty())); + new DefaultWebFilterChain((e) -> Mono.empty(), Collections.emptyList())); } } diff --git a/web/src/test/java/org/springframework/security/web/server/context/ReactorContextWebFilterTests.java b/web/src/test/java/org/springframework/security/web/server/context/ReactorContextWebFilterTests.java index 7f3e6a3f1f..6b342c22b5 100644 --- a/web/src/test/java/org/springframework/security/web/server/context/ReactorContextWebFilterTests.java +++ b/web/src/test/java/org/springframework/security/web/server/context/ReactorContextWebFilterTests.java @@ -16,6 +16,8 @@ package org.springframework.security.web.server.context; +import java.util.List; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -109,7 +111,8 @@ public class ReactorContextWebFilterTests { given(this.repository.load(any())).willReturn(this.securityContext.mono()); String contextKey = "main"; WebFilter mainContextWebFilter = (e, c) -> c.filter(e).subscriberContext(Context.of(contextKey, true)); - WebFilterChain chain = new DefaultWebFilterChain((e) -> Mono.empty(), mainContextWebFilter, this.filter); + WebFilterChain chain = new DefaultWebFilterChain((e) -> Mono.empty(), + List.of(mainContextWebFilter, this.filter)); Mono filter = chain.filter(MockServerWebExchange.from(this.exchange.build())); StepVerifier.create(filter).expectAccessibleContext().hasKey(contextKey).then().verifyComplete(); } diff --git a/web/src/test/java/org/springframework/security/web/server/context/SecurityContextServerWebExchangeWebFilterTests.java b/web/src/test/java/org/springframework/security/web/server/context/SecurityContextServerWebExchangeWebFilterTests.java index bcf3d2bba4..f42a30ee46 100644 --- a/web/src/test/java/org/springframework/security/web/server/context/SecurityContextServerWebExchangeWebFilterTests.java +++ b/web/src/test/java/org/springframework/security/web/server/context/SecurityContextServerWebExchangeWebFilterTests.java @@ -16,6 +16,8 @@ package org.springframework.security.web.server.context; +import java.util.Collections; + import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -48,7 +50,8 @@ public class SecurityContextServerWebExchangeWebFilterTests { .filter(this.exchange, new DefaultWebFilterChain((e) -> e.getPrincipal() .doOnSuccess((contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(this.principal)) .flatMap((contextPrincipal) -> Mono.subscriberContext()) - .doOnSuccess((context) -> assertThat(context.get("foo")).isEqualTo("bar")).then())) + .doOnSuccess((context) -> assertThat(context.get("foo")).isEqualTo("bar")).then(), + Collections.emptyList())) .subscriberContext((context) -> context.put("foo", "bar")) .subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.principal)); StepVerifier.create(result).verifyComplete(); @@ -61,7 +64,7 @@ public class SecurityContextServerWebExchangeWebFilterTests { new DefaultWebFilterChain((e) -> e.getPrincipal() .doOnSuccess( (contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(this.principal)) - .then())) + .then(), Collections.emptyList())) .subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.principal)); StepVerifier.create(result).verifyComplete(); } @@ -73,7 +76,7 @@ public class SecurityContextServerWebExchangeWebFilterTests { new DefaultWebFilterChain((e) -> e.getPrincipal().defaultIfEmpty(defaultAuthentication) .doOnSuccess( (contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(defaultAuthentication)) - .then())); + .then(), Collections.emptyList())); StepVerifier.create(result).verifyComplete(); }