1
0
mirror of synced 2026-08-05 17:57:15 +00:00

Polish Reactive Method Security reference

Issue gh-4757
This commit is contained in:
Rob Winch
2017-10-30 16:27:33 -05:00
parent d664ff2e26
commit e95430fa36
2 changed files with 47 additions and 1 deletions
@@ -50,6 +50,25 @@ public class ReactiveSecurityContextHolderTests {
.verifyComplete();
}
@Test
public void demo() {
Authentication authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
Mono<String> messageByUsername = ReactiveSecurityContextHolder.getContext()
.map(SecurityContext::getAuthentication)
.map(Authentication::getName)
.flatMap(this::findMessageByUsername)
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication));
StepVerifier.create(messageByUsername)
.expectNext("Hi user")
.verifyComplete();
}
private Mono<String> findMessageByUsername(String username) {
return Mono.just("Hi " + username);
}
@Test
public void setContextAndClearAndGetContextThenEmitsEmpty() {
SecurityContext expectedContext = new SecurityContextImpl(