Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include support for attributes and excluded attributes in bulk GET through path parameters #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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<String, String> 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);
Expand Down Expand Up @@ -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<String, String> parseQueryParameters(String path) {

String[] parts = path.split("[?]");
if (parts.length < 2) {
return new HashMap<>();
}
return Arrays.stream(parts[1].split("&"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the behavior if there are duplicate query params?

.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("[/]");
Expand All @@ -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) {

Expand Down
Loading