Cleanup of ACL reading/writing for PermissionsDaoComponent. All access is

through the AccessControlListDAO interface.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3700 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-09-06 00:41:41 +00:00
parent fff09ab01d
commit 920c487867
14 changed files with 298 additions and 196 deletions

View File

@@ -36,8 +36,8 @@ public class AVMCrawlTest extends AVMServiceTestBase
public void testCrawl()
{
int n = 2; // Number of Threads.
int m = 4; // How many multiples of content to start with.
long runTime = 1200000; // Ten minutes
int m = 2; // How many multiples of content to start with.
long runTime = 600000; // Ten minutes
fService.purgeAVMStore("main");
BulkLoader loader = new BulkLoader();
loader.setAvmService(fService);

View File

@@ -29,7 +29,6 @@ import java.util.Set;
import java.util.SortedMap;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.repo.node.AbstractNodeServiceImpl;
import org.alfresco.service.cmr.avm.AVMException;
@@ -1428,46 +1427,4 @@ public class AVMNodeService extends AbstractNodeServiceImpl implements NodeServi
{
throw new UnsupportedOperationException("AVM does not support this operation.");
}
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The list to set.
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = (Integer)avmVersionPath[0];
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", nodeRef);
}
try
{
fAVMService.setACL((String)avmVersionPath[1], acl);
}
catch (AVMNotFoundException e)
{
throw new InvalidNodeRefException("Not Found.", nodeRef);
}
}
/**
* Get the ACL on a node.
* @param nodeRef The reference to the node.
* @return The ACL.
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
try
{
return fAVMService.getACL((Integer)avmVersionPath[0],
(String)avmVersionPath[1]);
}
catch (AVMNotFoundException e)
{
throw new InvalidNodeRefException("Not Found.", nodeRef);
}
}
}

View File

@@ -891,33 +891,4 @@ public class AVMServiceImpl implements AVMService
}
return fAVMRepository.hasAspect(version, path, aspectName);
}
/**
* Set ACL on a node.
* @param path The path to the node.
* @param acl The ACL to set.
*/
public void setACL(String path, DbAccessControlList acl)
{
if (path == null)
{
throw new AVMBadArgumentException("Null path.");
}
fAVMRepository.setACL(path, acl);
}
/**
* Get the ACL on a node.
* @param version The version to look under.
* @param path The path to the node.
* @return The ACL.
*/
public DbAccessControlList getACL(int version, String path)
{
if (path == null)
{
throw new AVMBadArgumentException("Null path.");
}
return fAVMRepository.getACL(version, path);
}
}

View File

