use of org.wso2.mdm.qsg.dto.EMMQSGConfig in project product-iots by wso2.
the class QSGUtils method getClientCredentials.
private static ClientCredentials getClientCredentials() {
ClientCredentials clientCredentials = null;
HashMap<String, String> headers = new HashMap<String, String>();
EMMQSGConfig emmqsgConfig = EMMQSGConfig.getInstance();
String dcrEndPoint = emmqsgConfig.getDcrEndPoint();
// Set the DCR payload
JSONObject obj = new JSONObject();
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);
if (httpResponse.getResponseCode() == Constants.HTTPStatus.CREATED) {
try {
JSONObject jsonObject = (JSONObject) new JSONParser().parse(httpResponse.getResponse());
clientCredentials = new ClientCredentials();
clientCredentials.setClientKey((String) jsonObject.get("client_id"));
clientCredentials.setClientSecret((String) jsonObject.get("client_secret"));
} catch (ParseException e) {
e.printStackTrace();
}
}
return clientCredentials;
}
use of org.wso2.mdm.qsg.dto.EMMQSGConfig in project product-iots by wso2.
the class QSGUtils method initConfig.
public static EMMQSGConfig initConfig() {
Properties props = new Properties();
InputStream input = null;
EMMQSGConfig emmConfig = null;
try {
input = new FileInputStream("config.properties");
// load a properties file and set the properties
props.load(input);
emmConfig = EMMQSGConfig.getInstance();
emmConfig.setEmmHost(props.getProperty("emm-host"));
emmConfig.setDcrEndPoint(props.getProperty("dcr-endpoint"));
emmConfig.setOauthEndPoint(props.getProperty("oauth-endpoint"));
emmConfig.setUsername(props.getProperty("username"));
emmConfig.setPassword(props.getProperty("password"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return emmConfig;
}
Aggregations