mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-722 (REST API - Add and remove authorities from roles)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@50274 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -514,7 +514,7 @@
|
|||||||
<bean id="webscript.org.alfresco.repository.rule.rm-actiondefinitions.get"
|
<bean id="webscript.org.alfresco.repository.rule.rm-actiondefinitions.get"
|
||||||
class="org.alfresco.repo.web.scripts.rule.RmActionDefinitionsGet"
|
class="org.alfresco.repo.web.scripts.rule.RmActionDefinitionsGet"
|
||||||
parent="webscript">
|
parent="webscript">
|
||||||
<property name="recordsManagementActionService" ref="RecordsManagementActionService"/>
|
<property name="recordsManagementActionService" ref="RecordsManagementActionService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- REST impl for GET Action Condition Defitions for RM -->
|
<!-- REST impl for GET Action Condition Defitions for RM -->
|
||||||
@@ -522,7 +522,7 @@
|
|||||||
class="org.alfresco.repo.web.scripts.rule.RmActionConditionDefinitionsGet"
|
class="org.alfresco.repo.web.scripts.rule.RmActionConditionDefinitionsGet"
|
||||||
parent="webscript">
|
parent="webscript">
|
||||||
<property name="actionService" ref="ActionService"/>
|
<property name="actionService" ref="ActionService"/>
|
||||||
<property name="recordsManagementActionService" ref="RecordsManagementActionService"/>
|
<property name="recordsManagementActionService" ref="RecordsManagementActionService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- REST impl for GET Class Definitions for RM/DM -->
|
<!-- REST impl for GET Class Definitions for RM/DM -->
|
||||||
@@ -539,4 +539,22 @@
|
|||||||
<property name="siteService" ref="SiteService" />
|
<property name="siteService" ref="SiteService" />
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
<!-- REST impl for POST Children for RM -->
|
||||||
|
<bean id="webscript.org.alfresco.repository.groups.rm-children.post"
|
||||||
|
class="org.alfresco.repo.web.scripts.groups.RmChildrenPost"
|
||||||
|
parent="webscript">
|
||||||
|
<property name="filePlanService" ref="FilePlanService" />
|
||||||
|
<property name="filePlanRoleService" ref="FilePlanRoleService" />
|
||||||
|
<property name="authorityService" ref="AuthorityService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- REST impl for DELETE Children for RM -->
|
||||||
|
<bean id="webscript.org.alfresco.repository.groups.rm-children.delete"
|
||||||
|
class="org.alfresco.repo.web.scripts.groups.RmChildrenDelete"
|
||||||
|
parent="webscript">
|
||||||
|
<property name="filePlanService" ref="FilePlanService" />
|
||||||
|
<property name="filePlanRoleService" ref="FilePlanRoleService" />
|
||||||
|
<property name="authorityService" ref="AuthorityService" />
|
||||||
|
</bean>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
@@ -0,0 +1,12 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Remove a group or a user from a role</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Removes a group or a user from a role.
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<url>/api/rm/role/{roleId}/children/{authorityName}</url>
|
||||||
|
<url>/api/rm/{store_type}/{store_id}/{id}/role/{roleId}/children/{authorityName}</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -0,0 +1 @@
|
|||||||
|
{}
|
@@ -0,0 +1,12 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Add a group or a user to a role</shortname>
|
||||||
|
<description><![CDATA[
|
||||||
|
Adds a group or a user to a role.
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<url>/api/rm/role/{roleId}/children/{authorityName}</url>
|
||||||
|
<url>/api/rm/{store_type}/{store_id}/{id}/role/{roleId}/children/{authorityName}</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
</webscript>
|
@@ -0,0 +1 @@
|
|||||||
|
{}
|
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* 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.repo.web.scripts.groups;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.script.admin.RoleDeclarativeWebScript;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
import org.tuckey.web.filters.urlrewrite.utils.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract class for adding/removing a user/group to/from a role
|
||||||
|
* This class contains the common methods needed in the sub classes.
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.1
|
||||||
|
*/
|
||||||
|
public class RmChildrenAbstract extends RoleDeclarativeWebScript
|
||||||
|
{
|
||||||
|
/** Constants for the url parameters */
|
||||||
|
private static final String ROLE_ID = "roleId";
|
||||||
|
private static final String AUTHORITY_NAME = "authorityName";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method for getting the nodeRef from the request
|
||||||
|
*
|
||||||
|
* @param req The webscript request
|
||||||
|
* @return The nodeRef passed in the request
|
||||||
|
*/
|
||||||
|
protected NodeRef getFilePlan(WebScriptRequest req)
|
||||||
|
{
|
||||||
|
NodeRef filePlan = super.getFilePlan(req);
|
||||||
|
if (filePlan == null)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No filePlan was provided on the URL.");
|
||||||
|
}
|
||||||
|
return filePlan;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method for getting the roleId from the request
|
||||||
|
*
|
||||||
|
* @param req The webscript request
|
||||||
|
* @return The role id passed in the request
|
||||||
|
*/
|
||||||
|
protected String getRoleId(WebScriptRequest req)
|
||||||
|
{
|
||||||
|
return getParamValue(req, ROLE_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method for getting the authorityName from the request
|
||||||
|
*
|
||||||
|
* @param req The webscript request
|
||||||
|
* @return The authorityName passed in the request
|
||||||
|
*/
|
||||||
|
protected String getAuthorityName(WebScriptRequest req)
|
||||||
|
{
|
||||||
|
return getParamValue(req, AUTHORITY_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to get the value of parameter from the request
|
||||||
|
*
|
||||||
|
* @param req The webscript request
|
||||||
|
* @param param The name of the parameter for which the value is requested
|
||||||
|
* @return The value for the requested parameter
|
||||||
|
*/
|
||||||
|
private String getParamValue(WebScriptRequest req, String param)
|
||||||
|
{
|
||||||
|
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||||
|
|
||||||
|
String authorityName = templateVars.get(param);
|
||||||
|
if (StringUtils.isBlank(authorityName))
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No '" + param + "' was provided on the URL.");
|
||||||
|
}
|
||||||
|
return authorityName;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.repo.web.scripts.groups;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Webscript for removing a user or a group from a role
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.1
|
||||||
|
*/
|
||||||
|
public class RmChildrenDelete extends RmChildrenAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
|
||||||
|
* org.springframework.extensions.webscripts.Status,
|
||||||
|
* org.springframework.extensions.webscripts.Cache)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
NodeRef filePlan = getFilePlan(req);
|
||||||
|
String roleId = getRoleId(req);
|
||||||
|
String authorityName = getAuthorityName(req);
|
||||||
|
|
||||||
|
filePlanRoleService.unassignRoleFromAuthority(filePlan, roleId, authorityName);
|
||||||
|
|
||||||
|
return new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* 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.repo.web.scripts.groups;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Webscript for adding a user or a group to a role
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.1
|
||||||
|
*/
|
||||||
|
public class RmChildrenPost extends RmChildrenAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
|
||||||
|
* org.springframework.extensions.webscripts.Status,
|
||||||
|
* org.springframework.extensions.webscripts.Cache)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
NodeRef filePlan = getFilePlan(req);
|
||||||
|
String roleId = getRoleId(req);
|
||||||
|
String authorityName = getAuthorityName(req);
|
||||||
|
|
||||||
|
filePlanRoleService.assignRoleToAuthority(filePlan, roleId, authorityName);
|
||||||
|
|
||||||
|
return new HashMap<String, Object>();
|
||||||
|
}
|
||||||
|
}
|
@@ -27,6 +27,7 @@ import org.alfresco.module.org_alfresco_module_rm.test.webscript.EmailMapScriptT
|
|||||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.EventRestApiTest;
|
import org.alfresco.module.org_alfresco_module_rm.test.webscript.EventRestApiTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMCaveatConfigScriptTest;
|
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMCaveatConfigScriptTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMConstraintScriptTest;
|
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RMConstraintScriptTest;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RmChildrenRestApiTest;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RoleRestApiTest;
|
import org.alfresco.module.org_alfresco_module_rm.test.webscript.RoleRestApiTest;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Suite;
|
import org.junit.runners.Suite;
|
||||||
@@ -51,10 +52,10 @@ import org.junit.runners.Suite.SuiteClasses;
|
|||||||
EmailMapScriptTest.class,
|
EmailMapScriptTest.class,
|
||||||
EmailMapKeysRestApiTest.class,
|
EmailMapKeysRestApiTest.class,
|
||||||
CapabilitiesRestApiTest.class,
|
CapabilitiesRestApiTest.class,
|
||||||
ActionDefinitionsRestApiTest.class
|
ActionDefinitionsRestApiTest.class,
|
||||||
//RmClassesRestApiTest.class,
|
//RmClassesRestApiTest.class,
|
||||||
//RmPropertiesRestApiTest.class
|
//RmPropertiesRestApiTest.class,
|
||||||
|
RmChildrenRestApiTest.class
|
||||||
})
|
})
|
||||||
public class WebScriptTestSuite
|
public class WebScriptTestSuite
|
||||||
{
|
{
|
||||||
|
@@ -51,6 +51,7 @@ import org.alfresco.service.cmr.repository.Period;
|
|||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
import org.alfresco.service.cmr.search.SearchService;
|
import org.alfresco.service.cmr.search.SearchService;
|
||||||
import org.alfresco.service.cmr.security.AuthorityService;
|
import org.alfresco.service.cmr.security.AuthorityService;
|
||||||
|
import org.alfresco.service.cmr.security.AuthorityType;
|
||||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.cmr.site.SiteInfo;
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
@@ -60,6 +61,7 @@ import org.alfresco.service.cmr.tagging.TaggingService;
|
|||||||
import org.alfresco.service.namespace.NamespaceService;
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
import org.alfresco.util.PropertyMap;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,12 +230,12 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
|
|||||||
@Override
|
@Override
|
||||||
public Object execute() throws Throwable
|
public Object execute() throws Throwable
|
||||||
{
|
{
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||||
setupTestDataImpl();
|
setupTestDataImpl();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -330,4 +332,40 @@ public class BaseRMWebScriptTestCase extends BaseWebScriptTest
|
|||||||
|
|
||||||
assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary);
|
assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createUser(String userName)
|
||||||
|
{
|
||||||
|
if (authenticationService.authenticationExists(userName) == false)
|
||||||
|
{
|
||||||
|
authenticationService.createAuthentication(userName, "PWD".toCharArray());
|
||||||
|
|
||||||
|
PropertyMap ppOne = new PropertyMap(4);
|
||||||
|
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
||||||
|
ppOne.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, "title" + userName);
|
||||||
|
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
|
||||||
|
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
|
||||||
|
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
|
||||||
|
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
|
||||||
|
|
||||||
|
personService.createPerson(ppOne);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deleteUser(String userName)
|
||||||
|
{
|
||||||
|
personService.deletePerson(userName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createGroup(String groupName)
|
||||||
|
{
|
||||||
|
if (authorityService.authorityExists(groupName) == false)
|
||||||
|
{
|
||||||
|
authorityService.createAuthority(AuthorityType.GROUP, groupName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deleteGroup(String groupName)
|
||||||
|
{
|
||||||
|
authorityService.deleteAuthority(groupName, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -21,13 +21,9 @@ package org.alfresco.module.org_alfresco_module_rm.test.webscript;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService;
|
import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
|
||||||
import org.alfresco.util.PropertyMap;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||||
@@ -40,27 +36,23 @@ import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
|||||||
*/
|
*/
|
||||||
public class RMConstraintScriptTest extends BaseRMWebScriptTestCase
|
public class RMConstraintScriptTest extends BaseRMWebScriptTestCase
|
||||||
{
|
{
|
||||||
private MutableAuthenticationService authenticationService;
|
|
||||||
private RMCaveatConfigService caveatConfigService;
|
private RMCaveatConfigService caveatConfigService;
|
||||||
private PersonService personService;
|
|
||||||
|
|
||||||
protected final static String RM_LIST = "rmc:smListTest";
|
protected final static String RM_LIST = "rmc:smListTest";
|
||||||
protected final static String RM_LIST_URI_ELEM = "rmc_smListTest";
|
protected final static String RM_LIST_URI_ELEM = "rmc_smListTest";
|
||||||
|
|
||||||
private static final String URL_RM_CONSTRAINTS = "/api/rma/rmconstraints";
|
private static final String URL_RM_CONSTRAINTS = "/api/rma/rmconstraints";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initServices()
|
protected void initServices()
|
||||||
{
|
{
|
||||||
super.initServices();
|
super.initServices();
|
||||||
|
|
||||||
this.caveatConfigService = (RMCaveatConfigService)getServer().getApplicationContext().getBean("CaveatConfigService");
|
this.caveatConfigService = (RMCaveatConfigService)getServer().getApplicationContext().getBean("CaveatConfigService");
|
||||||
this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
|
|
||||||
this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testGetRMConstraint() throws Exception
|
public void testGetRMConstraint() throws Exception
|
||||||
@@ -76,62 +68,44 @@ public class RMConstraintScriptTest extends BaseRMWebScriptTestCase
|
|||||||
caveatConfigService.deleteRMConstraint(RM_LIST);
|
caveatConfigService.deleteRMConstraint(RM_LIST);
|
||||||
}
|
}
|
||||||
caveatConfigService.addRMConstraint(RM_LIST, "my title", new String[0]);
|
caveatConfigService.addRMConstraint(RM_LIST, "my title", new String[0]);
|
||||||
|
|
||||||
|
|
||||||
createUser("fbloggs");
|
createUser("fbloggs");
|
||||||
createUser("jrogers");
|
createUser("jrogers");
|
||||||
createUser("jdoe");
|
createUser("jdoe");
|
||||||
|
|
||||||
|
|
||||||
List<String> values = new ArrayList<String>();
|
List<String> values = new ArrayList<String>();
|
||||||
values.add("NOFORN");
|
values.add("NOFORN");
|
||||||
values.add("FGI");
|
values.add("FGI");
|
||||||
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "fbloggs", values);
|
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "fbloggs", values);
|
||||||
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jrogers", values);
|
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jrogers", values);
|
||||||
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jdoe", values);
|
caveatConfigService.updateRMConstraintListAuthority(RM_LIST, "jdoe", values);
|
||||||
|
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser("jdoe");
|
AuthenticationUtil.setFullyAuthenticatedUser("jdoe");
|
||||||
/**
|
/**
|
||||||
* Positive test Get the constraint
|
* Positive test Get the constraint
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
String url = URL_RM_CONSTRAINTS + "/" + RM_LIST_URI_ELEM;
|
String url = URL_RM_CONSTRAINTS + "/" + RM_LIST_URI_ELEM;
|
||||||
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
|
Response response = sendRequest(new GetRequest(url), Status.STATUS_OK);
|
||||||
JSONObject top = new JSONObject(response.getContentAsString());
|
JSONObject top = new JSONObject(response.getContentAsString());
|
||||||
|
|
||||||
JSONObject data = top.getJSONObject("data");
|
JSONObject data = top.getJSONObject("data");
|
||||||
System.out.println(response.getContentAsString());
|
System.out.println(response.getContentAsString());
|
||||||
|
|
||||||
data.getJSONArray("allowedValuesForCurrentUser");
|
data.getJSONArray("allowedValuesForCurrentUser");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
||||||
personService.deletePerson("fbloggs");
|
deleteUser("fbloggs");
|
||||||
personService.deletePerson("jrogers");
|
deleteUser("jrogers");
|
||||||
personService.deletePerson("jdoe");
|
deleteUser("jdoe");
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createUser(String userName)
|
|
||||||
{
|
|
||||||
if (this.authenticationService.authenticationExists(userName) == false)
|
|
||||||
{
|
|
||||||
this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
|
|
||||||
|
|
||||||
PropertyMap ppOne = new PropertyMap(4);
|
|
||||||
ppOne.put(ContentModel.PROP_USERNAME, userName);
|
|
||||||
ppOne.put(ContentModel.PROP_AUTHORITY_DISPLAY_NAME, "title" + userName);
|
|
||||||
ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
|
|
||||||
ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
|
|
||||||
ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
|
|
||||||
ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
|
|
||||||
|
|
||||||
this.personService.createPerson(ppOne);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* 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.webscript;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMWebScriptTestCase;
|
||||||
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
||||||
|
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||||
|
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST API Tests for adding/removing users/groups to/from a role
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.1
|
||||||
|
*/
|
||||||
|
public class RmChildrenRestApiTest extends BaseRMWebScriptTestCase
|
||||||
|
{
|
||||||
|
/** URL for the REST APIs */
|
||||||
|
private static final String RM_CHILDREN_URL = "/api/rm/%s/role/%s/children/%s";
|
||||||
|
|
||||||
|
/** Constant for the content type */
|
||||||
|
private static final String APPLICATION_JSON = "application/json";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the REST API to add/remove a user to/from a role
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
|
public void testRmAddRemoveUser() throws IOException, JSONException
|
||||||
|
{
|
||||||
|
// Create a test user
|
||||||
|
String userName = "geshjsjuasftg";
|
||||||
|
createUser(userName);
|
||||||
|
|
||||||
|
// Check if the user is already assigned to the role
|
||||||
|
assertFalse(getUsersAssignedToRole().contains(userName));
|
||||||
|
|
||||||
|
// Format url and send request
|
||||||
|
String url = getFormattedUrlString(userName);
|
||||||
|
Response response = postRequest(url);
|
||||||
|
|
||||||
|
// Check the content from the response
|
||||||
|
checkContent(response);
|
||||||
|
|
||||||
|
// The user should be added to the role
|
||||||
|
assertTrue(getUsersAssignedToRole().contains(userName));
|
||||||
|
|
||||||
|
// Remove the user from the role
|
||||||
|
response = deleteRequest(url);
|
||||||
|
|
||||||
|
// Check the content from the response
|
||||||
|
checkContent(response);
|
||||||
|
|
||||||
|
// The user should be removed from the role
|
||||||
|
assertFalse(getUsersAssignedToRole().contains(userName));
|
||||||
|
|
||||||
|
// Delete the user
|
||||||
|
deleteUser(userName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the REST API to add/remove a group to/from a role
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws JSONException
|
||||||
|
*/
|
||||||
|
public void testRmAddRemoveGroup() throws IOException, JSONException
|
||||||
|
{
|
||||||
|
// Create a group
|
||||||
|
String groupName = "arhweurawy";
|
||||||
|
createGroup(groupName);
|
||||||
|
|
||||||
|
// Check if the group is already assigned to the role
|
||||||
|
assertFalse(getGroupsAssignedToRole().contains(groupName));
|
||||||
|
|
||||||
|
// Format url and send request
|
||||||
|
String url = getFormattedUrlString(groupName);
|
||||||
|
Response response = postRequest(url);
|
||||||
|
|
||||||
|
// Check the content from the response
|
||||||
|
checkContent(response);
|
||||||
|
|
||||||
|
// The group should be added to the role
|
||||||
|
assertTrue(getGroupsAssignedToRole().contains(groupName));
|
||||||
|
|
||||||
|
// Remove the group from the role
|
||||||
|
response = deleteRequest(url);
|
||||||
|
|
||||||
|
// Check the content from the response
|
||||||
|
checkContent(response);
|
||||||
|
|
||||||
|
// The user should be removed from the role
|
||||||
|
assertFalse(getGroupsAssignedToRole().contains(groupName));
|
||||||
|
|
||||||
|
// Delete the group
|
||||||
|
deleteGroup(groupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method to get a set of groups assigned to a role
|
||||||
|
*
|
||||||
|
* @return Returns a set of groups assigned to a role
|
||||||
|
*/
|
||||||
|
private Set<String> getGroupsAssignedToRole()
|
||||||
|
{
|
||||||
|
return filePlanRoleService.getGroupsAssignedToRole(filePlan, FilePlanRoleService.ROLE_SECURITY_OFFICER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method to get a set of users assigned to a role
|
||||||
|
*
|
||||||
|
* @return Returns a set of users assigned to a role
|
||||||
|
*/
|
||||||
|
private Set<String> getUsersAssignedToRole()
|
||||||
|
{
|
||||||
|
return filePlanRoleService.getUsersAssignedToRole(filePlan, FilePlanRoleService.ROLE_SECURITY_OFFICER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method to get a formatted nodeRef string
|
||||||
|
*
|
||||||
|
* @return Returns a formatted nodeRef string
|
||||||
|
*/
|
||||||
|
private String getFormattedFilePlanString()
|
||||||
|
{
|
||||||
|
StoreRef storeRef = filePlan.getStoreRef();
|
||||||
|
String storeType = storeRef.getProtocol();
|
||||||
|
String storeId = storeRef.getIdentifier();
|
||||||
|
String id = filePlan.getId();
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append(storeType);
|
||||||
|
sb.append("/");
|
||||||
|
sb.append(storeId);
|
||||||
|
sb.append("/");
|
||||||
|
sb.append(id);
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method to get a formatted url string
|
||||||
|
*
|
||||||
|
* @param authorityName The name of the authority which should be added/removed to/from a role
|
||||||
|
* @return Returns a formatted url string
|
||||||
|
*/
|
||||||
|
private String getFormattedUrlString(String authorityName)
|
||||||
|
{
|
||||||
|
return String.format(RM_CHILDREN_URL, getFormattedFilePlanString(), FilePlanRoleService.ROLE_SECURITY_OFFICER, authorityName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method to send a post request
|
||||||
|
*
|
||||||
|
* @param url The url which should be used to make the post request
|
||||||
|
* @return Returns the response from the server
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private Response postRequest(String url) throws UnsupportedEncodingException, IOException
|
||||||
|
{
|
||||||
|
return sendRequest(new PostRequest(url, new JSONObject().toString(), APPLICATION_JSON), Status.STATUS_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method to send a delete request
|
||||||
|
*
|
||||||
|
* @param url The url which should be used to make the delete request
|
||||||
|
* @return Returns the response from the server
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private Response deleteRequest(String url) throws IOException
|
||||||
|
{
|
||||||
|
return sendRequest(new DeleteRequest(url), Status.STATUS_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Util method to check the server response
|
||||||
|
*
|
||||||
|
* @param response The server response
|
||||||
|
* @throws UnsupportedEncodingException
|
||||||
|
*/
|
||||||
|
private void checkContent(Response response) throws UnsupportedEncodingException
|
||||||
|
{
|
||||||
|
String contentAsString = response.getContentAsString();
|
||||||
|
assertNotNull(contentAsString);
|
||||||
|
assertTrue(contentAsString.equals("{}"));
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user