From a633547d19ce5275fda33b22f5fdaad158d7e614 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Tue, 20 Dec 2016 13:03:19 +0530 Subject: [PATCH] IOTS-340: Fixing consumer key and consumer secret is null on api-mgt-ext --- .../APIManagementProviderServiceImpl.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java index 97dea104b2..087a6ee4a2 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -75,16 +75,9 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe "Api application creation failed for " + applicationName + " to the user " + username); } - APIKey retrievedApiApplicationKey = null; - for (APIKey apiKey : application.getKeys()) { - String applicationKeyType = apiKey.getType(); - if (applicationKeyType != null && applicationKeyType.equals(keyType)) { - retrievedApiApplicationKey = apiKey; - break; - } - } - if (retrievedApiApplicationKey != null) { - if (retrievedApiApplicationKey.getConsumerKey().equals(clientId)) { + OAuthApplicationInfo oAuthApp = application.getOAuthApp(keyType); + if (oAuthApp != null) { + if (oAuthApp.getClientId().equals(clientId)) { if (tags != null && tags.length > 0) { createApplicationAndSubscribeToAPIs(applicationName, tags, username); } @@ -152,18 +145,11 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe "Api application creation failed for " + apiApplicationName + " to the user " + username); } - APIKey retrievedApiApplicationKey = null; - for (APIKey apiKey : application.getKeys()) { - String applicationKeyType = apiKey.getType(); - if (applicationKeyType != null && applicationKeyType.equals(keyType)) { - retrievedApiApplicationKey = apiKey; - break; - } - } - if (retrievedApiApplicationKey != null) { + OAuthApplicationInfo oAuthApp = application.getOAuthApp(keyType); + if (oAuthApp != null) { ApiApplicationKey apiApplicationKey = new ApiApplicationKey(); - apiApplicationKey.setConsumerKey(retrievedApiApplicationKey.getConsumerKey()); - apiApplicationKey.setConsumerSecret(retrievedApiApplicationKey.getConsumerSecret()); + apiApplicationKey.setConsumerKey(oAuthApp.getClientId()); + apiApplicationKey.setConsumerSecret(oAuthApp.getClientSecret()); return apiApplicationKey; } String[] allowedDomains = new String[1];