mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM: Add extended rule service which allows RM rules to be executed as RMAdmin
* unit test fix ups * fix test fall out from previous changes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@46815 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,6 +23,13 @@ audit.rm.enabled=true
|
||||
#
|
||||
cache.writersSharedCache.maxItems=10000
|
||||
|
||||
#
|
||||
# Global RM admin default bootstrap details
|
||||
#
|
||||
bootstrap.rmadmin.name=rmadmin
|
||||
bootstrap.rmadmin.pwd=rmadmin
|
||||
|
||||
#
|
||||
# Indicates whether RM rules will be run as RM Admin or not by default
|
||||
#
|
||||
rm.rule.runasrmadmin=true
|
@@ -157,4 +157,29 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Rule Service -->
|
||||
|
||||
<bean id="ruleService" class="org.alfresco.repo.rule.ExtendedRuleServiceImpl" init-method="init">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
<property name="runtimeNodeService" ref="nodeService"/>
|
||||
<property name="copyService" ref="copyService"/>
|
||||
<property name="actionService" ref="ActionService"/>
|
||||
<property name="runtimeActionService" ref="actionService"/>
|
||||
<property name="dictionaryService" ref="dictionaryService"/>
|
||||
<property name="policyComponent" ref="policyComponent"/>
|
||||
<property name="permissionService" ref="permissionService"/>
|
||||
<property name="nodeRulesCache" ref="nodeRulesCache"/>
|
||||
<property name="rulesDisabled">
|
||||
<value>false</value>
|
||||
</property>
|
||||
|
||||
<!-- Since RM 2.1 -->
|
||||
<property name="filePlanAuthenticationService" ref="FilePlanAuthenticationService"/>
|
||||
<property name="recordsManagementService" ref="RecordsManagementService" />
|
||||
<property name="runAsRmAdmin">
|
||||
<value>${rm.rule.runasrmadmin}</value>
|
||||
</property>
|
||||
|
||||
</bean>
|
||||
|
||||
</beans>
|
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.rule;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanAuthenticationService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.rule.Rule;
|
||||
|
||||
/**
|
||||
* Extended rule service implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedRuleServiceImpl extends RuleServiceImpl
|
||||
{
|
||||
private boolean runAsRmAdmin = true;
|
||||
|
||||
private FilePlanAuthenticationService filePlanAuthenticationService;
|
||||
|
||||
private RecordsManagementService recordsManagementService;
|
||||
|
||||
public void setRunAsRmAdmin(boolean runAsRmAdmin)
|
||||
{
|
||||
this.runAsRmAdmin = runAsRmAdmin;
|
||||
}
|
||||
|
||||
public void setFilePlanAuthenticationService(FilePlanAuthenticationService filePlanAuthenticationService)
|
||||
{
|
||||
this.filePlanAuthenticationService = filePlanAuthenticationService;
|
||||
}
|
||||
|
||||
public void setRecordsManagementService(RecordsManagementService recordsManagementService)
|
||||
{
|
||||
this.recordsManagementService = recordsManagementService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeRule(final Rule rule, final NodeRef nodeRef, final Set<ExecutedRuleData> executedRules)
|
||||
{
|
||||
if (isFilePlanComponentRule(rule) == true && runAsRmAdmin == true)
|
||||
{
|
||||
filePlanAuthenticationService.runAsRmAdmin(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// just execute the rule as the current user
|
||||
super.executeRule(rule, nodeRef, executedRules);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFilePlanComponentRule(Rule rule)
|
||||
{
|
||||
NodeRef nodeRef = getOwningNodeRef(rule);
|
||||
return recordsManagementService.isFilePlanComponent(nodeRef);
|
||||
}
|
||||
}
|
@@ -108,13 +108,15 @@ public class CapabilityServiceImplTest extends BaseRMTestCase
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
int initialSize = capabilityService.getGroups().size();
|
||||
|
||||
GroupImpl testGroup = new GroupImpl();
|
||||
testGroup.setId("testGroup");
|
||||
testGroup.setIndex(140);
|
||||
testGroup.setTitle("Test group");
|
||||
capabilityService.addGroup(testGroup);
|
||||
|
||||
assertTrue(capabilityService.getGroups().size() == 14);
|
||||
assertEquals(initialSize+1, capabilityService.getGroups().size());
|
||||
|
||||
Group group = capabilityService.getGroup("testGroup");
|
||||
assertNotNull(group);
|
||||
@@ -133,36 +135,10 @@ public class CapabilityServiceImplTest extends BaseRMTestCase
|
||||
{
|
||||
Group testGroup = capabilityService.getGroup("testGroup");
|
||||
assertNotNull(testGroup);
|
||||
int initialSize = capabilityService.getGroups().size();
|
||||
|
||||
capabilityService.removeGroup(testGroup);
|
||||
assertTrue(capabilityService.getGroups().size() == 13);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void run() throws Exception
|
||||
{
|
||||
List<Group> groups = capabilityService.getGroups();
|
||||
assertNotNull(groups);
|
||||
|
||||
int size = groups.size();
|
||||
assertTrue(size == 13);
|
||||
|
||||
Group auditGroup = groups.get(0);
|
||||
assertNotNull(auditGroup);
|
||||
assertTrue(auditGroup.getIndex() == 10);
|
||||
assertTrue(auditGroup.getId().equalsIgnoreCase("audit"));
|
||||
assertTrue(auditGroup.getTitle().equalsIgnoreCase("Audit"));
|
||||
|
||||
Group vitalRecords = groups.get(size - 1);
|
||||
assertNotNull(vitalRecords);
|
||||
assertTrue(vitalRecords.getIndex() == 130);
|
||||
assertTrue(vitalRecords.getId().equalsIgnoreCase("vitalRecords"));
|
||||
assertTrue(vitalRecords.getTitle().equalsIgnoreCase("Vital Records"));
|
||||
assertEquals(initialSize-1, capabilityService.getGroups().size());
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -186,7 +162,7 @@ public class CapabilityServiceImplTest extends BaseRMTestCase
|
||||
assertNotNull(auditCapabilities);
|
||||
|
||||
int vitalRecordCapabilitiesSize = auditCapabilities.size();
|
||||
assertTrue(vitalRecordCapabilitiesSize == 6);
|
||||
assertEquals(4, vitalRecordCapabilitiesSize);
|
||||
|
||||
for (int i = 1; i == vitalRecordCapabilitiesSize; i++)
|
||||
{
|
||||
@@ -202,7 +178,7 @@ public class CapabilityServiceImplTest extends BaseRMTestCase
|
||||
assertNotNull(vitalRecordCapabilities);
|
||||
|
||||
vitalRecordCapabilitiesSize = vitalRecordCapabilities.size();
|
||||
assertEquals(3, vitalRecordCapabilitiesSize);
|
||||
assertEquals(1, vitalRecordCapabilitiesSize);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@@ -524,7 +524,7 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
import org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchParameters;
|
||||
import org.alfresco.module.org_alfresco_module_rm.search.SavedSearchDetails;
|
||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.util.TestWithUserUtils;
|
||||
@@ -89,7 +90,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,14 +118,12 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
|
||||
doTestInTransaction(new Test<Void>()
|
||||
{
|
||||
@Override
|
||||
@@ -136,7 +135,9 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testSearch()
|
||||
@@ -156,7 +157,7 @@ public class RecordsManagementSearchServiceImplTest extends BaseRMTestCase
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
|
||||
// Property search
|
||||
|
||||
|
@@ -101,6 +101,9 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
||||
/** Common test utils */
|
||||
protected CommonRMTestUtils utils;
|
||||
|
||||
/** RM Admin user name */
|
||||
protected String rmAdminUserName;
|
||||
|
||||
/** Services */
|
||||
protected NodeService nodeService;
|
||||
protected ContentService contentService;
|
||||
@@ -293,6 +296,20 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
||||
// Initialise the service beans
|
||||
initServices();
|
||||
|
||||
// grab the rmadmin user name
|
||||
retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>()
|
||||
{
|
||||
@Override
|
||||
public Object execute() throws Throwable
|
||||
{
|
||||
// As system user
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
|
||||
rmAdminUserName = filePlanAuthenticationService.getRmAdminUserName();
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
// Setup test data
|
||||
setupTestData();
|
||||
|
||||
@@ -671,13 +688,13 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase
|
||||
@Override
|
||||
protected <A> A doTestInTransaction(Test<A> test)
|
||||
{
|
||||
return super.doTestInTransaction(test, filePlanAuthenticationService.getRmAdminUserName());
|
||||
return super.doTestInTransaction(test, rmAdminUserName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doTestInTransaction(FailureTest test)
|
||||
{
|
||||
super.doTestInTransaction(test, filePlanAuthenticationService.getRmAdminUserName());
|
||||
super.doTestInTransaction(test, rmAdminUserName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user