]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1929
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 14 Jun 2010 23:50:35 +0000 (23:50 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Mon, 14 Jun 2010 23:50:35 +0000 (23:50 +0000)
The delete on accountrole sub resource of the account service now requires a POST with parameter _method=delete (/accounts/{accountcsid}/accountroles?_method=delete) and entity body (like POST for create). The delete only deletes the relationships found in the entity body.
test: all service tests

NOTE: all the tests pass with the first run. in the second run dimension service tests fail. this might be because some problem (debugging) introduced by eith the security/client/AuthorizationServiceTest or security/client/MultiTenancyTest which use "dimensions" service for security testing

services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleClient.java
services/account/client/src/main/java/org/collectionspace/services/client/AccountRoleProxy.java
services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java
services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
services/account/service/src/main/java/org/collectionspace/services/account/AccountRoleSubResource.java
services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountRoleDocumentHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/AuthorizationDelegate.java
services/authorization/service/src/main/java/org/collectionspace/services/authorization/spring/SpringPermissionManager.java
services/security/client/src/test/java/org/collectionspace/services/security/client/test/AuthorizationServiceTest.java
services/security/client/src/test/java/org/collectionspace/services/security/client/test/MultiTenancyTest.java

index 7bb2bcc3b78836321606a092c453fdc6146b59ef..43df476be3ab8f070837aea236dcfe9ad50ca482 100644 (file)
@@ -95,7 +95,8 @@ public class AccountRoleClient extends AbstractServiceClientImpl {
     }
 
     /**
-     * @param accRole
+     * @param csid
+     * @param accRole relationships to create
      * @return
      * @see 
      */
@@ -106,11 +107,11 @@ public class AccountRoleClient extends AbstractServiceClientImpl {
 
     /**
      * @param csid
-     * @param arcsid relationship does not have an id, junk is fine
+     * @param accRole relationship to delete
      * @return
      * @see 
      */
-    public ClientResponse<Response> delete(String csid, String arcsid) {
-        return accountRoleProxy.delete(csid, arcsid);
+    public ClientResponse<Response> delete(String csid, AccountRole accRole) {
+        return accountRoleProxy.delete(csid, "delete", accRole);
     }
 }
index d64d9f1a74f3148987a78ac7971ee515b6e79882..7399bf705106226e6e42057cf74970bf71492bde 100644 (file)
 package org.collectionspace.services.client;
 
 import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 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.Response;
 
 
@@ -59,8 +59,9 @@ public interface AccountRoleProxy extends CollectionSpaceProxy {
             @PathParam("arcsid") String arcsid);
 
     //(D)elete
-    @DELETE
-    @Path("/{csid}/accountroles/{arcsid}")
+    @POST
+    @Path("/{csid}/accountroles")
     ClientResponse<Response> delete(@PathParam("csid") String csid,
-            @PathParam("arcsid") String arcsid);
+            @QueryParam("_method") String method,
+            AccountRole accRole);
 }
index fb5ec81146614a2148f5688c1551da5f230fee95..fab84d5bb5e6877a0dee59422f709e6241ee1885 100644 (file)
@@ -170,11 +170,11 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
         setupCreate();
 
         // Submit the request to the service and store the response.
