List of usage examples for org.springframework.security.oauth2.common.exceptions OAuth2Exception valueOf
public static OAuth2Exception valueOf(Map<String, String> errorParams)
From source file:org.cloudfoundry.identity.uaa.integration.NativeApplicationIntegrationTests.java
/** * tests that an error occurs if you attempt to use bad client credentials. *///from www . jav a2 s . com @Test // Need a custom auth entry point to get the correct JSON response here. public void testInvalidClient() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("grant_type", "password"); formData.add("username", resource.getUsername()); formData.add("password", resource.getPassword()); formData.add("scope", "cloud_controller.read"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode("no-such-client:".getBytes("UTF-8")))); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/oauth/token", formData, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); List<String> newCookies = response.getHeaders().get("Set-Cookie"); if (newCookies != null && !newCookies.isEmpty()) { fail("No cookies should be set. Found: " + newCookies.get(0) + "."); } assertEquals("no-store", response.getHeaders().getFirst("Cache-Control")); @SuppressWarnings("unchecked") OAuth2Exception error = OAuth2Exception.valueOf(response.getBody()); assertEquals("invalid_client", error.getOAuth2ErrorCode()); }