From ef47f0c20a2b83728170529a2f70cf9236081f58 Mon Sep 17 00:00:00 2001 From: pasindu Date: Fri, 8 Sep 2023 11:36:05 +0530 Subject: [PATCH] Update scopes including already existing roles --- .../apimgt/webapp/publisher/APIPublisherServiceImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 871450c824..61196a1da0 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 @@ -513,8 +513,15 @@ public class APIPublisherServiceImpl implements APIPublisherService { if (scopeObj.getString("name").equals(scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { scope.setId(scopeObj.getString("id")); + +// Including already existing roles + JSONArray existingRolesArray = (JSONArray) scopeObj.get("bindings"); + for (int j = 0; j < existingRolesArray.length(); j++) { + roleString = roleString + "," + existingRolesArray.get(j); + } } } + scope.setRoles(roleString); if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);