Search in sources :

Example 61 with ClientRequest

use of org.springframework.web.reactive.function.client.ClientRequest in project spring-security by spring-projects.

the class ServletBearerExchangeFilterFunctionTests method filterWhenExistingAuthorizationThenSingleAuthorizationHeader.

@Test
public void filterWhenExistingAuthorizationThenSingleAuthorizationHeader() {
    ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).header(HttpHeaders.AUTHORIZATION, "Existing").build();
    this.function.filter(request, this.exchange).subscriberContext(context(this.authentication)).block();
    HttpHeaders headers = this.exchange.getRequest().headers();
    assertThat(headers.get(HttpHeaders.AUTHORIZATION)).containsOnly("Bearer " + this.accessToken.getTokenValue());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ClientRequest(org.springframework.web.reactive.function.client.ClientRequest) Test(org.junit.jupiter.api.Test)

Example 62 with ClientRequest

use of org.springframework.web.reactive.function.client.ClientRequest in project spring-security by spring-projects.

the class ServerBearerExchangeFilterFunctionTests method filterWhenUnauthenticatedThenAuthorizationHeaderNull.

@Test
public void filterWhenUnauthenticatedThenAuthorizationHeaderNull() {
    ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).build();
    this.function.filter(request, this.exchange).block();
    assertThat(this.exchange.getRequest().headers().getFirst(HttpHeaders.AUTHORIZATION)).isNull();
}
Also used : ClientRequest(org.springframework.web.reactive.function.client.ClientRequest) Test(org.junit.jupiter.api.Test)

Example 63 with ClientRequest

use of org.springframework.web.reactive.function.client.ClientRequest in project spring-security by spring-projects.

the class ServerBearerExchangeFilterFunctionTests method filterWhenExistingAuthorizationThenSingleAuthorizationHeader.

@Test
public void filterWhenExistingAuthorizationThenSingleAuthorizationHeader() {
    ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).header(HttpHeaders.AUTHORIZATION, "Existing").build();
    this.function.filter(request, this.exchange).subscriberContext(ReactiveSecurityContextHolder.withAuthentication(this.authentication)).block();
    HttpHeaders headers = this.exchange.getRequest().headers();
    assertThat(headers.get(HttpHeaders.AUTHORIZATION)).containsOnly("Bearer " + this.accessToken.getTokenValue());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ClientRequest(org.springframework.web.reactive.function.client.ClientRequest) Test(org.junit.jupiter.api.Test)

Aggregations

ClientRequest (org.springframework.web.reactive.function.client.ClientRequest)63 Test (org.junit.jupiter.api.Test)59 OAuth2AuthorizedClient (org.springframework.security.oauth2.client.OAuth2AuthorizedClient)34 OAuth2RefreshToken (org.springframework.security.oauth2.core.OAuth2RefreshToken)21 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)18 OAuth2AccessTokenResponse (org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse)18 ClientResponse (org.springframework.web.reactive.function.client.ClientResponse)16 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)15 Mono (reactor.core.publisher.Mono)14 Instant (java.time.Instant)13 ClientRegistration (org.springframework.security.oauth2.client.registration.ClientRegistration)13 OAuth2AccessToken (org.springframework.security.oauth2.core.OAuth2AccessToken)13 ExchangeFunction (org.springframework.web.reactive.function.client.ExchangeFunction)13 URI (java.net.URI)12 HttpHeaders (org.springframework.http.HttpHeaders)12 HttpMethod (org.springframework.http.HttpMethod)12 HttpStatus (org.springframework.http.HttpStatus)12 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)11 Duration (java.time.Duration)10