RM-634: A records admin can access the users and groups within a RM role (or all the roles) via a web script API.

* add additional user/group management methods to FilePlanRoleService java API
  * add file plan retrieval methods to FilePlanService .. including retrieving file plan node reference from RM site id
  * deprecate file plan retrieval methods on RecordsManagementService
  * add FilePlanService unit tests
  * refactor role web service API implementations to allow the file plan (or rm site) to be specified
  * GET roles can optionally include information about the assigned users and groups



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@48438 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2013-03-21 05:28:57 +00:00
parent 2a45ef99e8
commit 5943d7ad46
27 changed files with 986 additions and 273 deletions

View File

@@ -26,6 +26,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.service.DataSetServiceImp
import org.alfresco.module.org_alfresco_module_rm.test.service.DispositionServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.ExtendedSecurityServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.FilePlanRoleServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.FilePlanServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.FreezeServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.ModelSecurityServiceImplTest;
import org.alfresco.module.org_alfresco_module_rm.test.service.RecordServiceImplTest;
@@ -67,6 +68,7 @@ public class ServicesTestSuite extends TestSuite
suite.addTestSuite(RecordServiceImplTest.class);
suite.addTestSuite(CapabilityServiceImplTest.class);
suite.addTestSuite(FilePlanRoleServiceImplTest.class);
suite.addTestSuite(FilePlanServiceImplTest.class);
return suite;
}
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
import org.alfresco.module.org_alfresco_module_rm.role.Role;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.security.AuthorityType;
@@ -158,7 +159,11 @@ public class FilePlanRoleServiceImplTest extends BaseRMTestCase
});
}
public void testAssignRoleToAuthority() throws Exception
/**
* {@link FilePlanRoleService#assignRoleToAuthority(org.alfresco.service.cmr.repository.NodeRef, String, String)}
* {@link FilePlanRoleService#getAuthorities(org.alfresco.service.cmr.repository.NodeRef, String)
*/
public void testAuthorityAssignment() throws Exception
{
doTestInTransaction(new Test<Void>()
{
@@ -168,12 +173,37 @@ public class FilePlanRoleServiceImplTest extends BaseRMTestCase
assertNotNull(roles);
assertEquals(1, roles.size());
Set<String> authorities = filePlanRoleService.getUsersAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER);
assertNotNull(authorities);
assertEquals(1, authorities.size());
authorities = filePlanRoleService.getGroupsAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER);
assertNotNull(authorities);
assertEquals(0, authorities.size());
authorities = filePlanRoleService.getAllAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER);
assertNotNull(authorities);
assertEquals(1, authorities.size());
filePlanRoleService.assignRoleToAuthority(filePlan, ROLE_NAME_RECORDS_MANAGER, rmUserName);
roles = filePlanRoleService.getRolesByUser(filePlan, rmUserName);
assertNotNull(roles);
assertEquals(2, roles.size());
authorities = filePlanRoleService.getUsersAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER);
assertNotNull(authorities);
assertEquals(2, authorities.size());
authorities = filePlanRoleService.getGroupsAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER);
assertNotNull(authorities);
assertEquals(0, authorities.size());
authorities = filePlanRoleService.getAllAssignedToRole(filePlan, ROLE_NAME_RECORDS_MANAGER);
assertNotNull(authorities);
assertEquals(2, authorities.size());
return null;
}
});

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.module.org_alfresco_module_rm.test.service;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.GUID;
/**
* File plan service unit test
*
* @author Roy Wetherall
* @since 2.1
*/
public class FilePlanServiceImplTest extends BaseRMTestCase
{
/**
* Pull in collaboration test data
*/
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
/**
* {@link FilePlanService#isFilePlan(org.alfresco.service.cmr.repository.NodeRef)}
*/
public void testIsFilePlan()
{
doTestInTransaction(new VoidTest()
{
public void runImpl() throws Exception
{
assertTrue(filePlanService.isFilePlan(filePlan));
assertFalse(filePlanService.isFilePlan(rmContainer));
assertFalse(filePlanService.isFilePlan(dmDocument));
}
});
}
/**
* {@link FilePlanService#getFilePlan(org.alfresco.service.cmr.repository.NodeRef)}
*/
public void testGetFilePlans()
{
doTestInTransaction(new VoidTest()
{
public void runImpl() throws Exception
{
assertEquals(filePlan, filePlanService.getFilePlan(filePlan));
assertEquals(filePlan, filePlanService.getFilePlan(rmContainer));
assertEquals(filePlan, filePlanService.getFilePlan(rmFolder));
assertNull(filePlanService.getFilePlan(dmDocument));
}
});
}
/**
* {@link FilePlanService#getFilePlanBySiteId(String)}
*/
public void testGetFilePlanBySiteId()
{
doTestInTransaction(new VoidTest()
{
public void runImpl() throws Exception
{
assertEquals(filePlan, filePlanService.getFilePlanBySiteId(SITE_ID));
assertNull(filePlanService.getFilePlanBySiteId("rubbish"));
String siteId = GUID.generate();
siteService.createSite("anything", siteId, "title", "descrition", SiteVisibility.PUBLIC);
assertNull(filePlanService.getFilePlanBySiteId(siteId));
}
});
}
}

