From 232ca132b23625214a33a40c3fffb2fd2f83c538 Mon Sep 17 00:00:00 2001 From: ChanikaRuchini Date: Wed, 24 Jan 2024 10:19:26 +0530 Subject: [PATCH] Include support for attributes and excluded attributes in bulk GET through path parameters --- .../core/protocol/BulkRequestProcessor.java | 59 +++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/BulkRequestProcessor.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/BulkRequestProcessor.java index 22ca389a5..a3540b4ce 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/BulkRequestProcessor.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/BulkRequestProcessor.java @@ -37,9 +37,11 @@ import org.wso2.charon3.core.protocol.endpoints.UserResourceManager; import org.wso2.charon3.core.schema.SCIMConstants; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @@ -292,12 +294,20 @@ private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkReques } case SCIMConstants.OperationalConstants.GET: { - String resourceId = extractIDFromPath(bulkRequestContent.getPath()); - String attributes = getAttributesFromData(bulkRequestContent.getData()); - String excludeAttributes = getExcludedAttributesFromData(bulkRequestContent.getData()); - + String resourceId = extractIDFromGetRequestPath(bulkRequestContent.getPath()); + Map queryParams = parseQueryParameters(bulkRequestContent.getPath()); + String attributes = queryParams.get(SCIMConstants.CommonSchemaConstants.ATTRIBUTES); + String excludeAttributes = queryParams.get(SCIMConstants.CommonSchemaConstants.EXCLUDE_ATTRIBUTES); + if (StringUtils.isNotBlank(bulkRequestContent.getData())) { + if (StringUtils.isBlank(attributes)) { + attributes = getAttributesFromData(bulkRequestContent.getData()); + } + if (StringUtils.isBlank(excludeAttributes)) { + excludeAttributes = getExcludedAttributesFromData(bulkRequestContent.getData()); + } + } if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_V2_ENDPOINT)) { - resourceId = extractIDFromV2Path(bulkRequestContent.getPath()); + resourceId = extractIDFromV2GetRequestPath(bulkRequestContent.getPath()); response = resourceManager.getRole(resourceId, roleV2Manager, attributes, excludeAttributes); } else if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { response = resourceManager.getRole(resourceId, roleManager, attributes, excludeAttributes); @@ -355,6 +365,32 @@ private String extractIDFromPath(String path) throws BadRequestException { } } + private String extractIDFromGetRequestPath(String path) throws BadRequestException { + + String[] parts = path.split("[?]"); + if (parts.length == 1) { + return extractIDFromPath(path); + } + if (parts[0] != null) { + return extractIDFromPath(parts[0]); + } + throw new BadRequestException + ("No resource Id is provided in path", ResponseCodeConstants.INVALID_VALUE); + } + + private static Map parseQueryParameters(String path) { + + String[] parts = path.split("[?]"); + if (parts.length < 2) { + return new HashMap<>(); + } + return Arrays.stream(parts[1].split("&")) + .map(param -> param.split("=")) + .collect(Collectors.toMap( + pair -> pair[0], + pair -> pair.length > 1 ? pair[1] : "")); + } + private String extractIDFromV2Path(String path) throws BadRequestException { String [] parts = path.split("[/]"); @@ -365,6 +401,19 @@ private String extractIDFromV2Path(String path) throws BadRequestException { ("No resource Id is provided in path", ResponseCodeConstants.INVALID_VALUE); } + private String extractIDFromV2GetRequestPath(String path) throws BadRequestException { + + String[] parts = path.split("[?]"); + if (parts.length == 1) { + return extractIDFromV2Path(path); + } + if (parts[0] != null) { + return extractIDFromV2Path(parts[0]); + } + throw new BadRequestException + ("No resource Id is provided in path", ResponseCodeConstants.INVALID_VALUE); + } + private BulkResponseContent createBulkResponseContent(SCIMResponse response, String method, BulkRequestContent requestContent) {