diff options
author | 2022-11-12 14:29:11 +0530 | |
---|---|---|
committer | 2022-12-21 12:04:30 +0000 | |
commit | cf04a1a714ef4a1df973929dc750232b4d67d7b4 (patch) | |
tree | edd2e6e5074ba58efb98663a1ea1851208895fff /openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services | |
parent | f995db01ee95606b6cded82822a73435ebc190c8 (diff) |
Multitenancy in SDC
Issue-ID: SDC-4215
Change-Id: Ie24ba38acc9f1998d4a7e722e8f98456dab9201d
Signed-off-by: Kartik Hegde <kh00735564@techmahindra.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services')
-rw-r--r-- | openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java index 9fb6ebd8b8..af3568cd2a 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java @@ -35,12 +35,15 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import javax.annotation.PostConstruct; import javax.inject.Named; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Response; +import org.keycloak.representations.AccessToken; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.activitylog.dao.type.ActivityType; import org.openecomp.sdc.be.csar.storage.StorageFactory; import org.openecomp.sdc.common.errors.ErrorCode.ErrorCodeBuilder; import org.openecomp.sdc.common.errors.ErrorCodeAndMessage; +import org.openecomp.sdc.common.util.Multitenancy; import org.openecomp.sdc.datatypes.model.ItemType; import org.openecomp.sdc.itempermissions.impl.types.PermissionTypes; import org.openecomp.sdc.logging.api.Logger; @@ -116,15 +119,27 @@ public class ItemsImpl implements Items { @Override public Response list(String itemStatusFilter, String versionStatusFilter, String itemTypeFilter, String permissionFilter, - String onboardingMethodFilter, String user) { + String onboardingMethodFilter, String user, HttpServletRequest hreq) { Predicate<Item> itemPredicate = createItemPredicate(itemStatusFilter, versionStatusFilter, itemTypeFilter, onboardingMethodFilter, permissionFilter, user); GenericCollectionWrapper<ItemDto> results = new GenericCollectionWrapper<>(); MapItemToDto mapper = new MapItemToDto(); - getManagersProvider().getItemManager().list(itemPredicate).stream() - .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) - .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class))); - return Response.ok(results).build(); + Multitenancy keyaccess= new Multitenancy(); + if (keyaccess.multiTenancyCheck()) { + AccessToken.Access realmAccess = keyaccess.getAccessToken(hreq).getRealmAccess(); + Set<String> realmroles = realmAccess.getRoles(); + realmroles.stream().forEach(role -> getManagersProvider().getItemManager().list(itemPredicate).stream() + .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) + .filter(item -> item.getTenant().contains(role)) + .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class)))); + return Response.ok(results).build(); + } + else{ + getManagersProvider().getItemManager().list(itemPredicate).stream() + .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())) + .forEach(item -> results.add(mapper.applyMapping(item, ItemDto.class))); + return Response.ok(results).build(); + } } @Override |