private Map<String, Object> parseToken(String tokenString) { String[] tokenParts = tokenString.split("\\."); if (tokenParts.length != 3) { // The token should have three parts (header, body and signature) separated by a dot. It doesn't, so we consider it as invalid. return Collections.emptyMap(); } String body = decode(tokenParts[1]); return JsonUtil.convertJsonToMap(body); }
private CloudResources getKnownRemoteResources(ApplicationArchive archive) throws IOException { CloudResources archiveResources = new CloudResources(archive); String json = JsonUtil.convertToJson(archiveResources); HttpHeaders headers = new HttpHeaders(); headers.setContentType(JsonUtil.JSON_MEDIA_TYPE); HttpEntity<String> requestEntity = new HttpEntity<String>(json, headers); ResponseEntity<String> responseEntity = getRestTemplate().exchange(getUrl("/v2/resource_match"), HttpMethod.PUT, requestEntity, String.class); List<CloudResource> cloudResources = JsonUtil.convertJsonToCloudResourceList(responseEntity.getBody()); return new CloudResources(cloudResources); }
@Override public void createSecurityGroup(String name, InputStream jsonRulesFile) { doCreateSecurityGroup(name, JsonUtil.convertToJsonList(jsonRulesFile)); }
@Override public Map<String, Object> getApplicationEnvironment(UUID appGuid) { String url = getUrl("/v2/apps/{guid}/env"); Map<String, Object> urlVars = new HashMap<>(); urlVars.put("guid", appGuid); String resp = restTemplate.getForObject(url, String.class, urlVars); return JsonUtil.convertJsonToMap(resp); }
private CloudResources getKnownRemoteResources(ApplicationArchive archive) throws IOException { CloudResources archiveResources = new CloudResources(archive); String json = JsonUtil.convertToJson(archiveResources); HttpHeaders headers = new HttpHeaders(); headers.setContentType(JsonUtil.JSON_MEDIA_TYPE); HttpEntity<String> requestEntity = new HttpEntity<String>(json, headers); ResponseEntity<String> responseEntity = getRestTemplate().exchange(getUrl("/v2/resource_match"), HttpMethod.PUT, requestEntity, String.class); List<CloudResource> cloudResources = JsonUtil.convertJsonToCloudResourceList(responseEntity.getBody()); return new CloudResources(cloudResources); }
@Override public void createSecurityGroup(String name, InputStream jsonRulesFile) { doCreateSecurityGroup(name, JsonUtil.convertToJsonList(jsonRulesFile)); }
private Map<String, Object> parseToken(String tokenString) { String[] tokenParts = tokenString.split("\\."); if (tokenParts.length != 3) { // The token should have three parts (header, body and signature) separated by a dot. It doesn't, so we consider it as invalid. return Collections.emptyMap(); } String body = decode(tokenParts[1]); return JsonUtil.convertJsonToMap(body); }
@Override public void updateSecurityGroup(String name, InputStream jsonRulesFile) { CloudSecurityGroup oldGroup = getSecurityGroup(name); doUpdateSecurityGroup(oldGroup, name, JsonUtil.convertToJsonList(jsonRulesFile)); }
@Override public Map<String, Object> getApplicationEnvironment(UUID appGuid) { String url = getUrl("/v2/apps/{guid}/env"); Map<String, Object> urlVars = new HashMap(); urlVars.put("guid", appGuid); String resp = restTemplate.getForObject(url, String.class, urlVars); return JsonUtil.convertJsonToMap(resp); }
@Override public void updateSecurityGroup(String name, InputStream jsonRulesFile) { CloudSecurityGroup oldGroup = doGetSecurityGroup(name, true); doUpdateSecurityGroup(oldGroup, name, JsonUtil.convertToJsonList(jsonRulesFile)); }
@SuppressWarnings("unchecked") private String addPageOfResources(String nextUrl, List<Map<String, Object>> allResources) { String resp = getRestTemplate().getForObject(getUrl(nextUrl), String.class); Map<String, Object> respMap = JsonUtil.convertJsonToMap(resp); List<Map<String, Object>> newResources = (List<Map<String, Object>>) respMap.get("resources"); if (newResources != null && newResources.size() > 0) { allResources.addAll(newResources); } return (String) respMap.get("next_url"); }
@SuppressWarnings("unchecked") private String addPageOfResources(String nextUrl, List<Map<String, Object>> allResources) { String resp = getRestTemplate().getForObject(getUrl(nextUrl), String.class); Map<String, Object> respMap = JsonUtil.convertJsonToMap(resp); List<Map<String, Object>> newResources = (List<Map<String, Object>>) respMap.get("resources"); if (newResources != null && newResources.size() > 0) { allResources.addAll(newResources); } return (String) respMap.get("next_url"); }
public Map<String, Object> readTokenKey() { String tokenKeyURL = uaaUrl.toString() + TOKEN_KEY_ENDPOINT; ResponseEntity<String> tokenKeyResponse = restTemplate.getForEntity(tokenKeyURL, String.class); if (!tokenKeyResponse.hasBody()) { throw new IllegalStateException( MessageFormat.format("Invalid response returned from /token_key: {0}", tokenKeyResponse.getBody())); } return JsonUtil.convertJsonToMap(tokenKeyResponse.getBody()); }
public Map<String, Object> readTokenKey() { String tokenKeyURL = uaaUrl.toString() + TOKEN_KEY_ENDPOINT; ResponseEntity<String> tokenKeyResponse = restTemplate.getForEntity(tokenKeyURL, String.class); if (!tokenKeyResponse.hasBody()) { throw new IllegalStateException( MessageFormat.format("Invalid response returned from /token_key: {0}", tokenKeyResponse.getBody())); } return JsonUtil.convertJsonToMap(tokenKeyResponse.getBody()); }
private Map<String, Object> getInstanceInfoForApp(UUID appId, String path) { String url = getUrl("/v2/apps/{guid}/" + path); Map<String, Object> urlVars = new HashMap<String, Object>(); urlVars.put("guid", appId); String resp = getRestTemplate().getForObject(url, String.class, urlVars); return JsonUtil.convertJsonToMap(resp); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public void changePassword(String oldPassword, String newPassword) { HttpHeaders headers = new HttpHeaders(); headers.add(AUTHORIZATION_HEADER_KEY, token.getTokenType() + " " + token.getValue()); HttpEntity info = new HttpEntity(headers); ResponseEntity<String> response = restTemplate.exchange(authorizationUrl + "/userinfo", HttpMethod.GET, info, String.class); Map<String, Object> responseMap = JsonUtil.convertJsonToMap(response.getBody()); String userId = (String) responseMap.get("user_id"); Map<String, Object> body = new HashMap<String, Object>(); body.put("schemas", new String[] {"urn:scim:schemas:core:1.0"}); body.put("password", newPassword); body.put("oldPassword", oldPassword); HttpEntity<Map> httpEntity = new HttpEntity<Map>(body, headers); restTemplate.put(authorizationUrl + "/User/{id}/password", httpEntity, userId); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public void changePassword(String oldPassword, String newPassword) { HttpHeaders headers = new HttpHeaders(); headers.add(AUTHORIZATION_HEADER_KEY, token.getTokenType() + " " + token.getValue()); HttpEntity info = new HttpEntity(headers); ResponseEntity<String> response = restTemplate.exchange(authorizationUrl + "/userinfo", HttpMethod.GET, info, String.class); Map<String, Object> responseMap = JsonUtil.convertJsonToMap(response.getBody()); String userId = (String) responseMap.get("user_id"); Map<String, Object> body = new HashMap<String, Object>(); body.put("schemas", new String[] { "urn:scim:schemas:core:1.0" }); body.put("password", newPassword); body.put("oldPassword", oldPassword); HttpEntity<Map> httpEntity = new HttpEntity<Map>(body, headers); restTemplate.put(authorizationUrl + "/User/{id}/password", httpEntity, userId); }
private Map<String, Object> findApplicationResource(UUID appGuid, boolean fetchServiceInfo) { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2/apps/{app}?inline-relations-depth=1"; urlVars.put("app", appGuid); String resp = getRestTemplate().getForObject(getUrl(urlPath), String.class, urlVars); return processApplicationResource(JsonUtil.convertJsonToMap(resp), fetchServiceInfo); }
private Map<String, Object> findApplicationResource(UUID appGuid, boolean fetchServiceInfo) { Map<String, Object> urlVars = new HashMap<String, Object>(); String urlPath = "/v2/apps/{app}?inline-relations-depth=1"; urlVars.put("app", appGuid); String resp = getRestTemplate().getForObject(getUrl(urlPath), String.class, urlVars); return processApplicationResource(JsonUtil.convertJsonToMap(resp), fetchServiceInfo); }
@Override public CloudBuild createBuild(UUID packageGuid) { Map<String, Object> buildRequest = new HashMap<>(); Map<String, Object> packageMap = new HashMap<>(); packageMap.put("guid", packageGuid); buildRequest.put("package", packageMap); String buildResponse = getRestTemplate().postForObject(getUrl("/v3/builds"), buildRequest, String.class); Map<String, Object> buildEntity = JsonUtil.convertJsonToMap(buildResponse); return resourceMapper.mapResource(buildEntity, CloudBuild.class); }