From 0e622450648044a678c3a3ee7e7d118e3407c239 Mon Sep 17 00:00:00 2001 From: pasindu Date: Wed, 7 Jun 2023 23:19:57 +0530 Subject: [PATCH] modify generateAndRetrieveApplicationKeys method --- .../APIManagementProviderServiceImpl.java | 25 ++++++++++++++----- .../rest/api/APIApplicationServices.java | 5 +--- .../rest/api/APIApplicationServicesImpl.java | 5 +--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java index 40037475ec..1e8fc44518 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -22,6 +22,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationService import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices; import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; @@ -110,9 +111,21 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe ConsumerRESTAPIServices consumerRESTAPIServices = APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices(); + APIApplicationKey apiApplicationKey; + io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo accessTokenInfo; + try { + apiApplicationKey = apiApplicationServices.generateAndRetrieveApplicationKeys(username, password); + accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + } catch (APIServicesException e) { + String errorMsg = "Error occurred while generating the API application"; + log.error(errorMsg, e); + throw new APIManagerException(e); + } + try { io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications = - consumerRESTAPIServices.getAllApplications(null, null, applicationName); + consumerRESTAPIServices.getAllApplications(apiApplicationKey, accessTokenInfo, applicationName); List uniqueApiList = new ArrayList<>(); @@ -126,7 +139,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe if (!"carbon.super".equals(tenantDomain)) { headerParams.put("X-WSO2-Tenant", "carbon.super"); } - apiInfos = consumerRESTAPIServices.getAllApis(null, null, queryParams, headerParams); + apiInfos = consumerRESTAPIServices.getAllApis(apiApplicationKey, accessTokenInfo, queryParams, headerParams); uniqueApiList.addAll(List.of(apiInfos)); Set taggedAPISet = new HashSet<>(uniqueApiList); @@ -139,7 +152,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe new io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application(); application.setName(applicationName); - application = consumerRESTAPIServices.createApplication(null, null, application); + application = consumerRESTAPIServices.createApplication(apiApplicationKey, accessTokenInfo, application); List subscriptions = new ArrayList<>(); for (APIInfo apiInfo : uniqueApiList) { Subscription subscription = new Subscription(); @@ -147,12 +160,12 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe subscription.setApplicationId(application.getApplicationId()); subscriptions.add(subscription); } - consumerRESTAPIServices.createSubscriptions(null, null, subscriptions); + consumerRESTAPIServices.createSubscriptions(apiApplicationKey, accessTokenInfo, subscriptions); } else { if (applications.length == 1) { Optional application = Arrays.stream(applications).findFirst(); - Subscription[] subscriptions = consumerRESTAPIServices.getAllSubscriptions(null, null, + Subscription[] subscriptions = consumerRESTAPIServices.getAllSubscriptions(apiApplicationKey, accessTokenInfo, application.get().getApplicationId()); for (Subscription subscription : subscriptions) { if (uniqueApiList.contains(subscription.getApiInfo())) { @@ -171,7 +184,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe subscription.setApplicationId(application.get().getApplicationId()); subscriptionList.add(subscription); } - consumerRESTAPIServices.createSubscriptions(null, null, subscriptionList); + consumerRESTAPIServices.createSubscriptions(apiApplicationKey, accessTokenInfo, subscriptionList); } else { String msg = "Found more than one application for application name: " + applicationName; log.error(msg); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java index 5b19bf9e3c..1cdceff56a 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java @@ -26,10 +26,7 @@ public interface APIApplicationServices { APIApplicationKey createAndRetrieveApplicationCredentials() throws APIServicesException; - APIApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String tags[], - String keyType, String username, - boolean isAllowedAllDomains, - String validityTime, String password) + APIApplicationKey generateAndRetrieveApplicationKeys(String username, String password) throws APIServicesException; AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIServicesException; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index 7209041ad6..8e80e1f5f5 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -80,10 +80,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } @Override - public APIApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String tags[], - String keyType, String username, - boolean isAllowedAllDomains, - String validityTime, String password) + public APIApplicationKey generateAndRetrieveApplicationKeys(String username, String password) throws APIServicesException { String applicationEndpoint = config.getFirstProperty(Constants.DCR_END_POINT);