From 041c84a45f76e00b180c41a653ed67ebb88935ea Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Wed, 20 Dec 2023 14:40:05 +0530 Subject: [PATCH] Fix duplicate scope publishing issue --- .../publisher/APIPublisherServiceImpl.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) 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..d748e1cee9 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 @@ -456,17 +456,19 @@ public class APIPublisherServiceImpl implements APIPublisherService { Scope scope = new Scope(); for (DefaultPermission defaultPermission: defaultPermissions.getDefaultPermissions()) { - //todo check whether scope is available or not - ScopeMapping scopeMapping = defaultPermission.getScopeMapping(); - - List bindings = new ArrayList<>( - Arrays.asList(scopeMapping.getDefaultRoles().split(","))); - bindings.add(ADMIN_ROLE_KEY); - scope.setName(scopeMapping.getKey()); - scope.setDescription(scopeMapping.getName()); - scope.setDisplayName(scopeMapping.getName()); - scope.setBindings(bindings); - publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope); + if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, + defaultPermission.getScopeMapping().getKey())) { + ScopeMapping scopeMapping = defaultPermission.getScopeMapping(); + + List bindings = new ArrayList<>( + Arrays.asList(scopeMapping.getDefaultRoles().split(","))); + bindings.add(ADMIN_ROLE_KEY); + scope.setName(scopeMapping.getKey()); + scope.setDescription(scopeMapping.getName()); + scope.setDisplayName(scopeMapping.getName()); + scope.setBindings(bindings); + publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope); + } } } catch (BadRequestException | UnexpectedResponseException | APIServicesException e) { log.error("Error occurred while adding default scopes");