Replace removed context-related operators

Closes gh-11194
This commit is contained in:
Marcus Da Coregio
2022-05-10 14:50:19 -03:00
parent b803e845e7
commit 806e05855c
45 changed files with 194 additions and 204 deletions

View File

@@ -97,7 +97,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
MethodParameter parameter = this.authenticationPrincipal.arg(String.class);
given(this.authentication.getPrincipal()).willReturn("user");
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.block()).isEqualTo(this.authentication.getPrincipal());
}
@@ -114,7 +114,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
MethodParameter parameter = this.authenticationPrincipal.arg(Mono.class, String.class);
given(this.authentication.getPrincipal()).willReturn("user");
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.cast(Mono.class).block().block()).isEqualTo(this.authentication.getPrincipal());
}
@@ -124,7 +124,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
.arg(Mono.class);
given(this.authentication.getPrincipal()).willReturn("user");
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.cast(Mono.class).block().block()).isEqualTo(this.authentication.getPrincipal());
}
@@ -134,7 +134,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
MethodParameter parameter = this.spel.arg(Long.class);
given(this.authentication.getPrincipal()).willReturn(user);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.block()).isEqualTo(user.getId());
}
@@ -144,7 +144,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
MethodParameter parameter = this.spelPrimitive.arg(int.class);
given(this.authentication.getPrincipal()).willReturn(user);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.block()).isEqualTo(user.getId());
}
@@ -155,7 +155,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
given(this.authentication.getPrincipal()).willReturn(user);
given(this.beanResolver.resolve(any(), eq("beanName"))).willReturn(new Bean());
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.block()).isEqualTo(user.getId());
}
@@ -164,7 +164,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
MethodParameter parameter = this.meta.arg(String.class);
given(this.authentication.getPrincipal()).willReturn("user");
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.block()).isEqualTo("user");
}
@@ -174,7 +174,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
.arg(Integer.class);
given(this.authentication.getPrincipal()).willReturn("user");
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.block()).isNull();
}
@@ -184,7 +184,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
.arg(Integer.class);
given(this.authentication.getPrincipal()).willReturn("user");
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThat(argument.block()).isNull();
}
@@ -194,7 +194,7 @@ public class AuthenticationPrincipalArgumentResolverTests {
.arg(Integer.class);
given(this.authentication.getPrincipal()).willReturn("user");
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.authentication));
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> argument.block());
}

View File