-        AccountValue pv = accValues.get("acc-role-user1");
-        AccountRole accRole = createAccountRoleInstance(pv,
+        AccountValue av = accValues.get("acc-role-user1");
+        AccountRole accRole = createAccountRoleInstance(av,
                 roleValues.values(), true, true);
         AccountRoleClient client = new AccountRoleClient();
-        ClientResponse<Response> res = client.create(pv.getAccountId(), accRole);
+        ClientResponse<Response> res = client.create(av.getAccountId(), accRole);
         try {
             int statusCode = res.getStatus();
 
@@ -433,8 +433,11 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
 
         // Submit the request to the service and store the response.
         AccountRoleClient client = new AccountRoleClient();
+                AccountValue av = accValues.get("acc-role-user1");
+        AccountRole accRole = createAccountRoleInstance(av,
+                roleValues.values(), true, true);
         ClientResponse<Response> res = client.delete(
-                accValues.get("acc-role-user1").getAccountId(), "123");
+                accValues.get("acc-role-user1").getAccountId(), accRole);
         int statusCode = res.getStatus();
         try {
             // Check the status code of the response: does it match
@@ -496,7 +499,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
     /**
      * Creates the account role instance.
      *
-     * @param pv the pv
+     * @param av the av
      * @param rvs the rvs
      * @param usePermId the use perm id
      * @param useRoleId the use role id
@@ -537,22 +540,6 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
             logger.debug("Cleaning up temporary resources created for testing ...");
         }
 
-        AccountRoleClient client = new AccountRoleClient();
-        for (String resourceId : allResourceIdsCreated) {
-            ClientResponse<Response> res = client.delete(resourceId, "123");
-            try {
-                int statusCode = res.getStatus();
-                if (logger.isDebugEnabled()) {
-                    logger.debug("clenaup: delete relationships for accission id="
-                            + resourceId + " status=" + statusCode);
-                }
-                Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
-                        invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-                Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
-            } finally {
-                res.releaseConnection();
-            }
-        }
 
         for (AccountValue pv : accValues.values()) {
             deleteAccount(pv.getAccountId());
index 052f7115abf9df0e04f4b5548667fbdac64eb65c..ee8937cd320a068c19834d8bef09f4c41dbe53d2 100644 (file)
@@ -31,6 +31,7 @@ import javax.ws.rs.DELETE;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
@@ -379,8 +380,14 @@ public class AccountResource
 
     @POST
     @Path("{csid}/accountroles")
-    public Response createAccountRole(@PathParam("csid") String accCsid,
+    public Response createAccountRole(@QueryParam("_method") String method,
+            @PathParam("csid") String accCsid,
             AccountRole input) {
+        if (method != null) {
+            if ("delete".equalsIgnoreCase(method)) {
+                return deleteAccountRole(accCsid, input);
+            }
+        }
         if (logger.isDebugEnabled()) {
             logger.debug("createAccountRole with accCsid=" + accCsid);
         }
@@ -477,11 +484,9 @@ public class AccountResource
         return result;
     }
 
-    @DELETE
-    @Path("{csid}/accountroles/{accrolecsid}")
     public Response deleteAccountRole(
             @PathParam("csid") String accCsid,
-            @PathParam("accrolecsid") String accrolecsid) {
+            AccountRole input) {
         if (logger.isDebugEnabled()) {
             logger.debug("deleteAccountRole with accCsid=" + accCsid);
         }
@@ -497,7 +502,7 @@ public class AccountResource
             AccountRoleSubResource subResource =
                     new AccountRoleSubResource(AccountRoleSubResource.ACCOUNT_ACCOUNTROLE_SERVICE);
             //delete all relationships for an account
-            subResource.deleteAccountRole(accCsid, SubjectType.ROLE);
+            subResource.deleteAccountRole(accCsid, SubjectType.ROLE, input);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
             Response response = Response.status(
index e10c18ea0755a7798397d0b6b43d53c7d6222dab..e605ecf502b7ca235216098f5d2bf3ffe50d6b98 100644 (file)
@@ -48,11 +48,10 @@ public class AccountRoleSubResource
 
     final public static String ACCOUNT_ACCOUNTROLE_SERVICE = "accounts/accountroles";
     final public static String ROLE_ACCOUNTROLE_SERVICE = "roles/accountroles";
-    
     //this service is never exposed as standalone RESTful service...just use unique
     //service name to identify binding
     /** The service name. */
-    private String serviceName =  ACCOUNT_ACCOUNTROLE_SERVICE;
+    private String serviceName = ACCOUNT_ACCOUNTROLE_SERVICE;
     /** The logger. */
     final Logger logger = LoggerFactory.getLogger(AccountRoleSubResource.class);
     /** The storage client. */
@@ -65,11 +64,10 @@ public class AccountRoleSubResource
     AccountRoleSubResource(String serviceName) {
         this.serviceName = serviceName;
     }
-    
+
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
      */
-
     @Override
     protected String getVersionString() {
         /** The last change revision. */
@@ -174,9 +172,9 @@ public class AccountRoleSubResource
     }
 
     /**
-     * deleteAccountRole deletes account-role relationships using given
+     * deleteAccountRole deletes all account-role relationships using given
      * csid of object (account/role) and subject (role/account)
-     * @param csid
+     * @param csid of the object
      * @param subject
      * @return
      * @throws Exception
@@ -190,4 +188,21 @@ public class AccountRoleSubResource
         ServiceContext<AccountRole, AccountRole> ctx = createServiceContext((AccountRole) null, subject);
         getStorageClient(ctx).delete(ctx, csid);
     }
+
+    /**
+     * deleteAccountRole deletes given account-role relationships using given
+     * csid of object (account/role) and subject (role/account)
+     * @param csid of the object
+     * @param subject
+     * @param input with account role relationships to delete
+     * @return
+     * @throws Exception
+     */
+    public void deleteAccountRole(String csid, SubjectType subject, AccountRole input)
+            throws Exception {
+
+        ServiceContext<AccountRole, AccountRole> ctx = createServiceContext(input, subject);
+        DocumentHandler handler = createDocumentHandler(ctx);
+        getStorageClient(ctx).delete(ctx, csid, handler);
+    }
 }
index 7d2c0ceb141522d168dd16ad17867b7911d50617..34edb72b7f86bafbdd857ba7b952700e68221583 100644 (file)
@@ -78,6 +78,11 @@ public class AccountRoleDocumentHandler
         throw new UnsupportedOperationException("operation not relevant for AccountRoleDocumentHandler");
     }
 
