diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java index 579e7837e..9d2fb5270 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/encoder/JSONDecoder.java @@ -882,6 +882,7 @@ public BulkRequestData decodeBulkData(String bulkResourceString) throws BadReque List usersEndpointOperationList = new ArrayList<>(); List groupsEndpointOperationList = new ArrayList<>(); List rolesEndpointOperationList = new ArrayList<>(); + List rolesV2EndpointOperationList = new ArrayList<>(); int failOnErrorsAttribute; List schemas = new ArrayList<>(); Set encounteredBulkIds = new HashSet<>(); @@ -930,7 +931,7 @@ public BulkRequestData decodeBulkData(String bulkResourceString) throws BadReque } encounteredBulkIds.add(bulkId); setRequestData(requestType, requestMethod, requestVersion, member, usersEndpointOperationList, - groupsEndpointOperationList, rolesEndpointOperationList); + groupsEndpointOperationList, rolesEndpointOperationList, rolesV2EndpointOperationList); } else { String error = "JSON string could not be decoded properly.Required " + "attribute BULK_ID is missing in the request"; @@ -939,7 +940,7 @@ public BulkRequestData decodeBulkData(String bulkResourceString) throws BadReque } } else { setRequestData(requestType, requestMethod, requestVersion, member, usersEndpointOperationList, - groupsEndpointOperationList, rolesEndpointOperationList); + groupsEndpointOperationList, rolesEndpointOperationList, rolesV2EndpointOperationList); } } //extract [failOnErrors] attribute from Json string @@ -949,6 +950,7 @@ public BulkRequestData decodeBulkData(String bulkResourceString) throws BadReque bulkRequestDataObject.setUserOperationRequests(usersEndpointOperationList); bulkRequestDataObject.setGroupOperationRequests(groupsEndpointOperationList); bulkRequestDataObject.setRoleOperationRequests(rolesEndpointOperationList); + bulkRequestDataObject.setRoleV2OperationRequests(rolesV2EndpointOperationList); } catch (JSONException e) { if (logger.isDebugEnabled()) { @@ -961,8 +963,10 @@ public BulkRequestData decodeBulkData(String bulkResourceString) throws BadReque } private void setRequestData(String requestType, String requestMethod, String requestVersion, JSONObject member, - List usersEndpointOperationList, List groupsEndpointOperationList, - List rolesEndpointOperationList) { + List usersEndpointOperationList, + List groupsEndpointOperationList, + List rolesEndpointOperationList, + List rolesV2EndpointOperationList) { // Create user request list. if (requestType.contains(SCIMConstants.USER_ENDPOINT)) { @@ -982,7 +986,11 @@ private void setRequestData(String requestType, String requestMethod, String req } // Create role request list. - if (requestType.contains(SCIMConstants.ROLE_ENDPOINT)) { + if (requestType.contains(SCIMConstants.ROLE_V2_ENDPOINT)) { + BulkRequestContent newRequestData = + getBulkRequestContent(member, requestMethod, requestType, requestVersion); + rolesV2EndpointOperationList.add(newRequestData); + } else if (requestType.contains(SCIMConstants.ROLE_ENDPOINT)) { BulkRequestContent newRequestData = getBulkRequestContent(member, requestMethod, requestType, requestVersion); rolesEndpointOperationList.add(newRequestData); diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/objects/bulk/BulkRequestData.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/objects/bulk/BulkRequestData.java index 6dc8ef857..20eb88c34 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/objects/bulk/BulkRequestData.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/objects/bulk/BulkRequestData.java @@ -30,12 +30,14 @@ public class BulkRequestData { private List userOperationRequests; private List groupOperationRequests; private List roleOperationRequests; + private List roleV2OperationRequests; public BulkRequestData() { userOperationRequests = new ArrayList<>(); groupOperationRequests = new ArrayList<>(); roleOperationRequests = new ArrayList<>(); + roleV2OperationRequests = new ArrayList<>(); schemas = new ArrayList<>(); } @@ -73,6 +75,16 @@ public void setRoleOperationRequests(List roleOperationReque this.roleOperationRequests = roleOperationRequests; } + public List getRoleV2OperationRequests() { + + return roleV2OperationRequests; + } + + public void setRoleV2OperationRequests(List roleV2OperationRequests) { + + this.roleV2OperationRequests = roleV2OperationRequests; + } + public List getSchemas() { return schemas; } 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 2875527ef..b479bf2b7 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 @@ -24,6 +24,7 @@ import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.extensions.RoleManager; +import org.wso2.charon3.core.extensions.RoleV2Manager; import org.wso2.charon3.core.extensions.UserManager; import org.wso2.charon3.core.objects.bulk.BulkRequestContent; import org.wso2.charon3.core.objects.bulk.BulkRequestData; @@ -32,6 +33,7 @@ import org.wso2.charon3.core.protocol.endpoints.GroupResourceManager; import org.wso2.charon3.core.protocol.endpoints.ResourceManager; import org.wso2.charon3.core.protocol.endpoints.RoleResourceManager; +import org.wso2.charon3.core.protocol.endpoints.RoleResourceV2Manager; import org.wso2.charon3.core.protocol.endpoints.UserResourceManager; import org.wso2.charon3.core.schema.SCIMConstants; @@ -46,10 +48,12 @@ public class BulkRequestProcessor { private UserResourceManager userResourceManager; private GroupResourceManager groupResourceManager; private RoleResourceManager roleResourceManager; + private RoleResourceV2Manager roleResourceV2Manager; private int failOnError; private int errors; private UserManager userManager; private RoleManager roleManager; + private RoleV2Manager roleV2Manager; public UserResourceManager getUserResourceManager() { return userResourceManager; @@ -77,6 +81,16 @@ public void setRoleResourceManager(RoleResourceManager roleResourceManager) { this.roleResourceManager = roleResourceManager; } + public RoleResourceV2Manager getRoleResourceV2Manager() { + + return roleResourceV2Manager; + } + + public void setRoleResourceV2Manager(RoleResourceV2Manager roleResourceV2Manager) { + + this.roleResourceV2Manager = roleResourceV2Manager; + } + public int getFailOnError() { return failOnError; } @@ -111,11 +125,22 @@ public void setRoleManager(RoleManager roleManager) { this.roleManager = roleManager; } + public RoleV2Manager getRoleV2Manager() { + + return roleV2Manager; + } + + public void setRoleV2Manager(RoleV2Manager roleV2Manager) { + + this.roleV2Manager = roleV2Manager; + } + public BulkRequestProcessor() { userResourceManager = new UserResourceManager(); groupResourceManager = new GroupResourceManager(); roleResourceManager = new RoleResourceManager(); + roleResourceV2Manager = new RoleResourceV2Manager(); failOnError = 0; errors = 0; userManager = null; @@ -150,6 +175,7 @@ public BulkResponseData processBulkRequests(BulkRequestData bulkRequestData) thr } } + // Handle v1 role operations. for (BulkRequestContent bulkRequestContent : bulkRequestData.getRoleOperationRequests()) { if (failOnError == 0) { bulkResponseData.addRoleOperation(getBulkResponseContent(bulkRequestContent, userIdMappings, @@ -161,6 +187,18 @@ public BulkResponseData processBulkRequests(BulkRequestData bulkRequestData) thr } } } + // Handle v2 role operations. + for (BulkRequestContent bulkRequestContent : bulkRequestData.getRoleV2OperationRequests()) { + if (failOnError == 0) { + bulkResponseData.addRoleOperation(getBulkResponseContent(bulkRequestContent, userIdMappings, + roleResourceV2Manager)); + } else { + if (errors < failOnError) { + bulkResponseData.addRoleOperation(getBulkResponseContent(bulkRequestContent, + userIdMappings, roleResourceV2Manager)); + } + } + } bulkResponseData.setSchema(SCIMConstants.BULK_RESPONSE_URI); return bulkResponseData; } @@ -182,7 +220,9 @@ private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkReques switch (bulkRequestContent.getMethod()) { case SCIMConstants.OperationalConstants.POST: - if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { + if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_V2_ENDPOINT)) { + response = resourceManager.createRole(bulkRequestContent.getData(), roleV2Manager); + } else if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { response = resourceManager.createRole(bulkRequestContent.getData(), roleManager); } else { response = resourceManager.create(bulkRequestContent.getData(), userManager, @@ -196,7 +236,11 @@ private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkReques case SCIMConstants.OperationalConstants.PUT: { String resourceId = extractIDFromPath(bulkRequestContent.getPath()); - if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { + if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_V2_ENDPOINT)) { + resourceId = extractIDFromV2Path(bulkRequestContent.getPath()); + response = resourceManager.updateWithPUTRole(resourceId, bulkRequestContent.getData(), + roleV2Manager); + } else if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { response = resourceManager.updateWithPUTRole(resourceId, bulkRequestContent.getData(), roleManager); } else { @@ -212,7 +256,11 @@ private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkReques case SCIMConstants.OperationalConstants.PATCH: { String resourceId = extractIDFromPath(bulkRequestContent.getPath()); - if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { + if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_V2_ENDPOINT)) { + resourceId = extractIDFromV2Path(bulkRequestContent.getPath()); + response = resourceManager.updateWithPATCHRole(resourceId, bulkRequestContent.getData(), + roleV2Manager); + } else if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { response = resourceManager.updateWithPATCHRole(resourceId, bulkRequestContent.getData(), roleManager); } else { @@ -228,7 +276,10 @@ private BulkResponseContent getBulkResponseContent(BulkRequestContent bulkReques case SCIMConstants.OperationalConstants.DELETE: { String resourceId = extractIDFromPath(bulkRequestContent.getPath()); - if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { + if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_V2_ENDPOINT)) { + resourceId = extractIDFromV2Path(bulkRequestContent.getPath()); + response = resourceManager.deleteRole(resourceId, roleV2Manager); + } else if (bulkRequestContent.getPath().contains(SCIMConstants.ROLE_ENDPOINT)) { response = resourceManager.deleteRole(resourceId, roleManager); } else { response = resourceManager.delete(resourceId, userManager); @@ -254,6 +305,16 @@ private String extractIDFromPath(String path) throws BadRequestException { } } + private String extractIDFromV2Path(String path) throws BadRequestException { + String [] parts = path.split("[/]"); + if (parts[3] != null) { + return parts[3]; + } else { + throw new BadRequestException + ("No resource Id is provided in path", ResponseCodeConstants.INVALID_VALUE); + } + } + private BulkResponseContent createBulkResponseContent(SCIMResponse response, String method, BulkRequestContent requestContent) { diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/BulkResourceManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/BulkResourceManager.java index 52cb9fd8b..df6852515 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/BulkResourceManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/BulkResourceManager.java @@ -23,6 +23,7 @@ import org.wso2.charon3.core.exceptions.CharonException; import org.wso2.charon3.core.exceptions.InternalErrorException; import org.wso2.charon3.core.extensions.RoleManager; +import org.wso2.charon3.core.extensions.RoleV2Manager; import org.wso2.charon3.core.extensions.UserManager; import org.wso2.charon3.core.objects.bulk.BulkRequestData; import org.wso2.charon3.core.objects.bulk.BulkResponseData; @@ -50,6 +51,14 @@ public BulkResourceManager() { bulkRequestProcessor = new BulkRequestProcessor(); } + public SCIMResponse processBulkData(String data, UserManager userManager, RoleManager roleManager, + RoleV2Manager roleV2Manager) { + + bulkRequestProcessor.setRoleManager(roleManager); + bulkRequestProcessor.setRoleV2Manager(roleV2Manager); + return processBulkData(data, userManager); + } + public SCIMResponse processBulkData(String data, UserManager userManager, RoleManager roleManager) { bulkRequestProcessor.setRoleManager(roleManager);