Example usage for org.springframework.http HttpStatus TEMPORARY_REDIRECT

List of usage examples for org.springframework.http HttpStatus TEMPORARY_REDIRECT

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus TEMPORARY_REDIRECT.

Prototype

HttpStatus TEMPORARY_REDIRECT

To view the source code for org.springframework.http HttpStatus TEMPORARY_REDIRECT.

Click Source Link

Document

307 Temporary Redirect .

Usage

From source file:io.syndesis.runtime.credential.CredentialITCase.java

@Test
public void callbackErrorsShouldBeHandeled() {
    final String credentialKey = UUID.randomUUID().toString();
    final OAuth2CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder()
            .providerId("test-provider").key(credentialKey).returnUrl(URI.create("/ui#state")).build();

    final HttpHeaders cookies = persistAsCookie(flowState);

    final ResponseEntity<Void> callbackResponse = http(HttpMethod.GET,
            "/api/v1/credentials/callback?denied=something", null, Void.class, null, cookies,
            HttpStatus.TEMPORARY_REDIRECT);

    assertThat(callbackResponse.getStatusCode()).as("Status should be temporarry redirect (307)")
            .isEqualTo(HttpStatus.TEMPORARY_REDIRECT);
    assertThat(callbackResponse.hasBody()).as("Should not contain HTTP body").isFalse();
    assertThat(callbackResponse.getHeaders().getLocation().toString()).matches(
            "http.?://localhost:[0-9]*/api/v1/ui#%7B%22connectorId%22:%22test-provider%22,%22message%22:%22Unable%20to%20update%20the%20state%20of%20authorization%22,%22status%22:%22FAILURE%22%7D");

    final List<String> receivedCookies = callbackResponse.getHeaders().get("Set-Cookie");
    assertThat(receivedCookies).hasSize(1);
    assertThat(receivedCookies.get(0)).isEqualTo("cred-o2-" + credentialKey
            + "=\"\"; path=/; secure; HttpOnly; Max-Age=0; Expires=Thu, 01-Jan-1970 00:00:00 GMT");
}

From source file:io.syndesis.runtime.credential.CredentialITCase.java

@Test
public void shouldReceiveCallbacksFromResourceProviders() {
    final OAuth2CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder()
            .providerId("test-provider").key(UUID.randomUUID().toString()).returnUrl(URI.create("/ui#state"))
            .build();//from  w  w  w  . j  a v  a  2  s .  co  m

    final HttpHeaders cookies = persistAsCookie(flowState);

    final ResponseEntity<Void> callbackResponse = http(HttpMethod.GET,
            "/api/v1/credentials/callback?state=test-state&code=code", null, Void.class, null, cookies,
            HttpStatus.TEMPORARY_REDIRECT);

    assertThat(callbackResponse.getStatusCode()).as("Status should be temporarry redirect (307)")
            .isEqualTo(HttpStatus.TEMPORARY_REDIRECT);
    assertThat(callbackResponse.hasBody()).as("Should not contain HTTP body").isFalse();
    assertThat(callbackResponse.getHeaders().getLocation().toString()).matches(
            "http.?://localhost:[0-9]*/api/v1/ui#%7B%22connectorId%22:%22test-provider%22,%22message%22:%22Successfully%20authorized%20Syndesis's%20access%22,%22status%22:%22SUCCESS%22%7D");

    final List<String> receivedCookies = callbackResponse.getHeaders().get("Set-Cookie");
    assertThat(receivedCookies).hasSize(1);

    final OAuth2CredentialFlowState endingFlowState = clientSideState
            .restoreFrom(Cookie.valueOf(receivedCookies.get(0)), OAuth2CredentialFlowState.class);

    // AccessGrant does not implement equals/hashCode
    assertThat(endingFlowState).isEqualToIgnoringGivenFields(
            new OAuth2CredentialFlowState.Builder().createFrom(flowState).code("code").build(), "accessGrant");
    assertThat(endingFlowState.getAccessGrant()).isEqualToComparingFieldByField(new AccessGrant("token"));
}