Example usage for org.springframework.security.oauth2.client.http OAuth2ErrorHandler OAuth2ErrorHandler

List of usage examples for org.springframework.security.oauth2.client.http OAuth2ErrorHandler OAuth2ErrorHandler

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.client.http OAuth2ErrorHandler OAuth2ErrorHandler.

Prototype

public OAuth2ErrorHandler(ResponseErrorHandler errorHandler, OAuth2ProtectedResourceDetails resource) 

Source Link

Document

Construct an error handler that can deal with OAuth2 concerns before delegating to acustom handler.

Usage

From source file:org.zalando.riptide.OAuth2CompatibilityTest.java

@Test
public void dispatchesConsumedResponseAgain() throws IOException {
    final RestTemplate template = new RestTemplate();
    final MockRestServiceServer server = MockRestServiceServer.createServer(template);

    server.expect(requestTo(url)).andRespond(withUnauthorizedRequest().body(new byte[] { 0x13, 0x37 }));

    template.setErrorHandler(new OAuth2ErrorHandler(new OAuth2CompatibilityResponseErrorHandler(), null));
    final Rest rest = Rest.create(template);

    final ClientHttpResponse response = rest.execute(GET, url).dispatch(status(), on(UNAUTHORIZED).capture())
            .to(ClientHttpResponse.class);

    assertThat(response.getBody().available(), is(2));
}

From source file:org.zalando.riptide.OAuth2CompatibilityTest.java

@Test
public void responseIsConsumedIfOtherHandlerIsUsed() throws IOException {
    final RestTemplate template = new RestTemplate();
    final MockRestServiceServer server = MockRestServiceServer.createServer(template);

    server.expect(requestTo(url)).andRespond(withUnauthorizedRequest().body(new byte[] { 0x13, 0x37 }));

    template.setErrorHandler(new OAuth2ErrorHandler(new PassThroughResponseErrorHandler(), null));
    final Rest rest = Rest.create(template);

    final ClientHttpResponse response = rest.execute(GET, url).dispatch(status(), on(UNAUTHORIZED).capture())
            .to(ClientHttpResponse.class);

    // Since our mocked response is using a byte[] stream we check for the remaining bytes instead
    // of expecting an "already closed" IOException.
    assertThat(response.getBody().available(), is(0));
}

From source file:org.zalando.riptide.OAuth2CompatibilityTest.java

@Test
public void dispatchesConsumedAsyncResponseAgain() throws IOException {
    final AsyncRestTemplate template = new AsyncRestTemplate();
    final MockRestServiceServer server = MockRestServiceServer.createServer(template);

    server.expect(requestTo(url)).andRespond(withUnauthorizedRequest().body(new byte[] { 0x13, 0x37 }));

    template.setErrorHandler(new OAuth2ErrorHandler(new OAuth2CompatibilityResponseErrorHandler(), null));
    final AsyncRest rest = AsyncRest.create(template);

    final AtomicReference<ClientHttpResponse> reference = new AtomicReference<>();

    rest.execute(GET, url).dispatch(status(), on(UNAUTHORIZED).call(reference::set));

    assertThat(reference.get().getBody().available(), is(2));
}