From eb71d1874bc92ed129a35daf3c86586d4b8b03a2 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Wed, 5 Jul 2017 16:26:11 +0530 Subject: [PATCH] fixing qsg issues due to the change of DCR application --- .../java/org/wso2/mdm/qsg/utils/QSGUtils.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/scripts/mobile-qsg/src/main/java/org/wso2/mdm/qsg/utils/QSGUtils.java b/modules/scripts/mobile-qsg/src/main/java/org/wso2/mdm/qsg/utils/QSGUtils.java index 2372750b..6bdb95e5 100644 --- a/modules/scripts/mobile-qsg/src/main/java/org/wso2/mdm/qsg/utils/QSGUtils.java +++ b/modules/scripts/mobile-qsg/src/main/java/org/wso2/mdm/qsg/utils/QSGUtils.java @@ -21,6 +21,7 @@ package org.wso2.mdm.qsg.utils; import org.apache.commons.codec.binary.Base64; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -74,14 +75,21 @@ public class QSGUtils { private static ClientCredentials getClientCredentials() { ClientCredentials clientCredentials = null; HashMap headers = new HashMap(); - String dcrEndPoint = EMMQSGConfig.getInstance().getDcrEndPoint(); + EMMQSGConfig emmqsgConfig = EMMQSGConfig.getInstance(); + String dcrEndPoint = emmqsgConfig.getDcrEndPoint(); //Set the DCR payload JSONObject obj = new JSONObject(); - obj.put("owner", "admin"); - obj.put("clientName", "qsg"); - obj.put("grantType", "refresh_token password client_credentials"); - obj.put("tokenScope", "user:view,user:manage,user:admin:reset-password,role:view,role:manage,policy:view," + - "policy:manage,application:manage,appm:create,appm:publish,appm:update,appm:read"); + JSONArray arr = new JSONArray(); + arr.add("android"); + arr.add("device_management"); + obj.put("applicationName", "qsg"); + obj.put("tags", arr); + obj.put("isAllowedToAllDomains", false); + obj.put("isMappingAnExistingOAuthApp", false); + String authorizationStr = emmqsgConfig.getUsername() + ":" + emmqsgConfig.getPassword(); + String authHeader = "Basic " + new String(Base64.encodeBase64(authorizationStr.getBytes())); + headers.put(Constants.Header.AUTH, authHeader); + //Set the headers headers.put(Constants.Header.CONTENT_TYPE, Constants.ContentType.APPLICATION_JSON); HTTPResponse httpResponse = HTTPInvoker.sendHTTPPost(dcrEndPoint, obj.toJSONString(), headers);