) AlfrescoTransactionSupport.getResource("MyAuthCache");
- Authentication auth = AuthenticationUtil.getRunAsAuthentication();
- if (auths != null)
- {
- if (auth == null || !auths.contains(((User)auth.getPrincipal()).getUsername()))
- {
- auths = null;
- }
- }
- if (auths == null)
- {
- auths = getCoreAuthorisations(auth);
- AlfrescoTransactionSupport.bindResource("MyAuthCache", auths);
- }
- return Collections.unmodifiableSet(auths);
- }
-
-}
diff --git a/rm-server/source/java/org/alfresco/repo/security/permissions/impl/RMPermissionServiceImpl.java b/rm-server/source/java/org/alfresco/repo/security/permissions/impl/RMPermissionServiceImpl.java
new file mode 100644
index 0000000000..21649f23bc
--- /dev/null
+++ b/rm-server/source/java/org/alfresco/repo/security/permissions/impl/RMPermissionServiceImpl.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2005-2012 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.security.permissions.impl;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
+import org.alfresco.repo.security.permissions.AccessControlEntry;
+import org.alfresco.repo.security.permissions.AccessControlList;
+import org.alfresco.service.cmr.security.PermissionService;
+
+/**
+ * Extends the core permission service implementation allowing the consideration of the read records
+ * permission.
+ *
+ * This is required for SOLR support.
+ *
+ * @author Roy Wetherall
+ */
+public class RMPermissionServiceImpl extends PermissionServiceImpl
+{
+
+ /**
+ * Builds the set of authorities who can read the given ACL. No caching is done here.
+ *
+ * @return an unmodifiable set of authorities
+ */
+ protected Set buildReaders(Long aclId)
+ {
+ AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
+ if (acl == null)
+ {
+ return Collections.emptySet();
+ }
+
+ HashSet assigned = new HashSet();
+ HashSet readers = new HashSet();
+
+ for (AccessControlEntry ace : acl.getEntries())
+ {
+ assigned.add(ace.getAuthority());
+ }
+
+ for (String authority : assigned)
+ {
+ UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.READ));
+ UnconditionalAclTest rmTest = new UnconditionalAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
+ if (test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
+ {
+ readers.add(authority);
+ }
+ }
+
+ return Collections.unmodifiableSet(readers);
+ }
+
+ /**
+ * @param aclId
+ * @return set of authorities with read permission on the ACL
+ */
+ protected Set buildReadersDenied(Long aclId)
+ {
+ HashSet assigned = new HashSet();
+ HashSet denied = new HashSet();
+ AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
+
+ if (acl == null)
+ {
+ return denied;
+ }
+
+ for (AccessControlEntry ace : acl.getEntries())
+ {
+ assigned.add(ace.getAuthority());
+ }
+
+ for(String authority : assigned)
+ {
+ UnconditionalDeniedAclTest test = new UnconditionalDeniedAclTest(getPermissionReference(PermissionService.READ));
+ UnconditionalDeniedAclTest rmTest = new UnconditionalDeniedAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
+ if(test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
+ {
+ denied.add(authority);
+ }
+ }
+
+ return denied;
+ }
+}
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/NewRecordsManagementSecurityServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/NewRecordsManagementSecurityServiceImplTest.java
deleted file mode 100644
index 938768a545..0000000000
--- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/NewRecordsManagementSecurityServiceImplTest.java
+++ /dev/null
@@ -1,151 +0,0 @@
-
-package org.alfresco.module.org_alfresco_module_rm.test.service;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
-import org.alfresco.service.cmr.repository.NodeRef;
-
-/**
- * Records management security service test.
- *
- * @author Roy Wetherall
- */
-public class NewRecordsManagementSecurityServiceImplTest extends BaseRMTestCase
-{
- private NodeRef record;
- private NodeRef recordToo;
-
- @Override
- protected boolean isUserTest()
- {
- return true;
- }
-
- @Override
- protected void setupTestDataImpl()
- {
- super.setupTestDataImpl();
-
- record = utils.createRecord(rmFolder, "record.txt");
- recordToo = utils.createRecord(rmFolder, "recordToo.txt");
- }
-
-
- // TODO testGetProtectedAspects
-
- // TODO getProtectedProperties
-
- // TODO bootstrapDefaultRoles
-
- // TODO getRoles
-
- // TODO getRolesByUser
-
- // TODO getRole
-
- // TODO existsRole
-
- // TODO hasRMAdminRole
-
- // TODO createRole
-
- // TODO updateRole
-
- // TODO deleteRole
-
- // TODO assignRoleToAuthority
-
- // TODO setPermission
-
- // TODO deletePermission
-
- public void testExtendedReaders()
- {
- doTestInTransaction(new Test()
- {
- public Void run()
- {
- assertFalse(hasExtendedReadersAspect(filePlan));
- assertFalse(hasExtendedReadersAspect(rmContainer));
- assertFalse(hasExtendedReadersAspect(rmFolder));
- assertFalse(hasExtendedReadersAspect(record));
-
- assertNull(securityService.getExtendedReaders(record));
-
- Set extendedReaders = new HashSet(2);
- extendedReaders.add("monkey");
- extendedReaders.add("elephant");
-
- securityService.setExtendedReaders(record, extendedReaders);
-
- Map testMap = new HashMap(2);
- testMap.put("monkey", Integer.valueOf(1));
- testMap.put("elephant", Integer.valueOf(1));
-
- test(filePlan, testMap);
- test(rmContainer, testMap);
- test(rmFolder, testMap);
- test(record, testMap);
-
- Set extendedReadersToo = new HashSet(2);
- extendedReadersToo.add("monkey");
- extendedReadersToo.add("snake");
-
- securityService.setExtendedReaders(recordToo, extendedReadersToo);
-
- Map testMapToo = new HashMap(2);
- testMapToo.put("monkey", Integer.valueOf(1));
- testMapToo.put("snake", Integer.valueOf(1));
-
- Map testMapThree = new HashMap(3);
- testMapThree.put("monkey", Integer.valueOf(2));
- testMapThree.put("elephant", Integer.valueOf(1));
- testMapThree.put("snake", Integer.valueOf(1));
-
- test(filePlan, testMapThree);
- test(rmContainer, testMapThree);
- test(rmFolder, testMapThree);
- test(recordToo, testMapToo);
-
- return null;
- }
-
- private boolean hasExtendedReadersAspect(NodeRef nodeRef)
- {
- return nodeService.hasAspect(nodeRef, ASPECT_EXTENDED_READERS);
- }
-
- private void test(NodeRef nodeRef, Map testMap)
- {
- assertTrue(hasExtendedReadersAspect(nodeRef));
-
- Map readersMap = (Map)nodeService.getProperty(nodeRef, PROP_READERS);
- assertNotNull(readersMap);
- assertEquals(testMap.size(), readersMap.size());
-
- for (Map.Entry entry: testMap.entrySet())
- {
- assertTrue(readersMap.containsKey(entry.getKey()));
- assertEquals(entry.getValue(), readersMap.get(entry.getKey()));
-
- }
-
- Set readers = securityService.getExtendedReaders(nodeRef);
- assertNotNull(readers);
- assertEquals(testMap.size(), readers.size());
- }
- });
- }
-
- // TODO getExtendedReaders
-
- // TODO setExtendedReaders
-
- // TODO removeExtendedReaders
-
- // TODO removeAllExtendedReaders
-}
diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSecurityServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSecurityServiceImplTest.java
index a1872523a8..1268d30d11 100644
--- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSecurityServiceImplTest.java
+++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementSecurityServiceImplTest.java
@@ -1,695 +1,152 @@
-/*
- * Copyright (C) 2005-2011 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.module.org_alfresco_module_rm.test.service;
-import java.io.Serializable;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.model.ContentModel;
-import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
-import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
-import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
-import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
-import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
-import org.alfresco.module.org_alfresco_module_rm.security.RecordsManagementSecurityService;
-import org.alfresco.module.org_alfresco_module_rm.security.Role;
-import org.alfresco.repo.security.authentication.AuthenticationUtil;
-import org.alfresco.repo.transaction.RetryingTransactionHelper;
-import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
-import org.alfresco.service.cmr.repository.ChildAssociationRef;
+import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.StoreRef;
-import org.alfresco.service.cmr.security.AccessPermission;
-import org.alfresco.service.cmr.security.AccessStatus;
-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.PermissionService;
-import org.alfresco.service.cmr.security.PersonService;
-import org.alfresco.service.namespace.NamespaceService;
-import org.alfresco.service.namespace.QName;
-import org.alfresco.util.BaseSpringTest;
-import org.alfresco.util.GUID;
-import org.alfresco.util.PropertyMap;
/**
- * Security service implementation unit test
+ * Records management security service test.
*
* @author Roy Wetherall
*/
-public class RecordsManagementSecurityServiceImplTest extends BaseSpringTest
- implements RecordsManagementModel
-{
- protected static StoreRef SPACES_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
+public class RecordsManagementSecurityServiceImplTest extends BaseRMTestCase
+{
+ private NodeRef record;
+ private NodeRef recordToo;
- private NodeService nodeService;
- private MutableAuthenticationService authenticationService;
- private AuthorityService authorityService;
- private PermissionService permissionService;
- private PersonService personService;
- private RecordsManagementSecurityService rmSecurityService;
- private RecordsManagementActionService rmActionService;
- private RetryingTransactionHelper transactionHelper;
- private CapabilityService capabilityService;
-
- @Override
- protected void onSetUpInTransaction() throws Exception
- {
- super.onSetUpInTransaction();
-
- // Get the service required in the tests
- this.nodeService = (NodeService)this.applicationContext.getBean("NodeService");
- this.authenticationService = (MutableAuthenticationService)this.applicationContext.getBean("AuthenticationService");
- this.personService = (PersonService)this.applicationContext.getBean("PersonService");
- this.authorityService = (AuthorityService)this.applicationContext.getBean("authorityService");
- this.rmSecurityService = (RecordsManagementSecurityService)this.applicationContext.getBean("RecordsManagementSecurityService");
- this.transactionHelper = (RetryingTransactionHelper)this.applicationContext.getBean("retryingTransactionHelper");
- this.permissionService = (PermissionService)this.applicationContext.getBean("PermissionService");
- this.rmActionService = (RecordsManagementActionService)this.applicationContext.getBean("RecordsManagementActionService");
- this.capabilityService = (CapabilityService)this.applicationContext.getBean("CapabilityService");
-
- // Set the current security context as admin
- AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
- }
-
- public void testRoles()
- {
- final NodeRef rmRootNode = createRMRootNodeRef();
-
- setComplete();
- endTransaction();
-
- transactionHelper.doInTransaction(new RetryingTransactionCallback