diff options
author | Kartik Hegde <kh00735564@techmahindra.com> | 2022-11-12 14:29:11 +0530 |
---|---|---|
committer | Kartik Hegde <kh00735564@techmahindra.com> | 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 | |
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')
3 files changed, 24 insertions, 6 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java index 066acb9370..a2c0e39e8f 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/Items.java @@ -26,6 +26,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tags; +import javax.servlet.http.HttpServletRequest; import javax.validation.constraints.NotNull; import javax.ws.rs.Consumes; import javax.ws.rs.GET; @@ -35,6 +36,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.openecomp.sdc.versioning.types.Item; @@ -61,7 +63,7 @@ public interface Items { @QueryParam("permission") String permissionFilter, @Parameter(description = "Filter by onboarding method", schema = @Schema(type = "string", allowableValues = {"NetworkPackage", "manual"})) @QueryParam("onboardingMethod") String onboardingMethodFilter, - @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user); + @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM) String user, @Context HttpServletRequest hreq); @GET @Path("/{itemId}") diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java index 3bd8a7fe9f..0eb74a03b6 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java @@ -34,5 +34,6 @@ public class MapItemToDto extends MappingBase<Item, ItemDto> { target.setOwner(source.getOwner()); target.setStatus(source.getStatus().name()); target.setProperties(source.getProperties()); + target.setTenant(source.getTenant()); } } 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 |