From bf63ef8e1a2c4a7651281e10489115d43b29b2f7 Mon Sep 17 00:00:00 2001 From: pasindu Date: Mon, 20 Nov 2023 12:15:37 +0530 Subject: [PATCH 1/2] Reuse AccessTokenInfo class --- .../pom.xml | 9 +- .../rest/api/APIApplicationServices.java | 2 +- .../rest/api/APIApplicationServicesImpl.java | 15 +++- .../rest/api/PublisherRESTAPIServices.java | 3 +- .../api/PublisherRESTAPIServicesImpl.java | 90 +++++++++---------- .../pom.xml | 10 ++- .../publisher/APIPublisherServiceImpl.java | 2 +- 7 files changed, 78 insertions(+), 53 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml index 60f7054d04..cbb8a179cf 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml @@ -84,6 +84,11 @@ okhttp compile + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.identity.jwt.client.extension + provided + @@ -121,7 +126,9 @@ org.wso2.carbon.apimgt.impl;version="${carbon.api.mgt.version.range}", org.wso2.carbon.apimgt.impl.utils;version="${carbon.api.mgt.version.range}", org.wso2.carbon.apimgt.impl.internal;version="${carbon.api.mgt.version.range}", - org.json + org.json, + io.entgra.device.mgt.core.identity.jwt.client.extension, + io.entgra.device.mgt.core.identity.jwt.client.extension.dto 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 d628c4ce25..9e8e86d419 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 @@ -19,7 +19,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; public interface APIApplicationServices { 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 05ecf1fd9e..f3a9827c6d 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 @@ -19,11 +19,12 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import org.json.JSONObject; import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -118,7 +119,17 @@ public class APIApplicationServicesImpl implements APIApplicationServices { try { Response response = client.newCall(request).execute(); - return gson.fromJson(response.body().string(), AccessTokenInfo.class); + + AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); + if (response != null) { + JSONObject responseObject = new JSONObject(response.body().string()); + accessTokenInfo.setAccessToken(responseObject.getString("access_token")); + accessTokenInfo.setRefreshToken(responseObject.getString("refresh_token")); + accessTokenInfo.setScopes(responseObject.getString("scope")); + accessTokenInfo.setTokenType(responseObject.getString("token_type")); + accessTokenInfo.setExpiresIn(responseObject.getInt("expires_in")); + } + return accessTokenInfo; } catch (IOException e) { msg = "Error occurred while processing the response"; log.error(msg, e); 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/PublisherRESTAPIServices.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/PublisherRESTAPIServices.java index b86437b6f3..387b1ed54f 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/PublisherRESTAPIServices.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/PublisherRESTAPIServices.java @@ -20,11 +20,10 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo; 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; -import org.json.JSONObject; import java.util.List; 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/PublisherRESTAPIServicesImpl.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/PublisherRESTAPIServicesImpl.java index 8ba8bb12f7..3b7870473c 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/PublisherRESTAPIServicesImpl.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/PublisherRESTAPIServicesImpl.java @@ -22,7 +22,7 @@ import com.google.gson.Gson; import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo; 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; @@ -57,7 +57,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getAllScopesUrl) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .get() .build(); @@ -69,7 +69,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return getScopes(apiApplicationKey, refreshedAccessToken); @@ -99,7 +99,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getScopeUrl) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .head() .build(); try { @@ -109,7 +109,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key); @@ -156,7 +156,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(addNewSharedScopeEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -167,7 +167,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return addNewSharedScope(apiApplicationKey, refreshedAccessToken, scope); @@ -210,7 +210,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(updateScopeUrl) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .put(requestBody) .build(); @@ -221,7 +221,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); @@ -248,7 +248,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getAllApi) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .get() .build(); @@ -259,7 +259,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return getApi(apiApplicationKey, refreshedAccessToken, apiUuid); @@ -286,7 +286,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getAllApis) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .get() .build(); @@ -298,7 +298,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return getApis(apiApplicationKey, refreshedAccessToken); @@ -426,7 +426,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(addAPIEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -437,7 +437,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return addAPI(apiApplicationKey, refreshedAccessToken, api); @@ -565,7 +565,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(updateAPIEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .put(requestBody) .build(); @@ -576,7 +576,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return updateApi(apiApplicationKey, refreshedAccessToken, api); @@ -611,7 +611,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { .url(saveAsyncAPI) .addHeader(Constants.HEADER_CONTENT_TYPE, "multipart/form-data") .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .put(requestBody) .build(); @@ -622,7 +622,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return saveAsyncApiDefinition(apiApplicationKey, refreshedAccessToken, uuid, asyncApiDefinition); @@ -651,7 +651,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getAPIMediationEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .get() .build(); @@ -663,7 +663,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return getAllApiSpecificMediationPolicies(apiApplicationKey, refreshedAccessToken, apiUuid); @@ -699,7 +699,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { .url(addAPIMediation) .addHeader(Constants.HEADER_CONTENT_TYPE, "multipart/form-data") .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -710,7 +710,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return addApiSpecificMediationPolicy(apiApplicationKey, refreshedAccessToken, uuid, mediation); @@ -740,7 +740,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(deleteApiMediationEndPOint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .delete() .build(); @@ -751,7 +751,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return deleteApiSpecificMediationPolicy(apiApplicationKey, refreshedAccessToken, uuid, mediation); @@ -783,7 +783,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(changeAPIStatusEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -794,7 +794,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return changeLifeCycleStatus(apiApplicationKey, refreshedAccessToken, uuid, action); @@ -824,7 +824,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getAPIRevisionsEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .get() .build(); @@ -836,7 +836,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return getAPIRevisions(apiApplicationKey, refreshedAccessToken, uuid, deploymentStatus); @@ -868,7 +868,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(addNewScope) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -879,7 +879,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return addAPIRevision(apiApplicationKey, refreshedAccessToken, apiRevision); @@ -917,7 +917,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(deployAPIRevisionEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -928,7 +928,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return deployAPIRevision(apiApplicationKey, refreshedAccessToken, uuid, apiRevisionId, @@ -969,7 +969,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(undeployAPIRevisionEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -980,7 +980,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return undeployAPIRevisionDeployment(apiApplicationKey, refreshedAccessToken, apiRevisionDeployment, uuid); @@ -1010,7 +1010,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(apiRevisionEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .delete() .build(); @@ -1021,7 +1021,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return deleteAPIRevision(apiApplicationKey, refreshedAccessToken, apiRevision, uuid); @@ -1049,7 +1049,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getDocumentationsEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .get() .build(); @@ -1061,7 +1061,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return getDocumentations(apiApplicationKey, refreshedAccessToken, uuid); @@ -1090,7 +1090,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { Request request = new Request.Builder() .url(getDocumentationsEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .delete() .build(); @@ -1101,7 +1101,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return deleteDocumentations(apiApplicationKey, refreshedAccessToken, uuid, documentID); @@ -1141,7 +1141,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { .url(addNewScope) .addHeader(Constants.HEADER_CONTENT_TYPE, Constants.APPLICATION_JSON) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -1152,7 +1152,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return addDocumentation(apiApplicationKey, refreshedAccessToken, uuid, documentation); @@ -1187,7 +1187,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { .url(addDocumentationContentEndPoint) .addHeader(Constants.HEADER_CONTENT_TYPE, "multipart/form-data") .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) + + accessTokenInfo.getAccessToken()) .post(requestBody) .build(); @@ -1198,7 +1198,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return addDocumentationContent(apiApplicationKey, refreshedAccessToken, apiUuid, docId, docContent); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml index 16d7e5c1c5..08f4a29269 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml @@ -134,6 +134,11 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.device.mgt.core + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.identity.jwt.client.extension + provided + @@ -205,7 +210,10 @@ org.wso2.carbon.utils;version="4.6", org.wso2.carbon.utils.multitenancy;version="4.6", org.apache.commons.lang, - org.json + org.json, + io.entgra.device.mgt.core.identity.jwt.client.extension, + io.entgra.device.mgt.core.identity.jwt.client.extension.dto, + io.entgra.device.mgt.core.identity.jwt.client.extension.exception jsr311-api;scope=compile|runtime;inline=false diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index db7e58a32b..b5a2907ee1 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -26,7 +26,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServi import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo; 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; -- 2.36.3 From 8540630c108d9e6bde1f81b3c1624ab2c26a7e8f Mon Sep 17 00:00:00 2001 From: pasindu Date: Wed, 22 Nov 2023 14:06:17 +0530 Subject: [PATCH 2/2] Catch server response when calling token endpoint --- .../rest/api/APIApplicationServices.java | 8 +++-- .../rest/api/APIApplicationServicesImpl.java | 24 +++++++++---- .../publisher/APIPublisherServiceImpl.java | 35 ++++++++++++++++--- 3 files changed, 54 insertions(+), 13 deletions(-) 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 9e8e86d419..0e6e2bb00c 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 @@ -19,6 +19,8 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; @@ -26,8 +28,10 @@ public interface APIApplicationServices { APIApplicationKey createAndRetrieveApplicationCredentials() throws APIServicesException; - AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIServicesException; + AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) + throws APIServicesException, BadRequestException, UnexpectedResponseException; - AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) throws APIServicesException; + AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) + throws APIServicesException, BadRequestException, UnexpectedResponseException; } 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 f3a9827c6d..fabc1aec14 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 @@ -20,6 +20,11 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.Documentation; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; +import org.apache.commons.httpclient.HttpStatus; +import org.json.JSONArray; import org.json.JSONObject; import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; @@ -36,6 +41,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.impl.APIManagerConfiguration; import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder; + import java.io.IOException; public class APIApplicationServicesImpl implements APIApplicationServices { @@ -81,7 +87,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { @Override public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) - throws APIServicesException { + throws APIServicesException, BadRequestException, UnexpectedResponseException { String userName = config.getFirstProperty(Constants.SERVER_USER); String userPassword = config.getFirstProperty(Constants.SERVER_PASSWORD); @@ -96,7 +102,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { @Override public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret) - throws APIServicesException { + throws APIServicesException, BadRequestException, UnexpectedResponseException { JSONObject params = new JSONObject(); params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE); @@ -106,7 +112,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } public AccessTokenInfo getToken(JSONObject nameValuePairs, String clientId, String clientSecret) - throws APIServicesException { + throws APIServicesException, UnexpectedResponseException, BadRequestException { String tokenEndPoint = config.getFirstProperty(Constants.TOKE_END_POINT); @@ -119,17 +125,23 @@ public class APIApplicationServicesImpl implements APIApplicationServices { try { Response response = client.newCall(request).execute(); - AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); - if (response != null) { + if (HttpStatus.SC_OK == response.code()) { JSONObject responseObject = new JSONObject(response.body().string()); accessTokenInfo.setAccessToken(responseObject.getString("access_token")); accessTokenInfo.setRefreshToken(responseObject.getString("refresh_token")); accessTokenInfo.setScopes(responseObject.getString("scope")); accessTokenInfo.setTokenType(responseObject.getString("token_type")); accessTokenInfo.setExpiresIn(responseObject.getInt("expires_in")); + return accessTokenInfo; + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { + String msg = "Bad Request, Invalid request body"; + log.error(msg); + throw new BadRequestException(msg); + } else { + String msg = "Response : " + response.code() + response.body(); + throw new UnexpectedResponseException(msg); } - return accessTokenInfo; } catch (IOException e) { msg = "Error occurred while processing the response"; log.error(msg, e); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index b5a2907ee1..9026103fe7 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -119,7 +119,15 @@ public class APIPublisherServiceImpl implements APIPublisherService { } catch (APIServicesException e) { String errorMsg = "Error occurred while generating the API application"; log.error(errorMsg, e); - throw new APIManagerPublisherException(e); + throw new APIManagerPublisherException(errorMsg, e); + } catch (BadRequestException e) { + String errorMsg = "Error while calling APIs"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(errorMsg, e); + } catch (UnexpectedResponseException e) { + String errorMsg = "Unexpected response from the server"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(errorMsg, e); } try { @@ -455,7 +463,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl(); Scope scope = new Scope(); - for (DefaultPermission defaultPermission: defaultPermissions.getDefaultPermissions()) { + for (DefaultPermission defaultPermission : defaultPermissions.getDefaultPermissions()) { //todo check whether scope is available or not ScopeMapping scopeMapping = defaultPermission.getScopeMapping(); @@ -493,7 +501,16 @@ public class APIPublisherServiceImpl implements APIPublisherService { String errorMsg = "Error occurred while generating the API application"; log.error(errorMsg, e); throw new APIManagerPublisherException(e); + } catch (BadRequestException e) { + String errorMsg = "Error while calling APIs"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(errorMsg, e); + } catch (UnexpectedResponseException e) { + String errorMsg = "Unexpected response from the server"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(errorMsg, e); } + UserStoreManager userStoreManager; try { @@ -627,6 +644,14 @@ public class APIPublisherServiceImpl implements APIPublisherService { String errorMsg = "Error occurred while generating the API application"; log.error(errorMsg, e); throw new APIManagerPublisherException(e); + } catch (BadRequestException e) { + String errorMsg = "Error while calling APIs"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(errorMsg, e); + } catch (UnexpectedResponseException e) { + String errorMsg = "Unexpected response from the server"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(errorMsg, e); } try { @@ -677,8 +702,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { * @throws APIManagerPublisherException If the method receives invalid permission to update. */ private void updateScopes (String roleName, PublisherRESTAPIServices publisherRESTAPIServices, - APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, - Scope[] scopeList, String[] permissions, Map permScopeMap, boolean removingPermissions ) + APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, + Scope[] scopeList, String[] permissions, Map permScopeMap, boolean removingPermissions) throws APIManagerPublisherException { for (String permission : permissions) { String scopeValue = permScopeMap.get(permission); @@ -722,7 +747,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { // todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list log.warn(scope.getName() + " not available as shared scope"); } - } catch (APIServicesException | BadRequestException | UnexpectedResponseException e) { + } catch (APIServicesException | BadRequestException | UnexpectedResponseException e) { log.error("Error occurred while updating role scope mapping via APIM REST endpoint.", e); } break; -- 2.36.3