@@ -99,7 +99,7 @@ public class CurrentSecurityContextArgumentResolverTests {
SecurityContext.class);
Context context = ReactiveSecurityContextHolder.withSecurityContext(Mono.empty());
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Object obj = argument.subscriberContext(context).block();
Object obj = argument.contextWrite(context).block();
assertThat(obj).isNull();
ReactiveSecurityContextHolder.clearContext();
}
@@ -111,7 +111,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("hello");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
SecurityContext securityContext = (SecurityContext) argument.subscriberContext(context).cast(Mono.class).block()
SecurityContext securityContext = (SecurityContext) argument.contextWrite(context).cast(Mono.class).block()
.block();
assertThat(securityContext.getAuthentication()).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
@@ -124,8 +124,8 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("hello");
Context context = ReactiveSecurityContextHolder.withSecurityContext(Mono.just(new CustomSecurityContext(auth)));
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
CustomSecurityContext securityContext = (CustomSecurityContext) argument.subscriberContext(context)
.cast(Mono.class).block().block();
CustomSecurityContext securityContext = (CustomSecurityContext) argument.contextWrite(context).cast(Mono.class)
.block().block();
assertThat(securityContext.getAuthentication()).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
}
@@ -137,7 +137,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = null;
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
SecurityContext securityContext = (SecurityContext) argument.subscriberContext(context).cast(Mono.class).block()
SecurityContext securityContext = (SecurityContext) argument.contextWrite(context).cast(Mono.class).block()
.block();
assertThat(securityContext.getAuthentication()).isNull();
ReactiveSecurityContextHolder.clearContext();
@@ -150,7 +150,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = null;
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<Object> r = (Mono<Object>) argument.subscriberContext(context).block();
Mono<Object> r = (Mono<Object>) argument.contextWrite(context).block();
assertThat(r.block()).isNull();
ReactiveSecurityContextHolder.clearContext();
}
@@ -162,7 +162,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("authentication1");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<Authentication> auth1 = (Mono<Authentication>) argument.subscriberContext(context).block();
Mono<Authentication> auth1 = (Mono<Authentication>) argument.contextWrite(context).block();
assertThat(auth1.block()).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
}
@@ -174,7 +174,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = null;
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<Object> obj = (Mono<Object>) argument.subscriberContext(context).block();
Mono<Object> obj = (Mono<Object>) argument.contextWrite(context).block();
assertThat(obj.block()).isNull();
ReactiveSecurityContextHolder.clearContext();
}
@@ -186,7 +186,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("auth_optional");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<Object> obj = (Mono<Object>) argument.subscriberContext(context).block();
Mono<Object> obj = (Mono<Object>) argument.contextWrite(context).block();
assertThat(obj.block()).isEqualTo("auth_optional");
ReactiveSecurityContextHolder.clearContext();
}
@@ -199,7 +199,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
assertThatExceptionOfType(SpelEvaluationException.class)
.isThrownBy(() -> argument.subscriberContext(context).block());
.isThrownBy(() -> argument.contextWrite(context).block());
ReactiveSecurityContextHolder.clearContext();
}
@@ -210,7 +210,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("auth_string");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<String> obj = (Mono<String>) argument.subscriberContext(context).block();
Mono<String> obj = (Mono<String>) argument.contextWrite(context).block();
assertThat(obj.block()).isEqualTo("auth_string");
ReactiveSecurityContextHolder.clearContext();
}
@@ -222,7 +222,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("invalid_type_implicit");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<String> obj = (Mono<String>) argument.subscriberContext(context).block();
Mono<String> obj = (Mono<String>) argument.contextWrite(context).block();
assertThat(obj.block()).isNull();
ReactiveSecurityContextHolder.clearContext();
}
@@ -234,7 +234,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("error_on_invalid_type_explicit_false");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Mono<String> obj = (Mono<String>) argument.subscriberContext(context).block();
Mono<String> obj = (Mono<String>) argument.contextWrite(context).block();
assertThat(obj.block()).isNull();
ReactiveSecurityContextHolder.clearContext();
}
@@ -246,8 +246,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("error_on_invalid_type_explicit_true");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
assertThatExceptionOfType(ClassCastException.class)
.isThrownBy(() -> argument.subscriberContext(context).block());
assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> argument.contextWrite(context).block());
ReactiveSecurityContextHolder.clearContext();
}
@@ -258,7 +257,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("current_custom_security_context");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
SecurityContext securityContext = (SecurityContext) argument.subscriberContext(context).cast(Mono.class).block()
SecurityContext securityContext = (SecurityContext) argument.contextWrite(context).cast(Mono.class).block()
.block();
assertThat(securityContext.getAuthentication()).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
@@ -271,7 +270,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("current_authentication");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Authentication authentication = (Authentication) argument.subscriberContext(context).cast(Mono.class).block()
Authentication authentication = (Authentication) argument.contextWrite(context).cast(Mono.class).block()
.block();
assertThat(authentication).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
@@ -284,7 +283,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Authentication auth = buildAuthenticationWithPrincipal("current_security_with_error_on_invalid_type");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
SecurityContext securityContext = (SecurityContext) argument.subscriberContext(context).cast(Mono.class).block()
SecurityContext securityContext = (SecurityContext) argument.contextWrite(context).cast(Mono.class).block()
.block();
assertThat(securityContext.getAuthentication()).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
@@ -298,7 +297,7 @@ public class CurrentSecurityContextArgumentResolverTests {
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
assertThatExceptionOfType(ClassCastException.class)
.isThrownBy(() -> argument.subscriberContext(context).cast(Mono.class).block().block());
.isThrownBy(() -> argument.contextWrite(context).cast(Mono.class).block().block());
ReactiveSecurityContextHolder.clearContext();
}

View File

