From: remillet Date: Thu, 7 Dec 2017 22:42:26 +0000 (-0800) Subject: DRYD-186: Added support for PUT requests on Roles that contain associated permissions... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5308c2ae87424b6248c1679e05e19c274d8cdb71;p=tmp%2Fjakarta-migration.git DRYD-186: Added support for PUT requests on Roles that contain associated permissions. A role's existing permissions list will be replaced with the ones sent in the PUT request. --- diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/security.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/security.xml index 5946eca88..8c9316c25 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/security.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/security.xml @@ -77,6 +77,12 @@ /cspace-services/authorization/roles security/3-role-test-cm.xml + + PUT + /cspace-services/authorization/roles + security/3a-update-role-test-cm.xml + roleTestCM + POST /cspace-services/authorization/roles diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/security/3a-update-role-test-cm.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/security/3a-update-role-test-cm.xml new file mode 100644 index 000000000..2178ce6d9 --- /dev/null +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/security/3a-update-role-test-cm.xml @@ -0,0 +1,15 @@ + + + ROLE_TEST_CM + role for ROLE_TEST_CM + + 1-vocabularies-RL + vocabularies + RL + + + 1-groups-RL + groups + RL + + diff --git a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java index 7694e7b7a..7ab0946db 100644 --- a/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java +++ b/services/authorization-mgt/client/src/main/java/org/collectionspace/services/client/RoleClient.java @@ -44,7 +44,11 @@ public class RoleClient extends AbstractServiceClientImpl wrapDoc) throws Exception { - Role roleFound = wrapDoc.getWrappedObject(); - Role roleReceived = getCommonPart(); - // If marked as metadata immutable, do not do update - if(!RoleClient.IMMUTABLE.equals(roleFound.getMetadataProtection())) { - roleReceived.setRoleName(RoleClient.getBackendRoleName(roleReceived.getRoleName(), - roleFound.getTenantId())); - merge(roleReceived, roleFound); - } - } + public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { + Role roleFound = wrapDoc.getWrappedObject(); + Role roleReceived = getCommonPart(); + // If marked as metadata immutable, do not do update + if (!RoleClient.IMMUTABLE.equals(roleFound.getMetadataProtection())) { + roleReceived + .setRoleName(RoleClient.getBackendRoleName(roleReceived.getRoleName(), roleFound.getTenantId())); + merge(roleReceived, roleFound); + } + // + // Update perms is supplied. + // + List permValueList = roleReceived.getPermission(); + if (permValueList != null) { + PermissionRoleSubResource subResource = + new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE); + // + // First, delete the existing permroles + // + subResource.deletePermissionRole(roleFound.getCsid(), SubjectType.PERMISSION); + // + // Next, create the new permroles + // + RoleValue roleValue = RoleFactory.createRoleValueInstance(roleFound); + PermissionRole permRole = PermissionRoleFactory.createPermissionRoleInstance(SubjectType.PERMISSION, roleValue, + permValueList, true, true); + subResource.createPermissionRole(permRole, SubjectType.PERMISSION); + // + // Finally, set the updated perm list in the result + // + PermissionRole newPermRole = subResource.getPermissionRole(roleFound.getCsid(), SubjectType.PERMISSION); + roleFound.setPermission(newPermRole.getPermission()); + } + } /** * Merge fields manually from 'from' to the 'to' role @@ -169,7 +193,18 @@ public class RoleDocumentHandler public Role extractCommonPart( DocumentWrapper wrapDoc) throws Exception { - return wrapDoc.getWrappedObject(); + Role role = wrapDoc.getWrappedObject(); + + String includePermsQueryParamValue = (String) getServiceContext().getQueryParams().getFirst(RoleClient.INCLUDE_PERMS_QP); + boolean includePerms = Tools.isTrue(includePermsQueryParamValue); + if (includePerms) { + PermissionRoleSubResource permRoleResource = + new PermissionRoleSubResource(PermissionRoleSubResource.ROLE_PERMROLE_SERVICE); + PermissionRole permRole = permRoleResource.getPermissionRole(role.getCsid(), SubjectType.PERMISSION); + role.setPermission(permRole.getPermission()); + } + + return role; } @Override @@ -232,7 +267,7 @@ public class RoleDocumentHandler */ private void sanitize(Role role) { if (!SecurityUtils.isCSpaceAdmin()) { - role.setTenantId(null); // REM - See no reason for hiding the tenant ID? + // role.setTenantId(null); // REM - There's no reason for hiding the tenant ID is there? } }