List of usage examples for org.springframework.security.oauth2.common.exceptions InvalidGrantException getHttpErrorCode
@Override public int getHttpErrorCode()
From source file:com.bcknds.demo.oauth2.security.PasswordAuthenticationTests.java
/** * Test using a bad username//from ww w . j a v a2s . c o m */ @Test public void testBadUsername() { OAuth2RestTemplate restTemplate = AuthenticationUtil.getPasswordCredentials("badUsername", PASSWORD); try { restTemplate.getAccessToken(); fail("Expected OAuth2AccessDeniedException, but none was thrown"); } catch (OAuth2AccessDeniedException ex) { if (ex.getCause() instanceof InvalidGrantException) { InvalidGrantException clientException = (InvalidGrantException) 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 InvalidGrantException. Got %s", ex.getCause().getClass().getName())); } } catch (Exception ex) { fail(ex.getMessage()); } }
From source file:com.bcknds.demo.oauth2.security.PasswordAuthenticationTests.java
/** * Test using a bad username//w w w . j av a 2 s.com */ @Test public void testBadPassword() { OAuth2RestTemplate restTemplate = AuthenticationUtil.getPasswordCredentials(USERNAME, "badPassword"); try { restTemplate.getAccessToken(); fail("Expected OAuth2AccessDeniedException, but none was thrown"); } catch (OAuth2AccessDeniedException ex) { if (ex.getCause() instanceof InvalidGrantException) { InvalidGrantException clientException = (InvalidGrantException) 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 InvalidGrantException. Got %s", ex.getCause().getClass().getName())); } } catch (Exception ex) { fail(ex.getMessage()); } }