View File

@@ -155,6 +155,7 @@ public class RecordsManagementServiceImplTest extends BaseRMTestCase
{
doTestInTransaction(new Test<NodeRef>()
{
@SuppressWarnings("deprecation")
@Override
public NodeRef run()
{
@@ -176,17 +177,10 @@ public class RecordsManagementServiceImplTest extends BaseRMTestCase
{
doTestInTransaction(new Test<NodeRef>()
{
@SuppressWarnings("deprecation")
@Override
public NodeRef run()
{
// List<NodeRef> roots = rmService.getRecordsManagementRoots(storeRef);
// assertNotNull(roots);
// assertTrue(roots.size() != 0);
// assertTrue(roots.contains(rmRootContainer));
//
// RecordsManagementServiceImpl temp = (RecordsManagementServiceImpl)applicationContext.getBean("recordsManagementService");
// temp.setDefaultStoreRef(storeRef);
List<NodeRef> roots = rmService.getFilePlans();
assertNotNull(roots);
assertTrue(roots.size() != 0);

View File

@@ -18,14 +18,18 @@
*/
package org.alfresco.module.org_alfresco_module_rm.test.webscript;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.util.GUID;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
@@ -41,9 +45,20 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
public class RoleRestApiTest extends BaseRMWebScriptTestCase
implements RecordsManagementModel
{
protected static final String GET_ROLES_URL = "/api/rma/admin/rmroles";
protected static final String GET_ROLES_URL_BY_SITE = "/api/rma/admin/{0}/rmroles";
protected static final String GET_ROLES_URL_BY_FILEPLAN = "/api/rma/admin/{0}/{1}/{2}/rmroles";
protected static final String SERVICE_URL_PREFIX = "/alfresco/service";
protected static final String APPLICATION_JSON = "application/json";
protected static final String APPLICATION_JSON = "application/json";
private String getRolesUrlBySite()
{
return MessageFormat.format(GET_ROLES_URL_BY_SITE, SITE_ID);
}
private String getRoleUrlByFilePlan()
{
return MessageFormat.format(GET_ROLES_URL_BY_FILEPLAN, filePlan.getStoreRef().getProtocol(), filePlan.getStoreRef().getIdentifier(), filePlan.getId());
}
public void testGetRoles() throws Exception
{
@@ -54,13 +69,18 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
filePlanRoleService.createRole(filePlan, role2, "My Test Role Too", getListOfCapabilities(5));
// create test group
String groupName = GUID.generate();
String group = authorityService.createAuthority(AuthorityType.GROUP, groupName, "monkey", null);
// Add the admin user to one of the roles
filePlanRoleService.assignRoleToAuthority(filePlan, role1, "admin");
filePlanRoleService.assignRoleToAuthority(filePlan, role1, group);
try
{
// Get the roles
Response rsp = sendRequest(new GetRequest(GET_ROLES_URL),200);
// Get the roles (for the default file plan)
Response rsp = sendRequest(new GetRequest(getRolesUrlBySite()),200);
String rspContent = rsp.getContentAsString();
JSONObject obj = new JSONObject(rspContent);
@@ -71,20 +91,16 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
assertNotNull(roleObj);
assertEquals(role1, roleObj.get("name"));
assertEquals("My Test Role", roleObj.get("displayLabel"));
JSONArray caps = roleObj.getJSONArray("capabilities");
assertNotNull(caps);
assertEquals(5, caps.length());
checkCapabilities(roleObj, 5);
roleObj = roles.getJSONObject(role2);
assertNotNull(roleObj);
assertEquals(role2, roleObj.get("name"));
assertEquals("My Test Role Too", roleObj.get("displayLabel"));
caps = roleObj.getJSONArray("capabilities");
assertNotNull(caps);
assertEquals(5, caps.length());
checkCapabilities(roleObj, 5);
// Get the roles for "admin"
rsp = sendRequest(new GetRequest(GET_ROLES_URL + "?user=admin"),200);
// Get the roles, specifying the file plan
rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan()),200);
rspContent = rsp.getContentAsString();
obj = new JSONObject(rspContent);
@@ -95,11 +111,67 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
assertNotNull(roleObj);
assertEquals(role1, roleObj.get("name"));
assertEquals("My Test Role", roleObj.get("displayLabel"));
caps = roleObj.getJSONArray("capabilities");
assertNotNull(caps);
assertEquals(5, caps.length());
checkCapabilities(roleObj, 5);
roleObj = roles.getJSONObject(role2);
assertNotNull(roleObj);
assertEquals(role2, roleObj.get("name"));
assertEquals("My Test Role Too", roleObj.get("displayLabel"));
checkCapabilities(roleObj, 5);
// Get the roles for "admin"
rsp = sendRequest(new GetRequest(getRolesUrlBySite() + "?user=admin"),200);
rspContent = rsp.getContentAsString();
obj = new JSONObject(rspContent);
roles = obj.getJSONObject("data");
assertNotNull(roles);
roleObj = roles.getJSONObject(role1);
assertNotNull(roleObj);
assertEquals(role1, roleObj.get("name"));
assertEquals("My Test Role", roleObj.get("displayLabel"));
checkCapabilities(roleObj, 5);
assertFalse(roles.has(role2));
// Get the roles including assigned authorities
rsp = sendRequest(new GetRequest(getRoleUrlByFilePlan() + "?auths=true"),200);
rspContent = rsp.getContentAsString();
System.out.println(rspContent);
obj = new JSONObject(rspContent);
roles = obj.getJSONObject("data");
assertNotNull(roles);
roleObj = roles.getJSONObject(role1);
assertNotNull(roleObj);
assertEquals(role1, roleObj.get("name"));
assertEquals("My Test Role", roleObj.get("displayLabel"));
checkCapabilities(roleObj, 5);
JSONArray users = roleObj.getJSONArray("assignedUsers");
assertNotNull(users);
assertEquals(1, users.length());
JSONArray groups = roleObj.getJSONArray("assignedGroups");
assertNotNull(groups);
assertEquals(1, groups.length());
roleObj = roles.getJSONObject(role2);
assertNotNull(roleObj);
assertEquals(role2, roleObj.get("name"));
assertEquals("My Test Role Too", roleObj.get("displayLabel"));
checkCapabilities(roleObj, 5);
users = roleObj.getJSONArray("assignedUsers");
assertNotNull(users);
assertEquals(0, users.length());
groups = roleObj.getJSONArray("assignedGroups");
assertNotNull(groups);
assertEquals(0, groups.length());
}
finally
{
@@ -110,6 +182,25 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
}
@SuppressWarnings("unchecked")
private void checkCapabilities(JSONObject role, int expectedCount) throws JSONException
{
JSONObject capabilities = role.getJSONObject("capabilities");
assertNotNull(capabilities);
int count = 0;
Iterator it = capabilities.keys();
while (it.hasNext())
{
String key = (String)it.next();
assertNotNull(key);
assertNotNull(capabilities.getString(key));
count ++;
}
assertEquals(expectedCount, count);
}
public void testPostRoles() throws Exception
{
Set<Capability> caps = getListOfCapabilities(5);
@@ -126,7 +217,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
obj.put("displayLabel", "Display Label");
obj.put("capabilities", arrCaps);
Response rsp = sendRequest(new PostRequest(GET_ROLES_URL, obj.toString(), APPLICATION_JSON),200);
Response rsp = sendRequest(new PostRequest(getRolesUrlBySite(), obj.toString(), APPLICATION_JSON),200);
try
{
String rspContent = rsp.getContentAsString();
@@ -138,9 +229,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
assertNotNull(roleObj);
assertEquals(roleName, roleObj.get("name"));
assertEquals("Display Label", roleObj.get("displayLabel"));
JSONArray resultCaps = roleObj.getJSONArray("capabilities");
assertNotNull(resultCaps);
assertEquals(5, resultCaps.length());
checkCapabilities(roleObj, 5);
}
finally
{
@@ -170,7 +259,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
obj.put("capabilities", arrCaps);
// Get the roles
Response rsp = sendRequest(new PutRequest(GET_ROLES_URL + "/" + role1, obj.toString(), APPLICATION_JSON),200);
Response rsp = sendRequest(new PutRequest(getRolesUrlBySite() + "/" + role1, obj.toString(), APPLICATION_JSON),200);
String rspContent = rsp.getContentAsString();
JSONObject result = new JSONObject(rspContent);
@@ -180,12 +269,10 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
assertNotNull(roleObj);
assertEquals(role1, roleObj.get("name"));
assertEquals("Changed", roleObj.get("displayLabel"));
JSONArray bob = roleObj.getJSONArray("capabilities");
assertNotNull(bob);
assertEquals(4, bob.length());
checkCapabilities(roleObj, 4);
// Bad requests
sendRequest(new PutRequest(GET_ROLES_URL + "/cheese", obj.toString(), APPLICATION_JSON), 404);
sendRequest(new PutRequest(getRolesUrlBySite() + "/cheese", obj.toString(), APPLICATION_JSON), 404);
}
finally
{
@@ -203,7 +290,7 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
try
{
// Get the roles
Response rsp = sendRequest(new GetRequest(GET_ROLES_URL + "/" + role1),200);
Response rsp = sendRequest(new GetRequest(getRolesUrlBySite() + "/" + role1),200);
String rspContent = rsp.getContentAsString();
JSONObject obj = new JSONObject(rspContent);
@@ -213,12 +300,10 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
assertNotNull(roleObj);
assertEquals(role1, roleObj.get("name"));
assertEquals("My Test Role", roleObj.get("displayLabel"));
JSONArray caps = roleObj.getJSONArray("capabilities");
assertNotNull(caps);
assertEquals(5, caps.length());
checkCapabilities(roleObj, 5);
// Bad requests
sendRequest(new GetRequest(GET_ROLES_URL + "/cheese"), 404);
sendRequest(new GetRequest(getRolesUrlBySite() + "/cheese"), 404);
}
finally
{
@@ -234,11 +319,11 @@ public class RoleRestApiTest extends BaseRMWebScriptTestCase
assertFalse(filePlanRoleService.existsRole(filePlan, role1));
filePlanRoleService.createRole(filePlan, role1, "My Test Role", getListOfCapabilities(5));
assertTrue(filePlanRoleService.existsRole(filePlan, role1));
sendRequest(new DeleteRequest(GET_ROLES_URL + "/" + role1),200);
sendRequest(new DeleteRequest(getRolesUrlBySite() + "/" + role1),200);
assertFalse(filePlanRoleService.existsRole(filePlan, role1));
// Bad request
sendRequest(new DeleteRequest(GET_ROLES_URL + "/cheese"), 404);
sendRequest(new DeleteRequest(getRolesUrlBySite() + "/cheese"), 404);
}
private Set<Capability> getListOfCapabilities(int size)