Example usage for org.springframework.security.oauth2.common.exceptions InvalidScopeException getHttpErrorCode

List of usage examples for org.springframework.security.oauth2.common.exceptions InvalidScopeException getHttpErrorCode

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common.exceptions InvalidScopeException getHttpErrorCode.

Prototype

public int getHttpErrorCode() 

Source Link

Document

The HTTP error code associated with this error.

Usage

From source file:com.bcknds.demo.oauth2.security.ClientCredentialAuthenticationTests.java

/**
 * This test is designed to test having a bad scope.
 *//*from  w  w w. j a v  a 2  s. co m*/
@Test
public void testBadScope() {
    OAuth2RestTemplate restTemplate = AuthenticationUtil.getClientCredentialsWithBadScope();
    try {
        restTemplate.getAccessToken();
        fail("Expected OAuth2AccessDeniedException, but none was thrown");
    } catch (OAuth2AccessDeniedException ex) {
        if (ex.getCause() instanceof InvalidScopeException) {
            InvalidScopeException clientException = (InvalidScopeException) ex.getCause();
            assertEquals(HttpStatus.BAD_REQUEST.value(), clientException.getHttpErrorCode());
        } else if (ex.getCause() instanceof ResourceAccessException) {
            fail("It appears that the server may not be running. Please start it before running tests");
        } else {
            fail(String.format("Expected HttpClientErrorException. Got %s",
                    ex.getCause().getClass().getName()));
        }
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}