Polish Reactive Method Security reference
Issue gh-4757
This commit is contained in:
+19
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user