+    @Override
+    public void handleDelete(DocumentWrapper<List<AccountRoleRel>> wrapDoc) throws Exception {
+        fillCommonPart(getCommonPart(), wrapDoc);
+    }
+
     @Override
     public AccountRole extractCommonPart(
             DocumentWrapper<List<AccountRoleRel>> wrapDoc)
index 41636b45dd0660005f9f76914d709a4fd1b38464..02594b98adf29de968f2c049368cbd90755da477 100644 (file)
@@ -353,9 +353,11 @@ public class PermissionResource
             PermissionRoleSubResource subResource =
                     new PermissionRoleSubResource(PermissionRoleSubResource.PERMISSION_PERMROLE_SERVICE);
             subResource.deletePermissionRole(csid, SubjectType.ROLE);
-            //delete permissions in the authz provider too
+            //NOTE for delete permissions in the authz provider
             //at the PermissionRoleSubResource/DocHandler level, there is no visibility
-            //if permission is deleted, so do it here
+            //if permission is deleted, so do it here, however,
+            //this is a very dangerous operation as it deletes the Spring ACL instead of ACE(s)
+            //the ACL might be needed for other ACEs roles...
             AuthorizationDelegate.deletePermissions(csid);
 
             ServiceContext<Permission, Permission> ctx = createServiceContext((Permission) null, Permission.class);