@@ -35,8 +35,8 @@ public class AVMStressTest extends AVMServiceTestBase
{
try
{
int nCopies = 4;
int nThreads = 8;
int nCopies = 2;
int nThreads = 2;
BulkLoader loader = new BulkLoader();
loader.setAvmService(fService);
long start = System.currentTimeMillis();

View File

@@ -32,7 +32,7 @@ public class SimultaneousLoadTest extends AVMServiceTestBase
{
try
{
int n = 8;
int n = 4;
int m = 1;
fReaper.setInactiveBaseSleep(60000);
for (int i = 0; i < n; i++)

View File

@@ -0,0 +1,44 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.domain;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* This abstracts the reading and writing of ACLs on nodes
* from particular node implementations.
* @author britt
*/
public interface AccessControlListDAO
{
/**
* Get the ACL from a node.
* @param nodeRef The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef);
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl);
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.domain.hibernate;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.avm.AVMRepository;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.service.cmr.avm.AVMException;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* The AVM implementation for getting and setting ACLs.
* @author britt
*/
public class AVMAccessControlListDAO implements AccessControlListDAO
{
/**
* Reference to the AVM Repository instance.
*/
private AVMRepository fAVMRepository;
/**
* Default constructory.
*/
public AVMAccessControlListDAO()
{
}
public void setAvmRepository(AVMRepository repository)
{
fAVMRepository = repository;
}
/**
* Get the ACL from a node.
* @param nodeRef The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = (Integer)avmVersionPath[0];
String path = (String)avmVersionPath[1];
try
{
return fAVMRepository.getACL(version, path);
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
int version = (Integer)avmVersionPath[1];
if (version >= 0)
{
throw new InvalidNodeRefException("Read Only Node.", nodeRef);
}
String path = (String)avmVersionPath[1];
try
{
fAVMRepository.setACL(path, acl);
}
catch (AVMException e)
{
throw new InvalidNodeRefException(nodeRef);
}
}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (C) 2006 Alfresco, Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at
*
* http://www.alfresco.org/legal/license.txt
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
package org.alfresco.repo.domain.hibernate;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.node.db.NodeDaoService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* The Node implementation for getting and setting ACLs.
* @author britt
*/
public class NodeAccessControlListDAO extends HibernateDaoSupport implements AccessControlListDAO
{
/**
* The DAO for Nodes.
*/
private NodeDaoService fNodeDAOService;
/**
* Default constructor.
*/
public NodeAccessControlListDAO()
{
}
public void setNodeDaoService(NodeDaoService nodeDAOService)
{
fNodeDAOService = nodeDAOService;
}
/**
* Get the ACL from a node.
* @param nodeRef The reference to the node.
* @return The ACL.
* @throws InvalidNodeRefException
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Node node = fNodeDAOService.getNode(nodeRef);
if (node == null)
{
throw new InvalidNodeRefException(nodeRef);
}
return node.getAccessControlList();
}
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The ACL.
* @throws InvalidNodeRefException
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Node node = fNodeDAOService.getNode(nodeRef);
if (node == null)
{
throw new InvalidNodeRefException(nodeRef);
}
DbAccessControlList oldAcl = node.getAccessControlList();
if (oldAcl != null)
{
node.setAccessControlList(null);
this.getHibernateTemplate().delete(oldAcl);
}
node.setAccessControlList(acl);
}
}

View File

@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.AccessControlListDAO;
import org.alfresco.repo.domain.DbAccessControlEntry;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.DbAuthority;
@@ -35,6 +36,7 @@ import org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry;
import org.alfresco.repo.security.permissions.impl.SimplePermissionEntry;
import org.alfresco.repo.security.permissions.impl.SimplePermissionReference;
import org.alfresco.repo.transaction.TransactionalDao;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AccessStatus;
@@ -60,9 +62,9 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
public static final String QUERY_GET_AC_ENTRIES_FOR_AUTHORITY = "permission.GetAccessControlEntriesForAuthority";
public static final String QUERY_GET_AC_ENTRIES_FOR_PERMISSION = "permission.GetAccessControlEntriesForPermission";
private Map<String, NodeService> protocolToNodeService;
private Map<String, AccessControlListDAO> fProtocolToACLDAO;
private NodeService defaultNodeService;
private AccessControlListDAO fDefaultACLDAO;
/** a uuid identifying this unique instance */
private String uuid;
@@ -128,14 +130,14 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
getSession().flush();
}
public void setProtocolToNodeService(Map<String, NodeService> map)
public void setProtocolToACLDAO(Map<String, AccessControlListDAO> map)
{
protocolToNodeService = map;
fProtocolToACLDAO = map;
}
public void setDefaultNodeService(NodeService defaultNodeService)
public void setDefaultACLDAO(AccessControlListDAO defaultACLDAO)
{
this.defaultNodeService = defaultNodeService;
fDefaultACLDAO = defaultACLDAO;
}
public NodePermissionEntry getPermissions(NodeRef nodeRef)
@@ -144,14 +146,16 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
// Null objects are not cached in hibernate
// If the object does not exist it will repeatedly query to check its
// non existence.
NodePermissionEntry npe = null;
DbAccessControlList acl = null;
if (nodeExists(nodeRef))
try
{
// get the persisted version
acl = getAccessControlList(nodeRef, false);
}
catch (InvalidNodeRefException e)
{
// Do nothing.
}
if (acl == null)
{
// there isn't an access control list for the node - spoof a null one
@@ -186,7 +190,7 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
private DbAccessControlList getAccessControlList(NodeRef nodeRef, boolean create)
{
DbAccessControlList acl =
getNodeService(nodeRef).getAccessControlList(nodeRef);
getACLDAO(nodeRef).getAccessControlList(nodeRef);
if (acl == null && create)
{
acl = createAccessControlList(nodeRef);
@@ -212,7 +216,7 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
getHibernateTemplate().save(acl);
// maintain inverse
getNodeService(nodeRef).setAccessControlList(nodeRef, acl);
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
// done
if (logger.isDebugEnabled())
@@ -226,15 +230,19 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
public void deletePermissions(NodeRef nodeRef)
{
if (!nodeExists(nodeRef))
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef, false);
}
catch (InvalidNodeRefException e)
{
return;
}
DbAccessControlList acl = getAccessControlList(nodeRef, false);
if (acl != null)
{
// maintain referencial integrity
getNodeService(nodeRef).setAccessControlList(nodeRef, null);
getACLDAO(nodeRef).setAccessControlList(nodeRef, null);
// delete the access control list - it will cascade to the entries
getHibernateTemplate().delete(acl);
}
@@ -264,12 +272,15 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
public void deletePermissions(final NodeRef nodeRef, final String authority)
{
if (!nodeExists(nodeRef))
DbAccessControlList acl = null;
try
{
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
DbAccessControlList acl =
getNodeService(nodeRef).getAccessControlList(nodeRef);
int deletedCount = 0;
if (acl != null)
{
@@ -291,12 +302,15 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
*/
public void deletePermission(NodeRef nodeRef, String authority, PermissionReference permission)
{
if (!nodeExists(nodeRef))
DbAccessControlList acl = null;
try
{
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
}
catch (InvalidNodeRefException e)
{
return;
}
DbAccessControlList acl =
getNodeService(nodeRef).getAccessControlList(nodeRef);
int deletedCount = 0;
if (acl != null)
{
@@ -431,7 +445,7 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
if (acl != null)
{
// maintain referencial integrity
getNodeService(nodeRef).setAccessControlList(nodeRef, null);
getACLDAO(nodeRef).setAccessControlList(nodeRef, null);
// drop the list
getHibernateTemplate().delete(acl);
}
@@ -477,12 +491,15 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
public boolean getInheritParentPermissions(NodeRef nodeRef)
{
if (!nodeExists(nodeRef))
DbAccessControlList acl = null;
try
{
acl = getAccessControlList(nodeRef, false);
}
catch (InvalidNodeRefException e)
{
return INHERIT_PERMISSIONS_DEFAULT;
}
DbAccessControlList acl = getAccessControlList(nodeRef, false);
if (acl == null)
{
return true;
@@ -499,7 +516,7 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
private SimpleNodePermissionEntry createSimpleNodePermissionEntry(NodeRef nodeRef)
{
DbAccessControlList acl =
getNodeService(nodeRef).getAccessControlList(nodeRef);
getACLDAO(nodeRef).getAccessControlList(nodeRef);
if (acl == null)
{
// there isn't an access control list for the node - spoof a null one
@@ -567,27 +584,17 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
perm.getName());
}
/**
* Helper to check node existence.
* @param nodeRef The node ref to check.
* @return Whether the node exists.
*/
private boolean nodeExists(NodeRef nodeRef)
{
return getNodeService(nodeRef).exists(nodeRef);
}
/**
* Helper to choose appropriate NodeService for the given NodeRef
* @param nodeRef The NodeRef to dispatch from.
* @return The appropriate NodeService.
*/
private NodeService getNodeService(NodeRef nodeRef)
private AccessControlListDAO getACLDAO(NodeRef nodeRef)
{
NodeService ret = protocolToNodeService.get(nodeRef.getStoreRef().getProtocol());
AccessControlListDAO ret = fProtocolToACLDAO.get(nodeRef.getStoreRef().getProtocol());
if (ret == null)
{
return defaultNodeService;
return fDefaultACLDAO;
}
return ret;
}

View File

@@ -33,7 +33,6 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.avm.AVMContext;
import org.alfresco.repo.domain.ChildAssoc;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.repo.domain.Node;
import org.alfresco.repo.domain.NodeAssoc;
import org.alfresco.repo.domain.NodeStatus;
@@ -1840,26 +1839,4 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
" name: " + useName);
}
}
/**
* Set the ACL on a node.
* @param nodeRef The reference to the node.
* @param acl The ACL to set.
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
Node node = getNodeNotNull(nodeRef);
node.setAccessControlList(acl);
}
/**
* Get the ACL on a node.
* @param nodeRef The reference to the node.
* @return The ACL.
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
Node node = getNodeNotNull(nodeRef);
return node.getAccessControlList();
}
}

View File

@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.domain.DbAccessControlList;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.InvalidAspectException;
import org.alfresco.service.cmr.repository.AssociationExistsException;
@@ -557,24 +556,4 @@ public class NodeServiceImpl implements NodeService, VersionModel
{
throw new UnsupportedOperationException(MSG_UNSUPPORTED);
}
/**
* Set the access control list on a node. Defer to DbNodeService.
* @param nodeRef The reference to the node.
* @param acl The list to set.
*/
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl)
{
dbNodeService.setAccessControlList(nodeRef, acl);
}
/**
* Get the access control list on a node. Defer to DbNodeService.
* @param nodeRef The reference to the node.
* @return The list.
*/
public DbAccessControlList getAccessControlList(NodeRef nodeRef)
{
return dbNodeService.getAccessControlList(nodeRef);
}
}

View File

@@ -588,19 +588,4 @@ public interface AVMService
* @return Whether the given node has the given aspect.
*/
public boolean hasAspect(int version, String path, QName aspectName);
/**
* Get the ACL on a given node.
* @param version The version to look under.
* @param path The path to the node.
* @return The ACL.
*/
public DbAccessControlList getACL(int version, String path);
/**
* Set the ACL on a given node.
* @param path The path to the node.
* @param acl The ACL to set.
*/
public void setACL(String path, DbAccessControlList acl);
}

View File

@@ -561,20 +561,4 @@ public interface NodeService
NodeRef destinationParentNodeRef,
QName assocTypeQName,
QName assocQName);
/**
* Get the access control list associated with a Node.
* @param nodeRef The reference to the Node.
* @return The access control list.
*/
@Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef"})
public DbAccessControlList getAccessControlList(NodeRef nodeRef);
/**
* Set the access control list on a node.
* @param nodeRef The node reference.
* @param acl The list to set.
*/
@Auditable(key = Auditable.Key.ARG_0, parameters = {"nodeRef", "acl"})
public void setAccessControlList(NodeRef nodeRef, DbAccessControlList acl);
}