Skip to content

Commit

Permalink
fixing qsg issues due to the change of DCR application
Browse files Browse the repository at this point in the history
  • Loading branch information
inoshperera committed Jul 5, 2017
1 parent 978037e commit eb71d18
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -74,14 +75,21 @@ public static EMMQSGConfig initConfig() {
private static ClientCredentials getClientCredentials() {
ClientCredentials clientCredentials = null;
HashMap<String, String> headers = new HashMap<String, String>();
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);
Expand Down

0 comments on commit eb71d18

Please sign in to comment.