Search in sources :

Example 66 with Context

use of reactor.util.context.Context in project spring-security by spring-projects.

the class CurrentSecurityContextArgumentResolverTests method resolveArgumentWithAuthenticationOptional1.

@Test
public void resolveArgumentWithAuthenticationOptional1() {
    MethodParameter parameter = ResolvableMethod.on(getClass()).named("securityContextWithDepthPropOptional").build().arg(Mono.class, Object.class);
    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();
    assertThat(obj.block()).isEqualTo("auth_optional");
    ReactiveSecurityContextHolder.clearContext();
}
Also used : BindingContext(org.springframework.web.reactive.BindingContext) CurrentSecurityContext(org.springframework.security.core.annotation.CurrentSecurityContext) Context(reactor.util.context.Context) SecurityContext(org.springframework.security.core.context.SecurityContext) Authentication(org.springframework.security.core.Authentication) Mono(reactor.core.publisher.Mono) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.jupiter.api.Test)

Aggregations

Context (reactor.util.context.Context)66 Test (org.junit.jupiter.api.Test)29 Test (org.junit.Test)28 Mono (reactor.core.publisher.Mono)25 Authentication (org.springframework.security.core.Authentication)23 SecurityContext (org.springframework.security.core.context.SecurityContext)23 MethodParameter (org.springframework.core.MethodParameter)17 CurrentSecurityContext (org.springframework.security.core.annotation.CurrentSecurityContext)17 BindingContext (org.springframework.web.reactive.BindingContext)17 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)14 ArrayList (java.util.ArrayList)13 Consumer (java.util.function.Consumer)13 List (java.util.List)11 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)9 Collections (java.util.Collections)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Nullable (javax.annotation.Nullable)8 Flux (reactor.core.publisher.Flux)8 StepVerifier (reactor.test.StepVerifier)8