List of usage examples for org.springframework.security.oauth2.common.exceptions UserDeniedAuthorizationException getHttpErrorCode
public int getHttpErrorCode()
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//from w w w . java 2 s . c om */ @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 . jav a 2 s.c om*/ @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()); } }