Search in sources :

Example 46 with Credentials

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;
}
Also used : JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) JSONArray(org.json.JSONArray) JSONArray(org.json.JSONArray)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)18 HttpClient (org.apache.http.client.HttpClient)12 URL (java.net.URL)10 ArrayList (java.util.ArrayList)9 HttpGet (org.apache.http.client.methods.HttpGet)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 HttpResponse (org.apache.http.HttpResponse)8 Gson (com.google.gson.Gson)6 JSONObject (org.json.simple.JSONObject)6 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Test (org.testng.annotations.Test)6 Response (feign.Response)4 WorkflowProperties (org.wso2.carbon.apimgt.impl.dto.WorkflowProperties)4 JSONParser (org.json.simple.parser.JSONParser)3 ParseException (org.json.simple.parser.ParseException)3 DCRMServiceStub (org.wso2.carbon.apimgt.core.auth.DCRMServiceStub)3 OAuth2ServiceStubs (org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs)3 ScopeRegistration (org.wso2.carbon.apimgt.core.auth.ScopeRegistration)3