From bb879f52cefd6ec4d62de9b11ed4739052a5b659 Mon Sep 17 00:00:00 2001 From: pasindu Date: Thu, 14 Sep 2023 13:30:36 +0530 Subject: [PATCH] Fix grant type update method --- .../rest/api/ConsumerRESTAPIServices.java | 2 +- .../rest/api/ConsumerRESTAPIServicesImpl.java | 25 +++++++++++-------- 2 files changed, 15 insertions(+), 12 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/ConsumerRESTAPIServices.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/ConsumerRESTAPIServices.java index 957fcfdaa72..e8342b18d50 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/ConsumerRESTAPIServices.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/ConsumerRESTAPIServices.java @@ -62,7 +62,7 @@ public interface ConsumerRESTAPIServices { throws APIServicesException, BadRequestException, UnexpectedResponseException; ApplicationKey updateGrantType(TokenInfo tokenInfo, String applicationId, String keyMapId, String keyManager, - String supportedGrantTypes, String callbackUrl) + List supportedGrantTypes, String callbackUrl) throws APIServicesException, BadRequestException, UnexpectedResponseException; KeyManager[] getAllKeyManagers(TokenInfo tokenInfo) 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/ConsumerRESTAPIServicesImpl.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/ConsumerRESTAPIServicesImpl.java index 55f3c7003f8..e5608d5cbcb 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/ConsumerRESTAPIServicesImpl.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/ConsumerRESTAPIServicesImpl.java @@ -729,7 +729,7 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices { @Override public ApplicationKey updateGrantType(TokenInfo tokenInfo, String applicationId, String keyMapId, String keyManager, - String supportedGrantTypes, String callbackUrl) + List supportedGrantTypes, String callbackUrl) throws APIServicesException, BadRequestException, UnexpectedResponseException { ApiApplicationInfo apiApplicationInfo = tokenInfo.getApiApplicationInfo(); @@ -746,16 +746,19 @@ public class ConsumerRESTAPIServicesImpl implements ConsumerRESTAPIServices { + tokenInfo.getAccessToken()); } - String payload = "{\n" + - " \"keyMappingId\": \"" + keyMapId + "\",\n" + - " \"keyManager\": \"" + keyManager + "\",\n" + - " \"supportedGrantTypes\": [\n" + - " \"" + supportedGrantTypes + "\"\n" + - " ],\n" + - " \"callbackUrl\": \"" + callbackUrl + "\",\n" + - " \"additionalProperties\": {}\n" + - "}"; - RequestBody requestBody = RequestBody.create(JSON, payload); + JSONArray supportedGrantTypeList = new JSONArray(); + for (String string : supportedGrantTypes) { + supportedGrantTypeList.put(string); + } + + JSONObject payload = new JSONObject(); + payload.put("keyMappingId", keyMapId); + payload.put("keyManager", keyManager); + payload.put("supportedGrantTypes", supportedGrantTypeList); + payload.put("callbackUrl", (callbackUrl != null ? callbackUrl : "")); + payload.put("additionalProperties", new JSONObject()); + + RequestBody requestBody = RequestBody.create(JSON, payload.toString()); builder.put(requestBody); Request request = builder.build();