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
This commit is contained in:
Andrew Hind
2008-08-19 14:49:48 +00:00
parent dcc9ac128c
commit d405e72db8
5 changed files with 213 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ import javax.transaction.UserTransaction;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.alfresco.config.JNDIConstants;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.AccessControlListDAO; import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlList; import org.alfresco.repo.domain.DbAccessControlList;
@@ -3835,4 +3836,60 @@ public class AVMServicePermissionsTest extends TestCase
} }
return builder.toString(); 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);
}
} }

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -516,6 +516,7 @@ public abstract class AbstractPermissionsDaoComponentImpl implements Permissions
else else
{ {
// TODO: Find inheritance // TODO: Find inheritance
// ATM this should wire up any previous inheritance that existed
changes = aclDaoComponent.enableInheritance(report.getCreated().getId(), null); changes = aclDaoComponent.enableInheritance(report.getCreated().getId(), null);
} }
List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size()); List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size());

View File

@@ -1489,7 +1489,9 @@ public class AclDaoComponentImpl extends HibernateDaoSupport implements AclDaoCo
getWritable(id, null, null, null, null, false, changes, WriteMode.COPY_ONLY); getWritable(id, null, null, null, null, false, changes, WriteMode.COPY_ONLY);
} }
return mergeInheritedAccessControlList(parent, changes.get(0).getAfter()); List<AclChange> merged = mergeInheritedAccessControlList(parent, changes.get(0).getAfter());
changes.addAll(merged);
return changes;
} }
} }