From 53e37bab757f2a18f17c8b185477787558e30c4c Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Wed, 20 Feb 2013 05:08:46 +0000 Subject: [PATCH] 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 --- .../alfresco-global.properties | 9 +- .../extended-repository-context.xml | 25 ++++++ .../repo/rule/ExtendedRuleServiceImpl.java | 85 +++++++++++++++++++ .../service/CapabilityServiceImplTest.java | 38 ++------- ...RecordsManagementAdminServiceImplTest.java | 2 +- ...ecordsManagementSearchServiceImplTest.java | 13 +-- .../test/util/BaseRMTestCase.java | 21 ++++- 7 files changed, 152 insertions(+), 41 deletions(-) create mode 100644 rm-server/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties b/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties index 34c19ce0b6..e7a6836cb4 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties @@ -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 \ No newline at end of file +bootstrap.rmadmin.pwd=rmadmin + +# +# Indicates whether RM rules will be run as RM Admin or not by default +# +rm.rule.runasrmadmin=true \ No newline at end of file diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/extended-repository-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/extended-repository-context.xml index 232cba0185..f36ff9f590 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/extended-repository-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/extended-repository-context.xml @@ -157,4 +157,29 @@ + + + + + + + + + + + + + + false + + + + + + + ${rm.rule.runasrmadmin} + + + + \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java b/rm-server/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java new file mode 100644 index 0000000000..374cda3c12 --- /dev/null +++ b/rm-server/source/java/org/alfresco/repo/rule/ExtendedRuleServiceImpl.java @@ -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 . + */ +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 executedRules) + { + if (isFilePlanComponentRule(rule) == true && runAsRmAdmin == true) + { + filePlanAuthenticationService.runAsRmAdmin(new RunAsWork() + { + @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); + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java index 48c23a0e6a..782ebcf4db 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/CapabilityServiceImplTest.java @@ -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() - { - @Override - public Void run() throws Exception - { - List 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; } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java index eb03a63656..b10067fb8a 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementAdminServiceImplTest.java @@ -524,7 +524,7 @@ public class RecordsManagementAdminServiceImplTest extends BaseRMTestCase return null; } - }); + }, AuthenticationUtil.getSystemUserName()); } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java index 5edf2b2428..169345f991 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSearchServiceImplTest.java @@ -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() { @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 diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 049541d91f..73f3dc19b5 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -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() + { + @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 doTestInTransaction(Test 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); } /**