@Test
public void testWorkingContext() {
Authentication authentication = new PreAuthenticatedAuthenticationToken("TEST", "");
Mono<String> working = ReactiveSecurityContextHolder.getContext()
.map(securityContext -> (String)securityContext.getAuthentication().getPrincipal());
Mono<String> stringMono = working.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication));
StepVerifier.create(stringMono).expectNext("TEST").verifyComplete();
}
@Test
public void testBrokenContext() {
Authentication authentication = new PreAuthenticatedAuthenticationToken("TEST", "");
Mono<String> working = ReactiveSecurityContextHolder.getContext()
.map(securityContext -> (String)securityContext.getAuthentication().getPrincipal());
Mono<String> broken = Mono.fromFuture(working.toFuture());
Mono<String> stringMono = broken.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication));
StepVerifier.create(stringMono).expectNext("TEST").verifyComplete();
}
Summary
ReactiveSecurityContextHolderis broken when used with Futures. It does not always provide results and sometimes just fires the onComplete signal.Actual Behavior
Executes onComplete()
Expected Behavior
Should execute onNext()
Version
5.0.7 Release
Sample