From 2b0d1f90a826de0d37c6be2effb913ddd2a4bb71 Mon Sep 17 00:00:00 2001 From: Pasan Tennakoon Date: Wed, 26 Mar 2025 16:08:17 +0530 Subject: [PATCH] Skip retrieve application from external KM for MAPPED keys --- .../carbon/apimgt/impl/APIConsumerImpl.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java index eacfa8cf2a47..ae62e285b367 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIConsumerImpl.java @@ -2985,23 +2985,27 @@ public boolean updateApplicationOwner(String userId, String organization, Applic KeyManagerHolder.getTenantKeyManagerInstance(tenantDomain, apiKey.getKeyManager()); } /* retrieving OAuth application information for specific consumer key */ - consumerKey = apiKey.getConsumerKey(); - OAuthApplicationInfo oAuthApplicationInfo = keyManager.retrieveApplication(consumerKey); - if (oAuthApplicationInfo.getParameter(ApplicationConstants.OAUTH_CLIENT_NAME) != null) { - OAuthAppRequest oauthAppRequest = ApplicationUtils.createOauthAppRequest(oAuthApplicationInfo. - getParameter(ApplicationConstants.OAUTH_CLIENT_NAME).toString(), null, - oAuthApplicationInfo.getCallBackURL(), null, - null, application.getTokenType(), this.tenantDomain, apiKey.getKeyManager()); - oauthAppRequest.getOAuthApplicationInfo().setAppOwner(userId); - oauthAppRequest.getOAuthApplicationInfo().setClientId(consumerKey); - /* updating the owner of the OAuth application with userId */ - OAuthApplicationInfo updatedAppInfo = keyManager.updateApplicationOwner(oauthAppRequest, - userId); - isAppUpdated = true; - audit.info("Successfully updated the owner of application " + application.getName() + - " from " + oldUserName + " to " + userId + "."); - } else { - throw new APIManagementException("Unable to retrieve OAuth application information."); + if (!APIConstants.OAuthAppMode.MAPPED.name().equalsIgnoreCase(apiKey.getCreateMode())) { + consumerKey = apiKey.getConsumerKey(); + OAuthApplicationInfo oAuthApplicationInfo = keyManager.retrieveApplication(consumerKey); + Object oauthClientName = + oAuthApplicationInfo.getParameter(ApplicationConstants.OAUTH_CLIENT_NAME); + if (oauthClientName != null) { + OAuthAppRequest oauthAppRequest = ApplicationUtils.createOauthAppRequest( + oauthClientName.toString(), null, oAuthApplicationInfo.getCallBackURL(), + null, null, application.getTokenType(), this.tenantDomain, + apiKey.getKeyManager()); + oauthAppRequest.getOAuthApplicationInfo().setAppOwner(userId); + oauthAppRequest.getOAuthApplicationInfo().setClientId(consumerKey); + /* updating the owner of the OAuth application with userId */ + OAuthApplicationInfo updatedAppInfo = keyManager.updateApplicationOwner(oauthAppRequest, + userId); + isAppUpdated = true; + audit.info("Successfully updated the owner of application " + application.getName() + + " from " + oldUserName + " to " + userId + "."); + } else { + throw new APIManagementException("Unable to retrieve OAuth application information."); + } } } } else {