@@ -119,8 +119,7 @@ public class SwitchUserWebFilterTests {
given(this.successHandler.onAuthenticationSuccess(any(WebFilterExchange.class), any(Authentication.class)))
.willReturn(Mono.empty());
this.switchUserWebFilter.filter(exchange, chain)
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext)))
.block();
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext))).block();
verifyNoInteractions(chain);
verify(this.userDetailsService).findByUsername(targetUsername);
final ArgumentCaptor<SecurityContext> securityContextCaptor = ArgumentCaptor.forClass(SecurityContext.class);
@@ -161,8 +160,7 @@ public class SwitchUserWebFilterTests {
given(this.userDetailsService.findByUsername(targetUsername))
.willReturn(Mono.just(switchUserDetails(targetUsername, true)));
this.switchUserWebFilter.filter(exchange, chain)
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext)))
.block();
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext))).block();
final ArgumentCaptor<Authentication> authenticationCaptor = ArgumentCaptor.forClass(Authentication.class);
verify(this.successHandler).onAuthenticationSuccess(any(WebFilterExchange.class),
authenticationCaptor.capture());
@@ -183,7 +181,7 @@ public class SwitchUserWebFilterTests {
assertThatIllegalArgumentException().isThrownBy(() -> {
Context securityContextHolder = ReactiveSecurityContextHolder
.withSecurityContext(Mono.just(securityContext));
this.switchUserWebFilter.filter(exchange, chain).subscriberContext(securityContextHolder).block();
this.switchUserWebFilter.filter(exchange, chain).contextWrite(securityContextHolder).block();
}).withMessage("The userName can not be null.");
verifyNoInteractions(chain);
}
@@ -200,8 +198,7 @@ public class SwitchUserWebFilterTests {
given(this.failureHandler.onAuthenticationFailure(any(WebFilterExchange.class), any(DisabledException.class)))
.willReturn(Mono.empty());
this.switchUserWebFilter.filter(exchange, chain)
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext)))
.block();
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext))).block();
verify(this.failureHandler).onAuthenticationFailure(any(WebFilterExchange.class), any(DisabledException.class));
verifyNoInteractions(chain);
}
@@ -219,7 +216,7 @@ public class SwitchUserWebFilterTests {
assertThatExceptionOfType(DisabledException.class).isThrownBy(() -> {
Context securityContextHolder = ReactiveSecurityContextHolder
.withSecurityContext(Mono.just(securityContext));
this.switchUserWebFilter.filter(exchange, chain).subscriberContext(securityContextHolder).block();
this.switchUserWebFilter.filter(exchange, chain).contextWrite(securityContextHolder).block();
});
verifyNoInteractions(chain);
}
@@ -241,8 +238,7 @@ public class SwitchUserWebFilterTests {
given(this.successHandler.onAuthenticationSuccess(any(WebFilterExchange.class), any(Authentication.class)))
.willReturn(Mono.empty());
this.switchUserWebFilter.filter(exchange, chain)
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext)))
.block();
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext))).block();
final ArgumentCaptor<SecurityContext> securityContextCaptor = ArgumentCaptor.forClass(SecurityContext.class);
verify(this.serverSecurityContextRepository).save(eq(exchange), securityContextCaptor.capture());
final SecurityContext savedSecurityContext = securityContextCaptor.getValue();
@@ -266,7 +262,7 @@ public class SwitchUserWebFilterTests {
assertThatExceptionOfType(AuthenticationCredentialsNotFoundException.class).isThrownBy(() -> {
Context securityContextHolder = ReactiveSecurityContextHolder
.withSecurityContext(Mono.just(securityContext));
this.switchUserWebFilter.filter(exchange, chain).subscriberContext(securityContextHolder).block();
this.switchUserWebFilter.filter(exchange, chain).contextWrite(securityContextHolder).block();
}).withMessage("Could not find original Authentication object");
verifyNoInteractions(chain);
}

View File

