Example usage for org.springframework.security.oauth2.common.exceptions UserDeniedAuthorizationException getMessage

List of usage examples for org.springframework.security.oauth2.common.exceptions UserDeniedAuthorizationException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.springframework.security.oauth2.common.exception.OAuth2ExceptionJackson2DeserializerTests.java

@Test
public void readValueAccessDenied() throws Exception {
    String accessToken = createResponse(OAuth2Exception.ACCESS_DENIED);
    UserDeniedAuthorizationException result = (UserDeniedAuthorizationException) mapper.readValue(accessToken,
            OAuth2Exception.class);
    assertEquals(DETAILS, result.getMessage());
    assertEquals(null, result.getAdditionalInformation());
}

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

/**
 * Test authentication failure to role secure endpoint that requires the ROLE_PASSWORD role
 * which this user will not have/* w ww .  j  ava2 s .c o m*/
 */
@Test
public void testPasswordAuthenticationBadRole() {
    userService.remove(validUser);
    Role badRole = new Role("ROLE_INVALID");
    validUser.setRoles(new ArrayList<Role>());
    validUser.addRole(badRole);
    userService.save(validUser);
    OAuth2RestTemplate restTemplate = AuthenticationUtil.getPasswordCredentials(USERNAME, PASSWORD);
    try {
        restTemplate.getForEntity(ROLE_SECURE_ENDPOINT, String.class);
        fail("Expected exception. None was thrown");
    } catch (UserDeniedAuthorizationException ex) {
        assertEquals(HttpStatus.BAD_REQUEST.value(), ex.getHttpErrorCode());
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}

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

/**
 * Test authentication failure to role secure endpoint that requires the ROLE_PASSWORD role
 * which the client credentials client does not have
 *//*from w  ww . ja v a 2 s  .co  m*/
@Test
public void testClientCredentialsInvalidRole() {
    OAuth2RestTemplate restTemplate = AuthenticationUtil.getClientCredentials();
    try {
        restTemplate.getForEntity(ROLE_SECURE_ENDPOINT, String.class);
        fail("Expected exception. None was thrown");
    } catch (UserDeniedAuthorizationException ex) {
        assertEquals(HttpStatus.BAD_REQUEST.value(), ex.getHttpErrorCode());
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}