use of reactor.core.publisher.Mono in project spring-security by spring-projects.
the class WebClientReactiveJwtBearerTokenResponseClientTests method getTokenResponseWhenBodyExtractorSetThenCalled.
@Test
public void getTokenResponseWhenBodyExtractorSetThenCalled() {
BodyExtractor<Mono<OAuth2AccessTokenResponse>, ReactiveHttpInputMessage> bodyExtractor = mock(BodyExtractor.class);
OAuth2AccessTokenResponse response = TestOAuth2AccessTokenResponses.accessTokenResponse().build();
given(bodyExtractor.extract(any(), any())).willReturn(Mono.just(response));
ClientRegistration clientRegistration = this.clientRegistration.build();
JwtBearerGrantRequest request = new JwtBearerGrantRequest(clientRegistration, this.jwtAssertion);
this.client.setBodyExtractor(bodyExtractor);
enqueueJson(DEFAULT_ACCESS_TOKEN_RESPONSE);
this.client.getTokenResponse(request).block();
verify(bodyExtractor).extract(any(), any());
}
use of reactor.core.publisher.Mono in project spring-security by spring-projects.
the class WebClientReactiveAuthorizationCodeTokenResponseClientTests method getTokenResponseWhenSuccessCustomResponseThenReturnAccessTokenResponse.
// gh-10260
@Test
public void getTokenResponseWhenSuccessCustomResponseThenReturnAccessTokenResponse() {
String accessTokenSuccessResponse = "{}";
WebClientReactiveAuthorizationCodeTokenResponseClient customClient = new WebClientReactiveAuthorizationCodeTokenResponseClient();
BodyExtractor<Mono<OAuth2AccessTokenResponse>, ReactiveHttpInputMessage> extractor = mock(BodyExtractor.class);
OAuth2AccessTokenResponse response = TestOAuth2AccessTokenResponses.accessTokenResponse().build();
given(extractor.extract(any(), any())).willReturn(Mono.just(response));
customClient.setBodyExtractor(extractor);
this.server.enqueue(jsonResponse(accessTokenSuccessResponse));
OAuth2AccessTokenResponse accessTokenResponse = customClient.getTokenResponse(authorizationCodeGrantRequest()).block();
assertThat(accessTokenResponse.getAccessToken()).isNotNull();
}
use of reactor.core.publisher.Mono in project spring-security by spring-projects.
the class AuthorizationWebFilterTests method filterWhenNoAuthenticationThenThrowsAccessDenied.
@Test
public void filterWhenNoAuthenticationThenThrowsAccessDenied() {
given(this.chain.filter(this.exchange)).willReturn(this.chainResult.mono());
AuthorizationWebFilter filter = new AuthorizationWebFilter((a, e) -> a.flatMap((auth) -> Mono.error(new AccessDeniedException("Denied"))));
Mono<Void> result = filter.filter(this.exchange, this.chain).subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(new SecurityContextImpl())));
StepVerifier.create(result).expectError(AccessDeniedException.class).verify();
this.chainResult.assertWasNotSubscribed();
}
use of reactor.core.publisher.Mono in project spring-security by spring-projects.
the class SecurityContextServerWebExchangeWebFilterTests method filterWhenExistingContextAndPrincipalNotNullThenContextPopulated.
@Test
public void filterWhenExistingContextAndPrincipalNotNullThenContextPopulated() {
Mono<Void> result = this.filter.filter(this.exchange, new DefaultWebFilterChain((e) -> e.getPrincipal().doOnSuccess((contextPrincipal) -> assertThat(contextPrincipal).isEqualTo(this.principal)).flatMap((contextPrincipal) -> Mono.subscriberContext()).doOnSuccess((context) -> assertThat(context.<String>get("foo")).isEqualTo("bar")).then(), Collections.emptyList())).subscriberContext((context) -> context.put("foo", "bar")).subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.principal));
StepVerifier.create(result).verifyComplete();
}
use of reactor.core.publisher.Mono in project spring-security by spring-projects.
the class CurrentSecurityContextArgumentResolverTests method metaAnnotationWhenCurrentAuthenticationThenInjectAuthentication.
@Test
public void metaAnnotationWhenCurrentAuthenticationThenInjectAuthentication() {
MethodParameter parameter = ResolvableMethod.on(getClass()).named("currentAuthentication").build().arg(Mono.class, Authentication.class);
Authentication auth = buildAuthenticationWithPrincipal("current_authentication");
Context context = ReactiveSecurityContextHolder.withAuthentication(auth);
Mono<Object> argument = this.resolver.resolveArgument(parameter, this.bindingContext, this.exchange);
Authentication authentication = (Authentication) argument.subscriberContext(context).cast(Mono.class).block().block();
assertThat(authentication).isSameAs(auth);
ReactiveSecurityContextHolder.clearContext();
}
Aggregations