@@ -65,8 +65,8 @@ public class AuthorizationWebFilterTests {
given(this.chain.filter(this.exchange)).willReturn(this.chainResult.mono());
AuthorizationWebFilter filter = new AuthorizationWebFilter(
(a, e) -> a.flatMap((auth) -> Mono.error(new AccessDeniedException("Denied"))));
Mono<Void> result = filter.filter(this.exchange, this.chain).subscriberContext(
ReactiveSecurityContextHolder.withSecurityContext(Mono.just(new SecurityContextImpl())));
Mono<Void> result = filter.filter(this.exchange, this.chain)
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(new SecurityContextImpl())));
StepVerifier.create(result).expectError(AccessDeniedException.class).verify();
this.chainResult.assertWasNotSubscribed();
}
@@ -76,7 +76,7 @@ public class AuthorizationWebFilterTests {
given(this.chain.filter(this.exchange)).willReturn(this.chainResult.mono());
AuthorizationWebFilter filter = new AuthorizationWebFilter(
(a, e) -> Mono.error(new AccessDeniedException("Denied")));
Mono<Void> result = filter.filter(this.exchange, this.chain).subscriberContext(
Mono<Void> result = filter.filter(this.exchange, this.chain).contextWrite(
ReactiveSecurityContextHolder.withAuthentication(new TestingAuthenticationToken("a", "b", "R")));
StepVerifier.create(result).expectError(AccessDeniedException.class).verify();
this.chainResult.assertWasNotSubscribed();
@@ -89,7 +89,7 @@ public class AuthorizationWebFilterTests {
AuthorizationWebFilter filter = new AuthorizationWebFilter(
(a, e) -> Mono.error(new AccessDeniedException("Denied")));
Mono<Void> result = filter.filter(this.exchange, this.chain)
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(context.mono()));
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(context.mono()));
StepVerifier.create(result).expectError(AccessDeniedException.class).verify();
this.chainResult.assertWasNotSubscribed();
context.assertWasNotSubscribed();
@@ -102,7 +102,7 @@ public class AuthorizationWebFilterTests {
AuthorizationWebFilter filter = new AuthorizationWebFilter(
(a, e) -> Mono.just(new AuthorizationDecision(true)));
Mono<Void> result = filter.filter(this.exchange, this.chain)
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(context.mono()));
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(context.mono()));
StepVerifier.create(result).verifyComplete();
this.chainResult.assertWasSubscribed();
context.assertWasNotSubscribed();
@@ -115,7 +115,7 @@ public class AuthorizationWebFilterTests {
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> a
.map((auth) -> new AuthorizationDecision(true)).defaultIfEmpty(new AuthorizationDecision(true)));
Mono<Void> result = filter.filter(this.exchange, this.chain)
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(context.mono()));
.contextWrite(ReactiveSecurityContextHolder.withSecurityContext(context.mono()));
StepVerifier.create(result).verifyComplete();
this.chainResult.assertWasSubscribed();
context.assertWasSubscribed();

View File

@@ -110,7 +110,7 @@ public class ReactorContextWebFilterTests {
public void filterWhenMainContextThenDoesNotOverride() {
given(this.repository.load(any())).willReturn(this.securityContext.mono());
String contextKey = "main";
WebFilter mainContextWebFilter = (e, c) -> c.filter(e).subscriberContext(Context.of(contextKey, true));
WebFilter mainContextWebFilter = (e, c) -> c.filter(e).contextWrite(Context.of(contextKey, true));
WebFilterChain chain = new DefaultWebFilterChain((e) -> Mono.empty(),
List.of(mainContextWebFilter, this.filter));
Mono<Void> filter = chain.filter(MockServerWebExchange.from(this.exchange.build()));

View File

@@ -49,11 +49,11 @@ public class SecurityContextServerWebExchangeWebFilterTests {
Mono<Void> result = this.filter
.filter(this.exchange, new DefaultWebFilterChain((e) -> e.getPrincipal()
.doOnSuccess((contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(this.principal))
.flatMap((contextPrincipal) -> Mono.subscriberContext())
.flatMap((contextPrincipal) -> Mono.deferContextual(Mono::just))
.doOnSuccess((context) -> assertThat(context.<String>get("foo")).isEqualTo("bar")).then(),
Collections.emptyList()))
.subscriberContext((context) -> context.put("foo", "bar"))
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.principal));
.contextWrite((context) -> context.put("foo", "bar"))
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.principal));
StepVerifier.create(result).verifyComplete();
}
@@ -65,7 +65,7 @@ public class SecurityContextServerWebExchangeWebFilterTests {
.doOnSuccess(
(contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(this.principal))
.then(), Collections.emptyList()))
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.principal));
.contextWrite(ReactiveSecurityContextHolder.withAuthentication(this.principal));
StepVerifier.create(result).verifyComplete();
}