use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project carbon-apimgt by wso2.
the class SolaceAdminApis method applicationPatchRemoveSubscription.
/**
* Remove subscriptions to application in Solace and update the application
*
* @param organization name of the Organization
* @param application Application to be checked in solace
* @param apiProductsToRemove List of API products to remove from subscriptions
* @return CloseableHttpResponse of the PATCH call
*/
public CloseableHttpResponse applicationPatchRemoveSubscription(String organization, Application application, List<String> apiProductsToRemove) {
URL serviceEndpointURL = new URL(baseUrl);
HttpClient httpClient = APIUtil.getHttpClient(serviceEndpointURL.getPort(), serviceEndpointURL.getProtocol());
HttpPatch httpPatch = new HttpPatch(baseUrl + "/" + organization + "/developers/" + developerUserName + "/apps/" + application.getUUID());
httpPatch.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64EncodedCredentials());
httpPatch.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
// retrieve existing API products in the app
ArrayList<String> apiProducts = new ArrayList<>();
try {
apiProducts = retrieveApiProductsInAnApplication(applicationGet(organization, application.getUUID(), "default"), apiProducts);
} catch (IOException e) {
log.error(e.getMessage());
}
// remove API product from arrayList
apiProducts.removeAll(apiProductsToRemove);
org.json.JSONObject requestBody = buildRequestBodyForApplicationPatchSubscriptions(apiProducts);
StringEntity params = null;
try {
params = new StringEntity(requestBody.toString());
httpPatch.setEntity(params);
return APIUtil.executeHTTPRequest(httpPatch, httpClient);
} catch (IOException | APIManagementException e) {
log.error(e.getMessage());
}
return null;
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project carbon-apimgt by wso2.
the class CORSRequestHandlerTestCase method setup.
@Before
public void setup() {
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.when(APIUtil.getAllowedMethods()).thenReturn("GET,PUT,POST,DELETE,PATCH,OPTIONS");
PowerMockito.when(APIUtil.isAllowCredentials()).thenReturn(false);
PowerMockito.when(APIUtil.getAllowedOrigins()).thenReturn("*");
PowerMockito.when(APIUtil.getAllowedHeaders()).thenReturn("authorization,Access-Control-Allow-Origin,Content-Type,SOAPAction");
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method getSolaceAdminApis.
/**
* Get and patch client id for Solace application
*
* @return SolaceAdminApis object to invoke Solace
* @throws APIManagementException If the Solace env configuration if not provided properly
*/
public static SolaceAdminApis getSolaceAdminApis() throws APIManagementException {
Map<String, Environment> thirdPartyEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
Environment solaceEnvironment = null;
for (Map.Entry<String, Environment> entry : thirdPartyEnvironments.entrySet()) {
if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
solaceEnvironment = entry.getValue();
}
}
if (solaceEnvironment != null) {
return new SolaceAdminApis(solaceEnvironment.getServerURL(), solaceEnvironment.getUserName(), solaceEnvironment.getPassword(), solaceEnvironment.getAdditionalProperties().get(SolaceConstants.SOLACE_ENVIRONMENT_DEV_NAME));
} else {
throw new APIManagementException("Solace Environment configurations are not provided properly");
}
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project carbon-apimgt by wso2.
the class SolaceNotifierUtils method patchSolaceApplicationClientId.
/**
* Get and patch client id for Solace application
*
* @param organization Name of the Organization
* @param application Solace application
* @param consumerKey Consumer key to be used when patching
* @param consumerSecret Consumer secret to be used when patching
* @throws APIManagementException If the Solace env configuration if not provided properly
*/
public static void patchSolaceApplicationClientId(String organization, Application application, String consumerKey, String consumerSecret) throws APIManagementException {
SolaceAdminApis solaceAdminApis = SolaceNotifierUtils.getSolaceAdminApis();
if (log.isDebugEnabled()) {
log.info("Identified as Solace Application. Patching CliendID and Secret in solace application.....");
}
CloseableHttpResponse response = solaceAdminApis.patchClientIdForApplication(organization, application, consumerKey, consumerSecret);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
log.info("CliendID and Secret patched successfully for " + application.getName() + " Solace application");
} else {
log.error("Error while patching clientID for Solace application. : " + response.getStatusLine().toString());
}
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.Patch in project carbon-apimgt by wso2.
the class APIUtil method createSwaggerJSONContent.
/**
* Create API Definition in JSON
*
* @param api API
* @throws org.wso2.carbon.apimgt.api.APIManagementException if failed to generate the content and save
* @deprecated
*/
@Deprecated
public static String createSwaggerJSONContent(API api) throws APIManagementException {
APIIdentifier identifier = api.getId();
String organization = api.getOrganization();
Environment environment = (Environment) getEnvironments(organization).values().toArray()[0];
String endpoints = environment.getApiGatewayEndpoint();
String[] endpointsSet = endpoints.split(",");
String apiContext = api.getContext();
String version = identifier.getVersion();
Set<URITemplate> uriTemplates = api.getUriTemplates();
String description = api.getDescription();
// With the new context version strategy, the URL prefix is the apiContext. the verison will be embedded in
// the apiContext.
String urlPrefix = apiContext;
if (endpointsSet.length < 1) {
throw new APIManagementException("Error in creating JSON representation of the API" + identifier.getApiName());
}
if (description == null || "".equals(description)) {
description = "";
} else {
description = description.trim();
}
Map<String, List<Operation>> uriTemplateDefinitions = new HashMap<String, List<Operation>>();
List<APIResource> apis = new ArrayList<APIResource>();
for (URITemplate template : uriTemplates) {
List<Operation> ops;
List<Parameter> parameters;
String path = urlPrefix + APIUtil.removeAnySymbolFromUriTempate(template.getUriTemplate());
/* path exists in uriTemplateDefinitions */
if (uriTemplateDefinitions.get(path) != null) {
ops = uriTemplateDefinitions.get(path);
parameters = new ArrayList<Parameter>();
String httpVerb = template.getHTTPVerb();
/* For GET and DELETE Parameter name - Query Parameters */
if (Constants.Configuration.HTTP_METHOD_GET.equals(httpVerb) || Constants.Configuration.HTTP_METHOD_DELETE.equals(httpVerb)) {
Parameter queryParam = new Parameter(APIConstants.OperationParameter.QUERY_PARAM_NAME, APIConstants.OperationParameter.QUERY_PARAM_DESCRIPTION, APIConstants.OperationParameter.PAYLOAD_PARAM_TYPE, false, false, "String");
parameters.add(queryParam);
} else {
/* For POST, PUT and PATCH Parameter name - Payload */
Parameter payLoadParam = new Parameter(APIConstants.OperationParameter.PAYLOAD_PARAM_NAME, APIConstants.OperationParameter.PAYLOAD_PARAM_DESCRIPTION, APIConstants.OperationParameter.PAYLOAD_PARAM_TYPE, false, false, "String");
parameters.add(payLoadParam);
}
Parameter authParam = new Parameter(APIConstants.OperationParameter.AUTH_PARAM_NAME, APIConstants.OperationParameter.AUTH_PARAM_DESCRIPTION, APIConstants.OperationParameter.AUTH_PARAM_TYPE, false, false, "String");
parameters.add(authParam);
if (!"OPTIONS".equals(httpVerb)) {
Operation op = new Operation(httpVerb, description, description, parameters);
ops.add(op);
}
} else {
/* path not exists in uriTemplateDefinitions */
ops = new ArrayList<Operation>();
parameters = new ArrayList<Parameter>();
String httpVerb = template.getHTTPVerb();
/* For GET and DELETE Parameter name - Query Parameters */
if (Constants.Configuration.HTTP_METHOD_GET.equals(httpVerb) || Constants.Configuration.HTTP_METHOD_DELETE.equals(httpVerb)) {
Parameter queryParam = new Parameter(APIConstants.OperationParameter.QUERY_PARAM_NAME, APIConstants.OperationParameter.QUERY_PARAM_DESCRIPTION, APIConstants.OperationParameter.PAYLOAD_PARAM_TYPE, false, false, "String");
parameters.add(queryParam);
} else {
/* For POST,PUT and PATCH Parameter name - Payload */
Parameter payLoadParam = new Parameter(APIConstants.OperationParameter.PAYLOAD_PARAM_NAME, APIConstants.OperationParameter.PAYLOAD_PARAM_DESCRIPTION, APIConstants.OperationParameter.PAYLOAD_PARAM_TYPE, false, false, "String");
parameters.add(payLoadParam);
}
Parameter authParam = new Parameter(APIConstants.OperationParameter.AUTH_PARAM_NAME, APIConstants.OperationParameter.AUTH_PARAM_DESCRIPTION, APIConstants.OperationParameter.AUTH_PARAM_TYPE, false, false, "String");
parameters.add(authParam);
if (!"OPTIONS".equals(httpVerb)) {
Operation op = new Operation(httpVerb, description, description, parameters);
ops.add(op);
}
uriTemplateDefinitions.put(path, ops);
}
}
final Set<Entry<String, List<Operation>>> entries = uriTemplateDefinitions.entrySet();
for (Entry entry : entries) {
APIResource apiResource = new APIResource((String) entry.getKey(), description, (List<Operation>) entry.getValue());
apis.add(apiResource);
}
APIDefinition apidefinition = new APIDefinition(version, APIConstants.SWAGGER_VERSION, endpointsSet[0], apiContext, apis);
Gson gson = new Gson();
return gson.toJson(apidefinition);
}
Aggregations