From d405e72db885d0c6a6546f6cc4fca989aa6b424c Mon Sep 17 00:00:00 2001 From: Andrew Hind Date: Tue, 19 Aug 2008 14:49:48 +0000 Subject: [PATCH] Bug fix for inherited permissions COW git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10423 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/avm/AVMServicePermissionsTest.java | 57 +++++++++++++ .../repo/avm/AbstractSpringContextTest.java | 67 +++++++++++++++ .../repo/avm/WCMInheritPermissionsTest.java | 85 +++++++++++++++++++ .../AbstractPermissionsDaoComponentImpl.java | 1 + .../domain/hibernate/AclDaoComponentImpl.java | 4 +- 5 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 source/java/org/alfresco/repo/avm/AbstractSpringContextTest.java create mode 100644 source/java/org/alfresco/repo/avm/WCMInheritPermissionsTest.java diff --git a/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java b/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java index ae0471da66..a259f7eedb 100644 --- a/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServicePermissionsTest.java @@ -35,6 +35,7 @@ import javax.transaction.UserTransaction; import junit.framework.TestCase; +import org.alfresco.config.JNDIConstants; import org.alfresco.model.ContentModel; import org.alfresco.repo.domain.AccessControlListDAO; import org.alfresco.repo.domain.DbAccessControlList; @@ -3835,4 +3836,60 @@ public class AVMServicePermissionsTest extends TestCase } return builder.toString(); } + + + private static final String FILE_NAME = "fileForExport"; + private static final String STORE_NAME = "TestStore1"; + private static final String ROOT = "ROOT"; + + private void createStaggingWithSnapshots(String storeName) + { + if (avmService.getStore(storeName) != null) + { + avmService.purgeStore(storeName); + } + + avmService.createStore(storeName); + assertNotNull(avmService.getStore(storeName)); + + avmService.createDirectory(storeName + ":/", JNDIConstants.DIR_DEFAULT_WWW); + avmService.createSnapshot(storeName, "first", "first"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW)); + avmService.createDirectory(storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW, JNDIConstants.DIR_DEFAULT_APPBASE); + avmService.createSnapshot(storeName, "second", "second"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE)); + avmService.createDirectory(storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE, ROOT); + avmService.createSnapshot(storeName, "third", "third"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT)); + avmService.createFile(storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT, FILE_NAME); + avmService.createSnapshot(storeName, "fourth", "fourth"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT + "/" + FILE_NAME)); + + } + + private void removeStore(String storeName) + { + avmService.purgeStore(storeName); + assertNull(avmService.getStore(storeName)); + } + + public void testSetInheritParentPermissions() + { + createStaggingWithSnapshots(STORE_NAME); + + AVMNodeDescriptor nodeDescriptor = avmService.lookup(-1, STORE_NAME + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT + "/" + + FILE_NAME); + assertNotNull(nodeDescriptor); + NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, nodeDescriptor.getPath()); + assertNotNull(nodeRef); + + permissionService.setInheritParentPermissions(nodeRef, false); + assertFalse(permissionService.getInheritParentPermissions(nodeRef)); + permissionService.setInheritParentPermissions(nodeRef, true); + assertTrue(permissionService.getInheritParentPermissions(nodeRef)); + + removeStore(STORE_NAME); + } + + } diff --git a/source/java/org/alfresco/repo/avm/AbstractSpringContextTest.java b/source/java/org/alfresco/repo/avm/AbstractSpringContextTest.java new file mode 100644 index 0000000000..640f5654f7 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/AbstractSpringContextTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.avm; + +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.security.AuthenticationService; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.util.ApplicationContextHelper; +import org.springframework.test.AbstractDependencyInjectionSpringContextTests; + +public abstract class AbstractSpringContextTest extends AbstractDependencyInjectionSpringContextTests +{ + protected AVMService avmService; + protected AuthenticationService authenticationService; + protected ServiceRegistry servReg; + protected PermissionService permissionService; + + @Override + protected void onSetUp() throws Exception + { + super.onSetUp(); + servReg = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY); + avmService = servReg.getAVMService(); + assertNotNull(avmService); + authenticationService = servReg.getAuthenticationService(); + assertNotNull(authenticationService); + permissionService = servReg.getPermissionService(); + assertNotNull(permissionService); + + authenticationService.authenticate("admin", "admin".toCharArray()); + } + + @Override + protected void onTearDown() throws Exception + { + super.onTearDown(); + } + + @Override + protected String[] getConfigLocations() + { + return ApplicationContextHelper.CONFIG_LOCATIONS; + } +} diff --git a/source/java/org/alfresco/repo/avm/WCMInheritPermissionsTest.java b/source/java/org/alfresco/repo/avm/WCMInheritPermissionsTest.java new file mode 100644 index 0000000000..85f5d7861a --- /dev/null +++ b/source/java/org/alfresco/repo/avm/WCMInheritPermissionsTest.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.avm; + +import org.alfresco.config.JNDIConstants; +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; +import org.alfresco.service.cmr.repository.NodeRef; + +public class WCMInheritPermissionsTest extends AbstractSpringContextTest +{ + private static final String FILE_NAME = "fileForExport"; + private static final String STORE_NAME = "TestStore1"; + private static final String ROOT = "ROOT"; + + private void createStaggingWithSnapshots(String storeName) + { + if (avmService.getStore(storeName) != null) + { + avmService.purgeStore(storeName); + } + + avmService.createStore(storeName); + assertNotNull(avmService.getStore(storeName)); + + avmService.createDirectory(storeName + ":/", JNDIConstants.DIR_DEFAULT_WWW); + avmService.createSnapshot(storeName, "first", "first"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW)); + avmService.createDirectory(storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW, JNDIConstants.DIR_DEFAULT_APPBASE); + avmService.createSnapshot(storeName, "second", "second"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE)); + avmService.createDirectory(storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE, ROOT); + avmService.createSnapshot(storeName, "third", "third"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT)); + avmService.createFile(storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT, FILE_NAME); + avmService.createSnapshot(storeName, "fourth", "fourth"); + assertNotNull(avmService.lookup(-1, storeName + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT + "/" + FILE_NAME)); + + } + + private void removeStore(String storeName) + { + avmService.purgeStore(storeName); + assertNull(avmService.getStore(storeName)); + } + + public void testSetInheritParentPermissions() + { + createStaggingWithSnapshots(STORE_NAME); + + AVMNodeDescriptor nodeDescriptor = avmService.lookup(-1, STORE_NAME + ":/" + JNDIConstants.DIR_DEFAULT_WWW + "/" + JNDIConstants.DIR_DEFAULT_APPBASE + "/" + ROOT + "/" + + FILE_NAME); + assertNotNull(nodeDescriptor); + NodeRef nodeRef = AVMNodeConverter.ToNodeRef(-1, nodeDescriptor.getPath()); + assertNotNull(nodeRef); + + permissionService.setInheritParentPermissions(nodeRef, false); + assertFalse(permissionService.getInheritParentPermissions(nodeRef)); + permissionService.setInheritParentPermissions(nodeRef, true); + assertTrue(permissionService.getInheritParentPermissions(nodeRef)); + + removeStore(STORE_NAME); + } +} diff --git a/source/java/org/alfresco/repo/domain/hibernate/AbstractPermissionsDaoComponentImpl.java b/source/java/org/alfresco/repo/domain/hibernate/AbstractPermissionsDaoComponentImpl.java index 1868d1ba63..68713aa4d5 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/AbstractPermissionsDaoComponentImpl.java +++ b/source/java/org/alfresco/repo/domain/hibernate/AbstractPermissionsDaoComponentImpl.java @@ -516,6 +516,7 @@ public abstract class AbstractPermissionsDaoComponentImpl implements Permissions else { // TODO: Find inheritance + // ATM this should wire up any previous inheritance that existed changes = aclDaoComponent.enableInheritance(report.getCreated().getId(), null); } List all = new ArrayList(changes.size() + report.getChanges().size()); diff --git a/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java b/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java index fd1a2ecb40..7f9a5a839b 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java +++ b/source/java/org/alfresco/repo/domain/hibernate/AclDaoComponentImpl.java @@ -1489,7 +1489,9 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo getWritable(id, null, null, null, null, false, changes, WriteMode.COPY_ONLY); } - return mergeInheritedAccessControlList(parent, changes.get(0).getAfter()); + List merged = mergeInheritedAccessControlList(parent, changes.get(0).getAfter()); + changes.addAll(merged); + return changes; } }