List of usage examples for org.springframework.security.oauth2.common.exceptions InvalidClientException getMessage
public String getMessage()
From source file:com.ge.predix.test.utils.UaaTestUtil.java
private BaseClientDetails createOrUpdateClient(final BaseClientDetails client) { MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); headers.add("Accept", MediaType.APPLICATION_JSON_VALUE); headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE); if (StringUtils.isNotEmpty(this.zone)) { headers.add("X-Identity-Zone-Id", "uaa"); }//from w w w .j ava 2s . c o m HttpEntity<String> postEntity = new HttpEntity<String>(JSON_UTILS.serialize(client), headers); ResponseEntity<String> clientCreate = null; try { clientCreate = this.adminRestTemplate.exchange(this.uaaUrl + "/oauth/clients", HttpMethod.POST, postEntity, String.class); if (clientCreate.getStatusCode() == HttpStatus.CREATED) { return JSON_UTILS.deserialize(clientCreate.getBody(), BaseClientDetails.class); } else { throw new RuntimeException( "Unexpected return code for client create: " + clientCreate.getStatusCode()); } } catch (InvalidClientException ex) { if (ex.getMessage().equals("Client already exists: " + client.getClientId())) { HttpEntity<String> putEntity = new HttpEntity<String>(JSON_UTILS.serialize(client), headers); ResponseEntity<String> clientUpdate = this.adminRestTemplate.exchange( this.uaaUrl + "/oauth/clients/" + client.getClientId(), HttpMethod.PUT, putEntity, String.class); if (clientUpdate.getStatusCode() == HttpStatus.OK) { return JSON_UTILS.deserialize(clientUpdate.getBody(), BaseClientDetails.class); } else { throw new RuntimeException( "Unexpected return code for client update: " + clientUpdate.getStatusCode()); } } } throw new RuntimeException("Unexpected return code for client creation: " + clientCreate.getStatusCode()); }
From source file:org.springframework.security.oauth2.common.exception.OAuth2ExceptionJackson2DeserializerTests.java
@Test public void readValueInvalidClient() throws Exception { String accessToken = createResponse(OAuth2Exception.INVALID_CLIENT); InvalidClientException result = (InvalidClientException) mapper.readValue(accessToken, OAuth2Exception.class); assertEquals(DETAILS, result.getMessage()); assertEquals(null, result.getAdditionalInformation()); }
From source file:org.springframework.security.oauth2.common.exception.OAuth2ExceptionJackson2DeserializerTests.java
@Test public void readValueWithAdditionalDetails() throws Exception { String accessToken = "{\"error\": \"invalid_client\", \"error_description\": \"some detail\", \"foo\": \"bar\"}"; InvalidClientException result = (InvalidClientException) mapper.readValue(accessToken, OAuth2Exception.class); assertEquals(DETAILS, result.getMessage()); assertEquals("{foo=bar}", result.getAdditionalInformation().toString()); }
From source file:org.cloudfoundry.identity.uaa.client.ClientAdminEndpoints.java
@RequestMapping(value = "/oauth/clients/{client_id}/secret", method = RequestMethod.PUT) @ResponseBody/*from w w w . j ava2s . c o m*/ public ActionResult changeSecret(@PathVariable String client_id, @RequestBody SecretChangeRequest change) { ClientDetails clientDetails; try { clientDetails = clientDetailsService.retrieve(client_id); } catch (InvalidClientException e) { throw new NoSuchClientException("No such client: " + client_id); } try { checkPasswordChangeIsAllowed(clientDetails, change.getOldSecret()); } catch (IllegalStateException e) { throw new InvalidClientDetailsException(e.getMessage()); } ActionResult result; switch (change.getChangeMode()) { case ADD: if (!validateCurrentClientSecretAdd(clientDetails.getClientSecret())) { throw new InvalidClientDetailsException( "client secret is either empty or client already has two secrets."); } clientRegistrationService.addClientSecret(client_id, change.getSecret()); result = new ActionResult("ok", "Secret is added"); break; case DELETE: if (!validateCurrentClientSecretDelete(clientDetails.getClientSecret())) { throw new InvalidClientDetailsException( "client secret is either empty or client has only one secret."); } clientRegistrationService.deleteClientSecret(client_id); result = new ActionResult("ok", "Secret is deleted"); break; default: clientRegistrationService.updateClientSecret(client_id, change.getSecret()); result = new ActionResult("ok", "secret updated"); } clientSecretChanges.incrementAndGet(); return result; }
From source file:org.cloudfoundry.identity.uaa.oauth.ClientAdminEndpoints.java
@RequestMapping(value = "/oauth/clients/{client}/secret", method = RequestMethod.PUT) public SimpleMessage changeSecret(@PathVariable String client, @RequestBody SecretChangeRequest change) { ClientDetails clientDetails;/*from w w w. ja v a 2s .com*/ try { clientDetails = clientDetailsService.retrieve(client); } catch (InvalidClientException e) { throw new NoSuchClientException("No such client: " + client); } try { checkPasswordChangeIsAllowed(clientDetails, change.getOldSecret()); } catch (IllegalStateException e) { throw new InvalidClientDetailsException(e.getMessage()); } clientRegistrationService.updateClientSecret(client, change.getSecret()); clientSecretChanges.incrementAndGet(); return new SimpleMessage("ok", "secret updated"); }