Files
alfresco-community-repo/source/java/org/alfresco/repo/domain/permissions/AbstractAclCrudDAOImpl.java
Derek Hulley 4872eb9909 Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-5 to HEAD:
20678: DAO5 branch: Preparation for merge back to HEAD
   20689: Merged DAO4 to DAO5
        - Removed all 'dbscripts/create/3.x/SomeDialect' and replaced with 'dbscripts/create/SomeDialect'
          DB create scripts are taken from latest DAO4
        - TODO: FixAuthoritiesCrcValuesPatch needs query implementation in PatchDAO
        Merged DAO3 to DAO4
           - Reapplied fixes for ALF-713 (race condition on Usages)
           19350: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-2 to BRANCHES/DEV/V3.3-DAO-REFACTOR-3:
               18939: SAIL-4 :2nd stage branch for DAO refactor off HEAD rev 18898
               18948: Merged V3.3-DAO-REFACTOR to V3.3-DAO-REFACTOR-2
                    18202: Dev branch for DAO refactor
                    18252: SAIL-233: QName.hbm.xml
                    18295: Added missing CREATE TABLE statements for QName-related code
                    18324: SAIL-234: Node.hbm.xml: Node aspects initial integration
                    18355: Added 'setValue' method to manually update the cached value
                    18356: MV property stressing lowered to speed test up
                    18357: SAIL-234: Node.hbm.xml
                    18376: Pulled all Alfresco-related create SQL into script
                    18389: SAIL-234: Permissions DAO refactor - initial checkpoint
                    18390: Formatting only (line-endings)
                    18400: SAIL-234: Node.hbm.xml
                    18418: SAIL-234: Node.hbm.xml: 'alf_node_assoc' CRUD
                    18429: SAIL-234: Node.hbm.xml: Cleaned out all Hibernate references to NodeAssocImpl
                    18457: SAIL-234: Permissions DAO refactor
               18959: Merged DEV/V3.3-DAO-REFACTOR to DEV/V3.3-DAO-REFACTOR-2
                    18479: SAIL-234: Node.hbm.xml - fix updateNode (missing id when saving oldDummyNode)
                    18482: SAIL-235: remove Permissions.hbm.xml
                    18517: SAIL-235: Permissions DAO refactor
                    18523: SAIL-234: Node.hbm.xml
                    18524: SAIL-235: Permissions DAO refactor
               18960: Merged DEV/V3.3-DAO-REFACTOR to DEV/V3.3-DAO-REFACTOR-2
                    18533: Flipped back to Windows line endings
                    18535: Formatting-only (eol)
                    18540: Formatting-only (eol)
                    18541: SAIL-235: Permissions DAO refactor
                    18543: SAIL-234: Node.hbm.xml: Start alf_store changes
                    18567: SAIL-235: Permissions DAO refactor
                    18596: SAIL-305:  Alfresco DDL - formatted/rationalized and added missing indexes & fk constraints
                    18603: SAIL-311: Minor cleanup for schema upgrade scripts (V3.3)
                    18604: SAIL-311: Remove empty dirs
                    18619: SAIL-274: Locale.hbm.xml
                    18621: Added method to create default ACL
                    18622: SAIL-234: Node.hbm.xml: Store, Transaction, Server and some node
                    18624: Formatting only (eol)
                    18631: SAIL-235: Permissions DAO refactor
                    18633: SAIL-235: Permissions DAO refactor - do not expose CRUD for AceContext (or AuthorityAlias) since currently unused
                    18639: getLocale(Locale) should return null if it doesn't exist
                    18640: SAIL-234 NodeDAO: More replacement of node queries and updates
                    18648: SAIL-310: Create SQL script for core repo tables (All DB ports)
                    18651: SAIL-234 NodeDAO: Moves across stores handle presence of target deleted nodes
               18961: Merged DEV/V3.3-DAO-REFACTOR to DEV/V3.3-DAO-REFACTOR-2
                    18658: SAIL-274 Locale DAO: Missing getValueKey() method
                    18662: SAIL-235: Permissions DAO refactor - further cleanup (of DbAccessControlList usage, including copyACLs)
                    18664: DB scripts porting for PostgreSQL finished.
                    18668: SAIL-234 Node DAO: Note in case Transaction Change ID is dropped from indexes
                    18669: SAIL-234 Node DAO: deleteNode and archive (store move) fixes
                    18672: DB scripts porting for Oracle finished. 
                    18675: SAIL-235: Permissions DAO refactor 
                    18677: DB scripts porting for DB2 finished.
               18964: Merged DEV/V3.3-DAO-REFACTOR to DEV/V3.3-DAO-REFACTOR-2
                    18687: Execute a callback with retries
                    18688: SAIL-234 Node DAO: Child association creation
                    18690: SAIL-234 Node DAO: Comment out raw creation of stores as it breaks subsequent bootstrap checks
                    18691: SAIL-234 Node DAO: More replacement of alf_child_assoc handling
                    18713: Commented about needing a more efficient removeChildAssociation method
                    18714: SAIL-234 Node DAO: Replaced queries on alf_child_assoc
                    18715: SAIL-234 Node DAO: More alf_child_assoc query replacement
                    18727: SAIL-234 Node DAO: alf_child_assoc queries complete
                    18737: SAIL-234 Node DAO: Tweaks to newNode and implemented prependPaths
                    18741: SAIL-234 and SAIL-334: Moved UsageDelta Hibernate code and queries over to UsageDeltaDAO
                    18748: SAIL-234 Node DAO: fix NPE (EditionServiceImplTest)
                    18769: SAIL-234 Node DAO: alf_node_properties ground work
                    18786: SAIL-234 Node DAO: alf_node_properties and cm:auditable properties
                    18810: Added EqualsHelper.getMapComparison
                    18813: TransactionalCache propagates cache clears and removals during rollback
                    18826: SAIL-234 Node DAO: Moved over sundry references to NodeDaoService to NodeDAO
                    18849: SAIL-237: UsageDelta.hbm.xml - eol formatting only (including removal of unwanted svn:eol-style=native property)
                    18869: SAIL-234 NodeDAO: Fixed more references to 'nodeDaoService'
                    18895: SAIL-234 NodeDAO: Queries for alf_transaction
                    18899: SAIL-234 Node DAO: Fixed bean fetching for 'nodeDAO'
                    18909: SAIL-234 NodeDAO: Fixes to getNodeRefStatus and various txn queries
                    18916: SAIL-234 NodeDAO: Fixed moveNode alf_child_assoc updates
                    18922: SAIL-235: DAO refactoring: Permission.hbm.xml
                    18930: SAIL-235: DAO refactoring: Permission.hbm.xml
                    18932: SAIL-234 NodeDAO: Fixing up gotchas, javadocs and some naming
                    18933: SAIL-234 NodeDAO: Minor neatening
                    18935: SAIL-234 Node DAO: Caches for ID to NodeRef and StoreRef
                    18936: EHCache config files line endings
                    18938: SAIL-237: Usage DAO refactor - initial checkpoint
                    18945: SAIL-235: DAO refactoring: Permission.hbm.xml. Move Node.
               18975: Fix for move-node ACL jiggery-pokery
               19067: SAIL-4: fix VersionHistoryImpl.getSuccessors (causing VersionServiceImplTest.testGetVersionHistorySameWorkspace failure)
               19068: SAIL-234: fix VersionMigratorTest.testMigrateOneVersion
               19074: SAIL-237: Usage DAO - update to common iBatis mapping pattern(s) to ease DB porting
               19076: SAIL-231: Activities DAO - update to common iBatis mapping pattern(s)
               19077: SAIL-232: AppliedPatch DAO - minor cleanup (comments & formatting only)
               19092: Merging HEAD to DEV/V3.3-DAO-REFACTOR-2
                     18973: Temporarily comment out AVMTestSuite and run AVM tests individually
                     19056: AVM unit test improvements
               19097: SAIL-235: DAO refactoring: Permission.hbm.xml: Additional index to support queries to find the id and acl id for the primary children of a node.
               19185: SAIL-238: Permissions DAO - (minor) update to common iBatis mapping pattern
               19289: SAIL-234 NodeDAO: Node cache replaces NodeRef cache
               19302: SAIL-234 Node DAO: Added cache for node properties
               19318: SAIL-4: AVM DAO - (minor) update to common iBatis mapping pattern
   20690: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-4 to BRANCHES/DEV/V3.3-DAO-REFACTOR-5:
        20063: (RECORD ONLY) DAO refactor branch V4
        20146: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-3 to BRANCHES/DEV/V3.3-DAO-REFACTOR-4:
             19401: SAIL-234 Node DAO: Fix permission service tests (setPrimaryChildrenSharedAclId needs to invalidate nodesCache)
             19428: Fixed TransactionalCache issue with null and NullValueMarker
             19429: Took empty cm:content creation out of FileFolderService#createImpl
             19430: SAIL-234 Node DAO: Tweaks around caching and cm:auditable
             19431: SAIL-4 DAO Refactor: Exception thrown when attempting writes in read-only txn have changed
             19436: SAIL-234 Node DAO: Fix NPE during cm:auditable update
             19475: Allow debugging of code without stepping into trivial stuff
             19476: Follow-up on 19429 by ensuring CIFS/FTP set a  mimetype on the ContentWriter
             19477: SAIL-234 Node DAO: Leverage DAO better for NodeService.addProperties
             19478: SAIL-234 NodeDAO: Added toString() for ParentAssocsInfo (cache value for parent assocs)
             19479: SAIL-234 Node DAO: Fixed for parent association and property caches
             19480: Made TransactionAwareSingleton bind-key a GUID
             19481: SAIL-234 Node DAO: Reinstated 100K collection property tests
             19482: SAIL-234 Node DAO: Node and property cache fixes highlighted by unit tests
             19483: SAIL-234 Node DAO: Start on NodeBulkLoader implementation
             19595: SAIL-234 Node DAO: Fix moveNode to detect cyclic relationship prior to updating ACLs for moved tree FileFolderServiceImplTest.testETHREEOH_3088_MoveIntoSelf)
        20147: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-3 to BRANCHES/DEV/V3.3-DAO-REFACTOR-4:
             19602: (RECORD ONLY) Reintegrated with HEAD up to rev 19433
             19621: (RECORD ONLY) SAIL-347
             19683: (RECORD ONLY) Reverse-merged 19621 for SAIL-347
             19722: (RECORD ONLY) Merged /alfresco/HEAD:r19434-19721
        20150: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-3 to BRANCHES/DEV/V3.3-DAO-REFACTOR-4:
             19741: Merged DEV\V3.3-DAO-REFACTOR-2 to DEV\V3.3-DAO-REFACTOR-3
                   19739: Extended "move" tests
             19743: Fix AuditableAspectTest.testAddAspect (to allow for node modified date tolerance)
             19748: Remaining part of merge from HEAD to V3.3-DAO-REFACTOR-3
                   19367: Merged BRANCHES/V3.2 to HEAD:
                       19286: Fix for ALF-626 "Using 'null' as an authority argument in clearPermissions() cause a java.lang.NullPointerException"
             19755: SAIL-234 Node DAO: Fix RepoAdminServiceImplTest.testConcurrentDynamicModelDelete (handle InvalidNodeRefException after getChildAssocs)
   20692: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-4 to BRANCHES/DEV/V3.3-DAO-REFACTOR-5:
        - Retired all 1.3 and 1.4 upgrade scripts ... R.I.P.
        - Fixed CRC patch for Authorities (only tested on MySQL)
        - Fixed SQL patch revision numbers and bumped version schema number up
        20158: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-3 to BRANCHES/DEV/V3.3-DAO-REFACTOR-4:
             19773: SQL mappings and scripts: SAIL-310, SAIL-304, SAIL-303 and SAIL-347
             19774: Futher fix for SAIL-310: Sequence patch must take into account sequences created for 3.3
             19851: SAIL-371 (SAIL-294) NodeDAO fallout: Fix QName and Namespace read/write handling and bean name in unit test
        20183: Merged DAO3 to DAO4
             19852: SAIL-370: Remove LinkValidation
             19853: SAIL-239 (SAIL-294) Attributes.hbm.xml: Added ability to attach arbitrary property to unique context
             19857: SAIL-373 Fallout from Permissions DAO refactor (SAIL-235)
             19864: SAIL-239 (SAIL-294): Removed AttributeService RMI API
             19865: More SAIL-239 (SAIL-294): Removed AttributeService RMI API
        20208: DAO-refactor implementation of ALF-2712 query improvements
        20209: Merged BRANCHES/DEV/V3.3-DAO-REFACTOR-3 to BRANCHES/DEV/V3.3-DAO-REFACTOR-4:
             20060: Removal of AttributeService for SAIL-239 (SAIL-294)
        20348: SAIL-371 (SAIL-294): Protect collection properties during map insert and retrieval
        20547: SAIL-371 (SAIL-294) Attributes.hbm.xml: implement getAttributes + fixes
        20573: SAIL-371 (SAIL-294): NodeDAO: Fix unit tests and other fallout
        20597: SAIL-239 Attributes.hbm.xml: WCM/AVM locking test fixes (wip)
        20598: SAIL-239 Attributes.hbm.xml: WCM/AVM locking test fixes (wip) - fix AssetServiceImplTest.testSimpleLockFile NPE
        20600: Fix PropertyValueDAOTest.testPropertyValue_Enum (follow-on to r20060 for SAIL-239 - which introduces ENUM prop vals)
        20601: Fix UsageDAOTest.testCreateAndDeleteUsageDeltas NPE (would also affect ContentStoreCleanerScalabilityRunner)
        20603: Fix CMISPropertyServiceTest.* (fallout from r20146 <- r19429 <- Took empty cm:content creation out of FileFolderService#createImpl)
        20604: SAIL-371 (SAIL-294): NodeDAO: Fix unit tests - TransferServiceImplTest.*
        20618: SAIL-371 (SAIL-294): NodeDAO: AuditableAspectTest (fix testCreateNodeWithAuditableProperties_ALF_2565 + add remove aspect test)
        20624: SAIL-371 (SAIL-294): NodeDAO: Fix unit tests - UserUsageTest.*
        20626: Fixed random keys for RuleTrigger NodeRef tracking
        20635: SAIL-371 (SAIL-294): NodeDAO: Fix unit tests - PersonTest.testSplitDuplicates
        20642: SAIL-371 (SAIL-294) DAO: Fixed CacheTest
        20643: Removed must of the 'distribute' target's dependencies.  Not for HEAD
        20645: Follow-on to r20643 (Removed most of the 'distribute' target's dependencies.  Not for HEAD)
        20654: SAIL-371 (SAIL-294): NodeDAO: DMDeploymentTargetTest.* (do not try to remove mandatory aspects)
        20655: SAIL-371 (SAIL-294): NodeDAO: Initial fix for TaggingServiceImplTest.testTagScopeUpdateViaNodePolicies (+ minor test cleanup)
        20657: SAIL-371 (SAIL-294): NodeDAO: Fix unit tests - VersionMigratorTest.testMigrateOneVersion (cm:accessed not returned if null)
        20658: Merged (back merge only - no merge info) BRANCHES/V3.3 to BRANCHES/DEV/V3.3-DAO-REFACTOR-4:
             20090: Dynamic models: minor improvements to DictionaryModelType
             20554: Improvement to model delete validation (investigating intermittent failure of RepoAdminServiceImplTest.testSimpleDynamicModelViaNodeService)
        20662: SAIL-371 (SAIL-294): NodeDAO: Fix unit tests - RecordsManagementAuditServiceImplTest.* (we now ignore attempt to update 'cm:modifier' prop so update 'cm:title' prop instead)
        20666: SAIL-371 (SAIL-294): NodeDAO: Fix unit tests - ADMLuceneTest.*
        20668: SAIL-239 (SAIL-294) - delete WCM locks + tests (follow-on to r20060)
        20674: SAIL-371 (SAIL-294) NodeDAO fallout: Cleaner and additional checks for ContentStoreCleaner
        20675: SAIL-371 (SAIL-294) NodeDAO fallout: Fixed handling of ContentData


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20693 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2010-06-17 19:35:49 +00:00

1009 lines
35 KiB
Java

/*
* Copyright (C) 2005-2010 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.domain.permissions;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.cache.lookup.EntityLookupCache;
import org.alfresco.repo.cache.lookup.EntityLookupCache.EntityLookupCallbackDAO;
import org.alfresco.repo.domain.CrcHelper;
import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.repo.security.permissions.ACEType;
import org.alfresco.repo.security.permissions.PermissionReference;
import org.alfresco.repo.security.permissions.impl.SimplePermissionReference;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* Abstract implementation for ACL crud DAO.
* <p>
* This provides basic services such as caching, but defers to the underlying implementation
* for CRUD operations for:
*
* <b>alf_access_control_list</b>
* <b>alf_acl_member</b>
* <b>alf_acl_change_set</b>
* <b>alf_access_control_entry</b>
* <b>alf_permission</b>
* <b>alf_authority</b>
*
* Also, following are currently unused:
*
* <b>alf_ace_context</b>
* <b>alf_authority_alias</b>
*
*
*
* @author janv
* @since 3.4
*/
public abstract class AbstractAclCrudDAOImpl implements AclCrudDAO
{
private static final String CACHE_REGION_ACL = "Acl";
private static final String CACHE_REGION_AUTHORITY = "Authority";
private static final String CACHE_REGION_PERMISSION = "Permission";
private final AclEntityCallbackDAO aclEntityDaoCallback;
private final AuthorityEntityCallbackDAO authorityEntityDaoCallback;
private final PermissionEntityCallbackDAO permissionEntityDaoCallback;
private QNameDAO qnameDAO;
private static int batchSize = 500;
public void setQnameDAO(QNameDAO qnameDAO)
{
this.qnameDAO = qnameDAO;
}
public void setBatchSize(int batchSizeOverride)
{
batchSize = batchSizeOverride;
}
/**
* Cache for the ACL entity:<br/>
* KEY: ID (ACL)<br/>
* VALUE: AclEntity<br/>
* VALUE KEY: None<br/>
*/
private EntityLookupCache<Long, AclEntity, Serializable> aclCache;
/**
* Cache for the Authority entity:<br/>
* KEY: ID (Authority)<br/>
* VALUE: AuthorityEntity<br/>
* VALUE KEY: Name<br/>
*/
private EntityLookupCache<Long, AuthorityEntity, String> authorityCache;
/**
* Cache for the Permission entity:<br/>
* KEY: ID (Permission)<br/>
* VALUE: PermissionEntity<br/>
* VALUE KEY: PermissionEntity (compound key: qnameId + name)<br/>
*/
private EntityLookupCache<Long, PermissionEntity, PermissionEntity> permissionCache;
/**
* Set the cache to use for <b>alf_access_control_list</b> lookups (optional).
*
* @param aclCache the cache of IDs to AclEntities
*/
public void setAclCache(SimpleCache<Serializable, Object> aclCache)
{
this.aclCache = new EntityLookupCache<Long, AclEntity, Serializable>(
aclCache,
CACHE_REGION_ACL,
aclEntityDaoCallback);
}
/**
* Set the cache to use for <b>alf_authority</b> lookups (optional).
*
* @param authorityCache the cache of IDs to AclEntities
*/
public void setAuthorityCache(SimpleCache<Serializable, Object> authorityCache)
{
this.authorityCache = new EntityLookupCache<Long, AuthorityEntity, String>(
authorityCache,
CACHE_REGION_AUTHORITY,
authorityEntityDaoCallback);
}
/**
* Set the cache to use for <b>alf_permission</b> lookups (optional).
*
* @param permissionCache the cache of IDs to PermissionEntities
*/
public void setPermissionCache(SimpleCache<Serializable, Object> permissionCache)
{
this.permissionCache = new EntityLookupCache<Long, PermissionEntity, PermissionEntity>(
permissionCache,
CACHE_REGION_PERMISSION,
permissionEntityDaoCallback);
}
/**
* Default constructor.
* <p>
* This sets up the DAO accessors to bypass any caching to handle the case where the caches are not
* supplied in the setters.
*/
public AbstractAclCrudDAOImpl()
{
this.aclEntityDaoCallback = new AclEntityCallbackDAO();
this.aclCache = new EntityLookupCache<Long, AclEntity, Serializable>(aclEntityDaoCallback);
this.authorityEntityDaoCallback = new AuthorityEntityCallbackDAO();
this.authorityCache = new EntityLookupCache<Long, AuthorityEntity, String>(authorityEntityDaoCallback);
this.permissionEntityDaoCallback = new PermissionEntityCallbackDAO();
this.permissionCache = new EntityLookupCache<Long, PermissionEntity, PermissionEntity>(permissionEntityDaoCallback);
}
//
// Access Control List (ACL)
//
public AclEntity createAcl(AclEntity entity)
{
ParameterCheck.mandatory("entity", entity);
ParameterCheck.mandatory("entity.aclId", entity.getAclId());
ParameterCheck.mandatory("entity.aclVersion", entity.getAclVersion());
entity.setVersion(0L);
Pair<Long, AclEntity> entityPair = aclCache.getOrCreateByValue(entity);
return entityPair.getSecond();
}
public Acl getAcl(long id)
{
return getAclImpl(id);
}
private AclEntity getAclImpl(long id)
{
Pair<Long, AclEntity> entityPair = aclCache.getByKey(id);
if (entityPair == null)
{
return null;
}
return entityPair.getSecond();
}
public AclEntity getAclForUpdate(long id)
{
AclEntity acl = getAclImpl(id);
if (acl == null)
{
return null;
}
// copy for update
AclEntity aclEntity = new AclEntity();
aclEntity.setId(acl.getId());
aclEntity.setVersion(acl.getVersion());
aclEntity.setAclChangeSetId(acl.getAclChangeSetId());
aclEntity.setAclId(acl.getAclId());
aclEntity.setAclType(acl.getAclType());
aclEntity.setAclVersion(acl.getAclVersion());
aclEntity.setInheritedAcl(acl.getInheritedAcl());
aclEntity.setInherits(acl.getInherits());
aclEntity.setInheritsFrom(acl.getInheritsFrom());
aclEntity.setLatest(acl.isLatest());
aclEntity.setVersioned(acl.isVersioned());
aclEntity.setRequiresVersion(acl.getRequiresVersion());
return aclEntity;
}
public List<Long> getAclsThatInheritFromAcl(long aclEntityId)
{
// not cached
return getAclEntitiesThatInheritFromAcl(aclEntityId);
}
public Long getLatestAclByGuid(String aclGuid)
{
// not cached
return getLatestAclEntityByGuid(aclGuid);
}
public List<Long> getADMNodesByAcl(long aclEntityId, int maxResults)
{
return getADMNodeEntityIdsByAcl(aclEntityId, maxResults);
}
public List<Long> getAVMNodesByAcl(long aclEntityId, int maxResults)
{
return getAVMNodeEntityIdsByAcl(aclEntityId, maxResults);
}
public void updateAcl(AclEntity entity)
{
ParameterCheck.mandatory("entity", entity);
ParameterCheck.mandatory("entity.id", entity.getId());
ParameterCheck.mandatory("entity.aclVersion", entity.getAclVersion());
ParameterCheck.mandatory("entity.version", entity.getVersion());
int updated = aclCache.updateValue(entity.getId(), entity);
if (updated < 1)
{
throw new ConcurrencyFailureException("AclEntity with ID (" + entity.getId() + ") no longer exists or has been updated concurrently");
}
}
public void deleteAcl(long id)
{
Pair<Long, AclEntity> entityPair = aclCache.getByKey(id);
if (entityPair == null)
{
return;
}
int deleted = aclCache.deleteByKey(id);
if (deleted < 1)
{
throw new ConcurrencyFailureException("AclEntity with ID " + id + " no longer exists");
}
}
/**
* Callback for <b>alf_access_control_list</b> DAO
*/
private class AclEntityCallbackDAO implements EntityLookupCallbackDAO<Long, AclEntity, Serializable>
{
private final Pair<Long, AclEntity> convertEntityToPair(AclEntity entity)
{
if (entity == null)
{
return null;
}
else
{
return new Pair<Long, AclEntity>(entity.getId(), entity);
}
}
public Serializable getValueKey(AclEntity value)
{
return null;
}
public Pair<Long, AclEntity> createValue(AclEntity value)
{
AclEntity entity = createAclEntity(value);
return convertEntityToPair(entity);
}
public Pair<Long, AclEntity> findByKey(Long key)
{
AclEntity entity = getAclEntity(key);
return convertEntityToPair(entity);
}
public Pair<Long, AclEntity> findByValue(AclEntity value)
{
if ((value != null) && (value.getId() != null))
{
return findByKey(value.getId());
}
return null;
}
public int updateValue(Long key, AclEntity value)
{
return updateAclEntity(value);
}
public int deleteByKey(Long key)
{
return deleteAclEntity(key);
}
public int deleteByValue(AclEntity value)
{
throw new UnsupportedOperationException("deleteByValue");
}
}
protected abstract AclEntity createAclEntity(AclEntity entity);
protected abstract AclEntity getAclEntity(long id);
protected abstract List<Long> getAclEntitiesThatInheritFromAcl(long idOfAcl);
protected abstract Long getLatestAclEntityByGuid(String aclGuid);
protected abstract int updateAclEntity(AclEntity entity);
protected abstract int deleteAclEntity(long id);
protected abstract List<Long> getADMNodeEntityIdsByAcl(long aclEntityId, int maxResults);
protected abstract List<Long> getAVMNodeEntityIdsByAcl(long aclEntityId, int maxResults);
//
// ACL Member
//
public void addAclMembersToAcl(long aclId, List<Long> aceIds, int depth)
{
ParameterCheck.mandatory("aceIds", aceIds);
List<AclMemberEntity> newMembers = new ArrayList<AclMemberEntity>(aceIds.size());
for (Long aceId : aceIds)
{
AclMemberEntity newMember = new AclMemberEntity();
newMember.setAclId(aclId);
newMember.setAceId(aceId);
newMember.setPos(depth);
AclMemberEntity result = createAclMemberEntity(newMember);
newMembers.add(result);
}
}
public void addAclMembersToAcl(long aclId, List<Pair<Long, Integer>> aceIdsWithDepths)
{
ParameterCheck.mandatory("aceIdsWithDepths", aceIdsWithDepths);
List<AclMemberEntity> newMembers = new ArrayList<AclMemberEntity>(aceIdsWithDepths.size());
for (Pair<Long,Integer> aceIdWithDepth : aceIdsWithDepths)
{
AclMemberEntity newMember = new AclMemberEntity();
newMember.setAclId(aclId);
newMember.setAceId(aceIdWithDepth.getFirst());
newMember.setPos(aceIdWithDepth.getSecond());
AclMemberEntity result = createAclMemberEntity(newMember);
newMembers.add(result);
}
}
public List<AclMember> getAclMembersByAcl(long idOfAcl)
{
List<AclMemberEntity> entities = getAclMemberEntitiesByAcl(idOfAcl);
List<AclMember> result = new ArrayList<AclMember>(entities.size());
result.addAll(entities);
return result;
}
public List<AclMemberEntity> getAclMembersByAclForUpdate(long idOfAcl)
{
List<AclMemberEntity> members = getAclMemberEntitiesByAcl(idOfAcl);
List<AclMemberEntity> membersForUpdate = new ArrayList<AclMemberEntity>(members.size());
for (AclMemberEntity member : members)
{
AclMemberEntity newMember = new AclMemberEntity();
newMember.setId(member.getId());
newMember.setVersion(member.getVersion());
newMember.setAceId(member.getAceId());
newMember.setAclId(member.getAclId());
newMember.setPos(member.getPos());
membersForUpdate.add(newMember);
}
return membersForUpdate;
}
public List<AclMember> getAclMembersByAuthority(String authorityName)
{
List<AclMemberEntity> entities = getAclMemberEntitiesByAuthority(authorityName);
List<AclMember> result = new ArrayList<AclMember>(entities.size());
result.addAll(entities);
return result;
}
public void updateAclMember(AclMemberEntity entity)
{
ParameterCheck.mandatory("entity", entity);
ParameterCheck.mandatory("entity.id", entity.getId());
ParameterCheck.mandatory("entity.version", entity.getVersion());
ParameterCheck.mandatory("entity.aceId", entity.getAceId());
ParameterCheck.mandatory("entity.aclId", entity.getAclId());
ParameterCheck.mandatory("entity.pos", entity.getPos());
int updated = updateAclMemberEntity(entity);
if (updated < 1)
{
throw new ConcurrencyFailureException("AclMemberEntity with ID (" + entity.getId() + ") no longer exists or has been updated concurrently");
}
}
public int deleteAclMembers(List<Long> aclMemberIds)
{
int totalDeletedCount = 0;
if (aclMemberIds.size() == 0)
{
return 0;
}
else if (aclMemberIds.size() <= batchSize)
{
totalDeletedCount = deleteAclMemberEntities(aclMemberIds);
}
else
{
Iterator<Long> idIterator = aclMemberIds.iterator();
List<Long> batchIds = new ArrayList<Long>(batchSize);
while (idIterator.hasNext())
{
Long id = idIterator.next();
batchIds.add(id);
if (batchIds.size() == batchSize || (! idIterator.hasNext()))
{
int batchDeletedCount = deleteAclMemberEntities(batchIds);
totalDeletedCount = totalDeletedCount + batchDeletedCount;
batchIds.clear();
}
}
}
// TODO manually update the cache
return totalDeletedCount;
}
public int deleteAclMembersByAcl(long idOfAcl)
{
return deleteAclMemberEntitiesByAcl(idOfAcl);
}
protected abstract AclMemberEntity createAclMemberEntity(AclMemberEntity entity);
protected abstract List<AclMemberEntity> getAclMemberEntitiesByAcl(long idOfAcl);
protected abstract List<AclMemberEntity> getAclMemberEntitiesByAuthority(String authorityName);
protected abstract int updateAclMemberEntity(AclMemberEntity entity);
protected abstract int deleteAclMemberEntities(List<Long> aclMemberIds);
protected abstract int deleteAclMemberEntitiesByAcl(long idOfAcl);
//
// ACL Change Set
//
public long createAclChangeSet()
{
return createAclChangeSetEntity();
}
public AclChangeSetEntity getAclChangeSet(long changeSetId)
{
return getAclChangeSetEntity(changeSetId);
}
public void deleteAclChangeSet(long changeSetId)
{
deleteAclChangeSetEntity(changeSetId);
}
protected abstract long createAclChangeSetEntity();
protected abstract AclChangeSetEntity getAclChangeSetEntity(long changeSetId);
protected abstract int deleteAclChangeSetEntity(long id);
//
// Access Control Entry (ACE)
//
public Ace createAce(Permission permission, Authority authority, ACEType type, AccessStatus accessStatus)
{
ParameterCheck.mandatory("permission", permission);
ParameterCheck.mandatory("authority", authority);
ParameterCheck.mandatory("type", type);
ParameterCheck.mandatory("accessStatus", accessStatus);
AceEntity entity = new AceEntity();
entity.setApplies(type.getId()); // note: 'applies' stores the ACE type
entity.setAllowed((accessStatus == AccessStatus.ALLOWED) ? true : false);
entity.setAuthorityId(authority.getId());
entity.setPermissionId(permission.getId());
long aceId = createAceEntity(entity);
entity.setVersion(0L);
entity.setId(aceId);
return entity;
}
public Ace getAce(Permission permission, Authority authority, ACEType type, AccessStatus accessStatus)
{
ParameterCheck.mandatory("permission", permission);
ParameterCheck.mandatory("authority", authority);
ParameterCheck.mandatory("type", type);
ParameterCheck.mandatory("accessStatus", accessStatus);
return getAceEntity(permission.getId(),
authority.getId(),
((accessStatus == AccessStatus.ALLOWED) ? true : false),
type);
}
public Ace getAce(long aceEntityId)
{
return getAceEntity(aceEntityId);
}
public Ace getOrCreateAce(Permission permission, Authority authority, ACEType type, AccessStatus accessStatus)
{
Ace entity = getAce(permission, authority, type, accessStatus);
if (entity == null)
{
entity = createAce(permission, authority, type, accessStatus);
}
return entity;
}
public List<Ace> getAcesByAuthority(long authorityId)
{
return (List<Ace>)getAceEntitiesByAuthority(authorityId);
}
public List<Map<String, Object>> getAcesAndAuthoritiesByAcl(long idOfAcl)
{
return getAceAndAuthorityEntitiesByAcl(idOfAcl);
}
public int deleteAces(List<Long> aceIds)
{
int totalDeletedCount = 0;
if (aceIds.size() == 0)
{
return 0;
}
else if (aceIds.size() <= batchSize)
{
totalDeletedCount = deleteAceEntities(aceIds);
}
else
{
Iterator<Long> idIterator = aceIds.iterator();
List<Long> batchIds = new ArrayList<Long>(batchSize);
while (idIterator.hasNext())
{
Long id = idIterator.next();
batchIds.add(id);
if (batchIds.size() == batchSize || (! idIterator.hasNext()))
{
int batchDeletedCount = deleteAceEntities(batchIds);
totalDeletedCount = totalDeletedCount + batchDeletedCount;
batchIds.clear();
}
}
}
return totalDeletedCount;
}
protected abstract long createAceEntity(AceEntity entity);
protected abstract AceEntity getAceEntity(long aceEntityId);
protected abstract AceEntity getAceEntity(long permissionId, long authorityId, boolean allowed, ACEType type);
protected abstract List<Ace> getAceEntitiesByAuthority(long authorityId);
protected abstract List<Map<String, Object>> getAceAndAuthorityEntitiesByAcl(long idOfAcl);
protected abstract int deleteAceEntities(List<Long> aceIds);
//
// Permission
//
public Permission createPermission(PermissionReference permissionReference)
{
ParameterCheck.mandatory("permissionReference", permissionReference);
PermissionEntity entity = null;
// Get the persistent ID for the QName
Pair<Long, QName> qnamePair = qnameDAO.getOrCreateQName(permissionReference.getQName());
if (qnamePair != null)
{
Long qnameId = qnamePair.getFirst();
entity = new PermissionEntity(qnameId, permissionReference.getName());
entity.setVersion(0L);
Pair<Long, PermissionEntity> entityPair = permissionCache.getOrCreateByValue(entity);
entity = entityPair.getSecond();
}
return entity;
}
public Permission getPermission(long id)
{
Pair<Long, PermissionEntity> entityPair = permissionCache.getByKey(id);
if (entityPair == null)
{
return null;
}
return entityPair.getSecond();
}
public Permission getPermission(PermissionReference permissionReference)
{
return getPermissionImpl(permissionReference);
}
private PermissionEntity getPermissionImpl(PermissionReference permissionReference)
{
ParameterCheck.mandatory("permissionReference", permissionReference);
PermissionEntity entity = null;
// Get the persistent ID for the QName
Pair<Long, QName> qnamePair = qnameDAO.getOrCreateQName(permissionReference.getQName());
if (qnamePair != null)
{
Long qnameId = qnamePair.getFirst();
PermissionEntity permission = new PermissionEntity(qnameId, permissionReference.getName());
Pair<Long, PermissionEntity> entityPair = permissionCache.getByValue(permission);
if (entityPair != null)
{
entity = entityPair.getSecond();
}
}
return entity;
}
private PermissionEntity getPermissionForUpdate(PermissionReference permissionReference)
{
PermissionEntity perm = getPermissionImpl(permissionReference);
PermissionEntity newPerm = new PermissionEntity();
newPerm.setId(perm.getId());
newPerm.setVersion(perm.getVersion());
newPerm.setTypeQNameId(perm.getTypeQNameId());
newPerm.setName(perm.getName());
return newPerm;
}
public Permission getOrCreatePermission(PermissionReference permissionReference)
{
Permission entity = getPermission(permissionReference);
if (entity == null)
{
entity = createPermission(permissionReference);
}
return entity;
}
public void renamePermission(QName oldTypeQName, String oldName, QName newTypeQName, String newName)
{
ParameterCheck.mandatory("oldTypeQName", oldTypeQName);
ParameterCheck.mandatory("oldName", oldName);
ParameterCheck.mandatory("newTypeQName", newTypeQName);
ParameterCheck.mandatory("newName", newName);
if (oldTypeQName.equals(newTypeQName) && oldName.equals(newName))
{
throw new IllegalArgumentException("Cannot move permission to itself: " + oldTypeQName + "-" + oldName);
}
SimplePermissionReference oldPermRef = SimplePermissionReference.getPermissionReference(oldTypeQName, oldName);
PermissionEntity permission = getPermissionForUpdate(oldPermRef);
if (permission != null)
{
Long newTypeQNameId = qnameDAO.getOrCreateQName(newTypeQName).getFirst();
permission.setTypeQNameId(newTypeQNameId);
permission.setName(newName);
int updated = permissionCache.updateValue(permission.getId(), permission);
if (updated < 1)
{
throw new ConcurrencyFailureException("PermissionEntity with ID (" + permission.getId() + ") no longer exists or has been updated concurrently");
}
}
}
public void deletePermission(long id)
{
Pair<Long, PermissionEntity> entityPair = permissionCache.getByKey(id);
if (entityPair == null)
{
return;
}
int deleted = permissionCache.deleteByKey(id);
if (deleted < 1)
{
throw new ConcurrencyFailureException("PermissionEntity with ID " + id + " no longer exists");
}
}
/**
* Callback for <b>alf_permission</b> DAO
*/
private class PermissionEntityCallbackDAO implements EntityLookupCallbackDAO<Long, PermissionEntity, PermissionEntity>
{
private final Pair<Long, PermissionEntity> convertEntityToPair(PermissionEntity entity)
{
if (entity == null)
{
return null;
}
else
{
return new Pair<Long, PermissionEntity>(entity.getId(), entity);
}
}
public PermissionEntity getValueKey(PermissionEntity value)
{
return value;
}
public Pair<Long, PermissionEntity> createValue(PermissionEntity value)
{
PermissionEntity entity = createPermissionEntity(value);
return convertEntityToPair(entity);
}
public Pair<Long, PermissionEntity> findByKey(Long key)
{
PermissionEntity entity = getPermissionEntity(key);
return convertEntityToPair(entity);
}
public Pair<Long, PermissionEntity> findByValue(PermissionEntity value)
{
if ((value == null) || (value.getName() == null) || (value.getTypeQNameId() == null))
{
throw new AlfrescoRuntimeException("Unexpected: PermissionEntity / name / qnameId must not be null");
}
return convertEntityToPair(getPermissionEntity(value.getTypeQNameId(), value.getName()));
}
public int updateValue(Long key, PermissionEntity value)
{
return updatePermissionEntity(value);
}
public int deleteByKey(Long key)
{
return deletePermissionEntity(key);
}
public int deleteByValue(PermissionEntity value)
{
throw new UnsupportedOperationException("deleteByValue");
}
}
protected abstract PermissionEntity createPermissionEntity(PermissionEntity entity);
protected abstract PermissionEntity getPermissionEntity(long id);
protected abstract PermissionEntity getPermissionEntity(long qnameId, String name);
protected abstract int updatePermissionEntity(PermissionEntity updateEntity);
protected abstract int deletePermissionEntity(long id);
//
// Authority
//
public Authority createAuthority(String authorityName)
{
ParameterCheck.mandatory("authorityName", authorityName);
AuthorityEntity entity = new AuthorityEntity();
entity.setAuthority(authorityName);
entity.setCrc(CrcHelper.getStringCrcPair(authorityName, 32, true, true).getSecond());
entity.setVersion(0L);
Pair<Long, AuthorityEntity> entityPair = authorityCache.getOrCreateByValue(entity);
return entityPair.getSecond();
}
public Authority getAuthority(long id)
{
Pair<Long, AuthorityEntity> entityPair = authorityCache.getByKey(id);
if (entityPair == null)
{
return null;
}
return entityPair.getSecond();
}
public Authority getAuthority(String authorityName)
{
return getAuthorityImpl(authorityName);
}
private AuthorityEntity getAuthorityImpl(String authorityName)
{
ParameterCheck.mandatory("authorityName", authorityName);
AuthorityEntity authority = new AuthorityEntity();
authority.setAuthority(authorityName);
Pair<Long, AuthorityEntity> entityPair = authorityCache.getByValue(authority);
if (entityPair == null)
{
return null;
}
return entityPair.getSecond();
}
private AuthorityEntity getAuthorityForUpdate(String authorityName)
{
AuthorityEntity auth = getAuthorityImpl(authorityName);
if (auth == null)
{
return null;
}
AuthorityEntity newAuth = new AuthorityEntity();
newAuth.setId(auth.getId());
newAuth.setVersion(auth.getVersion());
newAuth.setAuthority(auth.getAuthority());
newAuth.setCrc(auth.getCrc());
return newAuth;
}
public Authority getOrCreateAuthority(String name)
{
Authority entity = getAuthority(name);
if (entity == null)
{
entity = createAuthority(name);
}
return entity;
}
public void renameAuthority(String before, String after)
{
ParameterCheck.mandatory("before", before);
ParameterCheck.mandatory("after", after);
AuthorityEntity entity = getAuthorityForUpdate(before);
if (entity != null)
{
entity.setAuthority(after);
entity.setCrc(CrcHelper.getStringCrcPair(after, 32, true, true).getSecond());
int updated = authorityCache.updateValue(entity.getId(), entity);
if (updated < 1)
{
throw new ConcurrencyFailureException("AuthorityEntity with ID (" + entity.getId() + ") no longer exists or has been updated concurrently");
}
}
}
public void deleteAuthority(long id)
{
Pair<Long, AuthorityEntity> entityPair = authorityCache.getByKey(id);
if (entityPair == null)
{
return;
}
int deleted = authorityCache.deleteByKey(id);
if (deleted < 1)
{
throw new ConcurrencyFailureException("AuthorityEntity with ID " + id + " no longer exists");
}
}
/**
* Callback for <b>alf_authority</b> DAO
*/
private class AuthorityEntityCallbackDAO implements EntityLookupCallbackDAO<Long, AuthorityEntity, String>
{
private final Pair<Long, AuthorityEntity> convertEntityToPair(AuthorityEntity entity)
{
if (entity == null)
{
return null;
}
else
{
return new Pair<Long, AuthorityEntity>(entity.getId(), entity);
}
}
public String getValueKey(AuthorityEntity value)
{
return value.getAuthority();
}
public Pair<Long, AuthorityEntity> createValue(AuthorityEntity value)
{
AuthorityEntity entity = createAuthorityEntity(value);
return convertEntityToPair(entity);
}
public Pair<Long, AuthorityEntity> findByKey(Long key)
{
AuthorityEntity entity = getAuthorityEntity(key);
return convertEntityToPair(entity);
}
public Pair<Long, AuthorityEntity> findByValue(AuthorityEntity value)
{
if ((value == null) || (value.getAuthority() == null))
{
throw new AlfrescoRuntimeException("Unexpected: AuthorityEntity / name must not be null");
}
return convertEntityToPair(getAuthorityEntity(value.getAuthority()));
}
public int updateValue(Long key, AuthorityEntity value)
{
return updateAuthorityEntity(value);
}
public int deleteByKey(Long key)
{
return deleteAuthorityEntity(key);
}
public int deleteByValue(AuthorityEntity value)
{
throw new UnsupportedOperationException("deleteByValue");
}
}
protected abstract AuthorityEntity createAuthorityEntity(AuthorityEntity entity);
protected abstract AuthorityEntity getAuthorityEntity(long id);
protected abstract AuthorityEntity getAuthorityEntity(String authorityName);
protected abstract int updateAuthorityEntity(AuthorityEntity updateEntity);
protected abstract int deleteAuthorityEntity(long id);
// ACE Context (NOTE: currently unused - intended for possible future enhancement)
protected abstract long createAceContextEntity(AceContextEntity entity);
protected abstract AceContextEntity getAceContextEntity(long aceContextId);
protected abstract int deleteAceContextEntity(long aceContextId);
//
// Authority Alias (NOTE: currently unused - intended for possible future enhancement)
//
protected abstract long createAuthorityAliasEntity(AuthorityAliasEntity entity);
protected abstract int deleteAuthorityAliasEntity(long id);
}