use of org.wso2.carbon.databridge.commons.Credentials in project carbon-apimgt by wso2.
the class SolaceAdminApis method buildRequestBodyForCreatingApp.
/**
* Build the request body for application creation request
*
* @param application Application to be created in Solace
* @param apiProducts List of API products to add as subscriptions
* @return org.json.JSON Object of request body
*/
private org.json.JSONObject buildRequestBodyForCreatingApp(Application application, ArrayList<String> apiProducts) throws APIManagementException {
org.json.JSONObject requestBody = new org.json.JSONObject();
String appName = application.getName();
requestBody.put("name", application.getUUID());
requestBody.put("expiresIn", -1);
requestBody.put("displayName", appName);
// add api products
org.json.JSONArray apiProductsArray = new org.json.JSONArray();
for (String x : apiProducts) {
apiProductsArray.put(x);
}
requestBody.put("apiProducts", apiProductsArray);
// add credentials
org.json.JSONObject credentialsBody = new org.json.JSONObject();
credentialsBody.put("expiresAt", -1);
credentialsBody.put("issuedAt", 0);
org.json.JSONObject credentialsSecret = new org.json.JSONObject();
// Set consumer key and secret for new application
if (application.getKeys().isEmpty()) {
throw new APIManagementException("Application keys are not generated for " + appName);
} else {
credentialsSecret.put("consumerKey", application.getKeys().get(0).getConsumerKey());
credentialsSecret.put("consumerSecret", application.getKeys().get(0).getConsumerSecret());
}
credentialsBody.put("secret", credentialsSecret);
requestBody.put("credentials", credentialsBody);
return requestBody;
}
Aggregations