|
@@ -32,7 +32,10 @@ public class ReactiveSecurityContextHolderTests {
|
|
|
@Test
|
|
|
public void getContextWhenEmpty() {
|
|
|
Mono<SecurityContext> context = ReactiveSecurityContextHolder.getContext();
|
|
|
- StepVerifier.create(context).verifyComplete();
|
|
|
+ // @formatter:off
|
|
|
+ StepVerifier.create(context)
|
|
|
+ .verifyComplete();
|
|
|
+ // @formatter:on
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -42,17 +45,26 @@ public class ReactiveSecurityContextHolderTests {
|
|
|
Mono<SecurityContext> context = Mono.subscriberContext()
|
|
|
.flatMap((c) -> ReactiveSecurityContextHolder.getContext())
|
|
|
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)));
|
|
|
- StepVerifier.create(context).expectNext(expectedContext).verifyComplete();
|
|
|
+ // @formatter:off
|
|
|
+ StepVerifier.create(context)
|
|
|
+ .expectNext(expectedContext)
|
|
|
+ .verifyComplete();
|
|
|
+ // @formatter:on
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void demo() {
|
|
|
Authentication authentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
|
|
|
+ // @formatter:off
|
|
|
Mono<String> messageByUsername = ReactiveSecurityContextHolder.getContext()
|
|
|
- .map(SecurityContext::getAuthentication).map(Authentication::getName)
|
|
|
+ .map(SecurityContext::getAuthentication)
|
|
|
+ .map(Authentication::getName)
|
|
|
.flatMap(this::findMessageByUsername)
|
|
|
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(authentication));
|
|
|
- StepVerifier.create(messageByUsername).expectNext("Hi user").verifyComplete();
|
|
|
+ StepVerifier.create(messageByUsername)
|
|
|
+ .expectNext("Hi user")
|
|
|
+ .verifyComplete();
|
|
|
+ // @formatter:on
|
|
|
}
|
|
|
|
|
|
private Mono<String> findMessageByUsername(String username) {
|
|
@@ -63,20 +75,28 @@ public class ReactiveSecurityContextHolderTests {
|
|
|
public void setContextAndClearAndGetContextThenEmitsEmpty() {
|
|
|
SecurityContext expectedContext = new SecurityContextImpl(
|
|
|
new TestingAuthenticationToken("user", "password", "ROLE_USER"));
|
|
|
+ // @formatter:off
|
|
|
Mono<SecurityContext> context = Mono.subscriberContext()
|
|
|
.flatMap((c) -> ReactiveSecurityContextHolder.getContext())
|
|
|
.subscriberContext(ReactiveSecurityContextHolder.clearContext())
|
|
|
.subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(expectedContext)));
|
|
|
- StepVerifier.create(context).verifyComplete();
|
|
|
+ StepVerifier.create(context)
|
|
|
+ .verifyComplete();
|
|
|
+ // @formatter:on
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void setAuthenticationAndGetContextThenEmitsContext() {
|
|
|
Authentication expectedAuthentication = new TestingAuthenticationToken("user", "password", "ROLE_USER");
|
|
|
+ // @formatter:off
|
|
|
Mono<Authentication> authentication = Mono.subscriberContext()
|
|
|
- .flatMap((c) -> ReactiveSecurityContextHolder.getContext()).map(SecurityContext::getAuthentication)
|
|
|
+ .flatMap((c) -> ReactiveSecurityContextHolder.getContext())
|
|
|
+ .map(SecurityContext::getAuthentication)
|
|
|
.subscriberContext(ReactiveSecurityContextHolder.withAuthentication(expectedAuthentication));
|
|
|
- StepVerifier.create(authentication).expectNext(expectedAuthentication).verifyComplete();
|
|
|
+ StepVerifier.create(authentication)
|
|
|
+ .expectNext(expectedAuthentication)
|
|
|
+ .verifyComplete();
|
|
|
+ // @formatter:on
|
|
|
}
|
|
|
|
|
|
}
|