index 3d7d1ad3abbc47ad602f9e5d9a9b6784520ef270..119618cd60c8ebb636eb3919d0acaf46b7f15891 100644 (file)
@@ -158,6 +158,10 @@ public class AuthorizationDelegate {
      * @param permCsid
      * @throws Exception
      */
+    //Non-javadoc comment : this is a very dangerous operation as it deletes
+    //the Spring ACL instead of ACE(s) that is associated with each role
+    //the ACL might be needed for other ACEs (including those for ROLE_ADMINISTRATOR,
+    //ROLE_TENANT_ADMINISTRATOR, etc.)...
     static public void deletePermissions(String permCsid) throws Exception {
         Permission p = getPermission(permCsid);
         if (p == null) {
index 0eeaa5251ec1364188a0db5fcb578c501972919b..6924e472ebb0533b876e4df30791eb4bed239c01 100644 (file)
@@ -56,6 +56,15 @@ public class SpringPermissionManager implements CSpacePermissionManager {
         this.provider = provider;
     }
 
+    /**
+     * addPermissions adds permissions according to the given grant for given
+     * resource#action for each given principal
+     * @param res
+     * @param action
+     * @param principals
+     * @param grant
+     * @throws PermissionException
+     */
     @Override
     public void addPermissions(CSpaceResource res, CSpaceAction action, String[] principals, boolean grant)
             throws PermissionException {
@@ -120,6 +129,14 @@ public class SpringPermissionManager implements CSpacePermissionManager {
         }
     }
 
+    /**
+     * deletePermissions removes permisions for given resource#action for each given principal
+     * @param res
+     * @param action
+     * @param principals
+     * @throws PermissionNotFoundException
+     * @throws PermissionException
+     */
     @Override
     public void deletePermissions(CSpaceResource res, CSpaceAction action, String[] principals)
             throws PermissionNotFoundException, PermissionException {
@@ -178,6 +195,15 @@ public class SpringPermissionManager implements CSpacePermissionManager {
         }
     }
 
+    /**
+     * deletePermissions
+     * @param res
+     * @param action
+     * @throws PermissionNotFoundException
+     * @throws PermissionException
+     */
+    //non-javadoc NOTE: this is a very destructive operation. it would remove all permissions
+    //to access given resource#action for ANY role including administrators
     @Override
     public void deletePermissions(CSpaceResource res, CSpaceAction action)
             throws PermissionNotFoundException, PermissionException {
@@ -222,6 +248,14 @@ public class SpringPermissionManager implements CSpacePermissionManager {
 
     }
 
+    /**
+     * deletePermissions
+     * @param res
+     * @throws PermissionNotFoundException
+     * @throws PermissionException
+     */
+    //non-javadoc NOTE: this is a very very destructive operation. it would remove all permissions
+    //to access given resource for ANY action for ANY role including administrators
     @Override
     public void deletePermissions(CSpaceResource res)
             throws PermissionNotFoundException, PermissionException {
@@ -258,6 +292,15 @@ public class SpringPermissionManager implements CSpacePermissionManager {
         }
     }
 
+    /**
+     * addPermission adds permission grant for given object identity for given permission
+     * for given sid
+     * @param oid
+     * @param permission
+     * @param sid
+     * @param grant
+     * @throws PermissionException
+     */
     private void addPermission(ObjectIdentity oid, Permission permission,
             Sid sid, boolean grant) throws PermissionException {
         MutableAcl acl;
@@ -285,6 +328,13 @@ public class SpringPermissionManager implements CSpacePermissionManager {
         }
     }
 
+    /**
+     * deletePermissions deletes given permission on given object id for given sid
+     * @param oid
+     * @param permission
+     * @param sid
+     */
+    //non-javadoc NOTE: if sid is null it would remove ACEs for all sid(s)
     private void deletePermissions(ObjectIdentity oid, Permission permission, Sid sid) /** throws AclDataAccessException */
     {
         int i = 0;
index 7530cc8a9f47a3d09792cf3849ca018ca0b80291..d683b8d149caa92c789782907cecce2282d0f33d 100644 (file)
@@ -521,13 +521,55 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl {
 
         deletePermissionRoles();
         deleteAccountRoles();
-        //FIXME delete on permission role deletes all roles associated with the permission
-        //this would delete association with ROLE_ADMINISTRATION too
+        //FIXME delete on permission deletes all associations with roles
+        //this would delete association with ROLE_ADMINISTRATOR too
         //deletePermissions();
         deleteRoles();
         deleteAccounts();
     }
 
+    private void deletePermissionRoles() {
+
+        List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
+        bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
+        deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
+
+        List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
+        elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
+        deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues);
+
+    }
+
+    private void deleteAccountRoles() {
+        List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
+        bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
+        deleteAccountRole(accValues.get("bigbird2010"), bigbirdRoleValues);
+
+        List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
+        elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
+        deleteAccountRole(accValues.get("elmo2010"), elmoRoleValues);
+    }
+
+    private void deletePermissions() {
+        //delete entities
+        for (PermissionValue pv : permValues.values()) {
+            deletePermission(pv.getPermissionId());
+        }
+    }
+
+    private void deleteRoles() {
+        for (RoleValue rv : roleValues.values()) {
+            deleteRole(rv.getRoleId());
+        }
+    }
+
+    private void deleteAccounts() {
+
+        for (AccountValue av1 : accValues.values()) {
+            deleteAccount(av1.getAccountId());
+        }
+    }
+
     private String createPermission(String resName, EffectType effect) {
         List<PermissionAction> actions = PermissionFactory.createDefaultActions();
         return createPermission(resName, actions, effect);
@@ -657,14 +699,17 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl {
         return extractId(res);
     }
 
-    private void deleteAccountRole(String screenName) {
+    private void deleteAccountRole(AccountValue av,
+            Collection<RoleValue> rvs) {
         // Perform setup.
         setupDelete();
 
         // Submit the request to the service and store the response.
         AccountRoleClient client = new AccountRoleClient();
+        AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
+                av, rvs, true, true);
         ClientResponse<Response> res = client.delete(
-                accValues.get(screenName).getAccountId(), "123");
+                av.getAccountId(), accRole);
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match
@@ -724,46 +769,4 @@ public class AuthorizationServiceTest extends AbstractServiceTestImpl {
         Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
         res.releaseConnection();
     }
-
-    private void deletePermissionRoles() {
-
-        List<RoleValue> bigbirdRoleValues = new ArrayList<RoleValue>();
-        bigbirdRoleValues.add(roleValues.get("ROLE_TEST_CM"));
-        deletePermissionRole(permValues.get(bigbirdPermId), bigbirdRoleValues);
-
-        List<RoleValue> elmoRoleValues = new ArrayList<RoleValue>();
-        elmoRoleValues.add(roleValues.get("ROLE_TEST_INTERN"));
-        deletePermissionRole(permValues.get(elmoPermId), elmoRoleValues);
-
-    }
-
-    private void deleteAccountRoles() {
-        for (AccountValue av : accValues.values()) {
-            deleteAccountRole(av.getUserId());
-        }
-    }
-
-    private void deletePermissions() {
-        //delete entities
-        for (PermissionValue pv : permValues.values()) {
-            deletePermission(pv.getPermissionId());
-        }
-    }
-
-    private void deleteRoles() {
-        for (RoleValue rv : roleValues.values()) {
-            deleteRole(rv.getRoleId());
-        }
-    }
-
-    private void deleteAccounts() {
-
-        for (AccountValue av1 : accValues.values()) {
-            deleteAccount(av1.getAccountId());
-        }
-    }
-
-    private String getTenantId(AccountClient client) {
-        return client.getProperty(AccountClient.TENANT_PROPERTY);
-    }
 }
index 966bed548b57bd8e87e973b45232efe46b41c9ec..349a93d292c3680348eef3b2f91415d4bc0a73e4 100644 (file)
@@ -632,8 +632,7 @@ public class MultiTenancyTest extends AbstractServiceTestImpl {
 
         deletePermissionRoles();
         deleteAccountRoles();
-        //FIXME delete on permission role deletes all roles associated with the permission
-        //this would delete association with ROLE_ADMINISTRATION too
+        //deletePermissions would delete association with ROLE_XXX_ADMINISTRTOR too
         //deletePermissions();
         deleteRoles();
         deleteAccounts();
@@ -641,8 +640,6 @@ public class MultiTenancyTest extends AbstractServiceTestImpl {
 
     private void deletePermissionRoles() {
 
-        //first delete relationships between the entities
-
         for (String tenantId : tenantPermissions.keySet()) {
             List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
             tenantRoleValues.add(tenantRoles.get(tenantId));
@@ -653,8 +650,10 @@ public class MultiTenancyTest extends AbstractServiceTestImpl {
 
     private void deleteAccountRoles() {
         for (String tenantId : tenantAccounts.keySet()) {
+            List<RoleValue> tenantRoleValues = new ArrayList<RoleValue>();
+            tenantRoleValues.add(tenantRoles.get(tenantId));
             AccountValue av = tenantAccounts.get(tenantId);
-            deleteAccountRole(tenantId, av.getAccountId());
+            deleteAccountRole(tenantId, av, tenantRoleValues);
         }
     }
 
@@ -819,7 +818,8 @@ public class MultiTenancyTest extends AbstractServiceTestImpl {
         return extractId(res);
     }
 
-    private void deleteAccountRole(String tenantId, String accountId) {
+    private void deleteAccountRole(String tenantId, AccountValue av,
+            List<RoleValue> rvs) {
         // Perform setup.
         setupDelete();
 
@@ -827,8 +827,10 @@ public class MultiTenancyTest extends AbstractServiceTestImpl {
         AccountRoleClient client = new AccountRoleClient();
         UserInfo ui = tenantAdminUsers.get(tenantId);
         client.setAuth(true, ui.userName, true, ui.password, true);
+        AccountRole accRole = AccountRoleFactory.createAccountRoleInstance(
+                av, rvs, true, true);
         ClientResponse<Response> res = client.delete(
-                accountId, "123");
+                av.getAccountId(), accRole);
         int statusCode = res.getStatus();
 
         // Check the status code of the response: does it match