mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V2.2 to HEAD
7575: Permission changes for AVM. 7577: Incorporated most of the feedback provided by Kevin C earlier today 7578: Removed directory not removed by patch 7579: EmailServer bug fixes AR-1902: Double posts when emailing to a document AR-1904: Attachments via email should be allowed on forum posts AR-1903: (Partial Fix) Text attachments should be treated the same way as other attachments 7583: Fixed WCM-961 & WCM-962: Added confirm dialog for 'Delete All Deployment Reports' and 'Release Server' actions git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@8434 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,226 +24,107 @@
|
||||
*/
|
||||
package org.alfresco.repo.domain.hibernate;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.repo.domain.AccessControlListDAO;
|
||||
import org.alfresco.repo.domain.DbAccessControlEntry;
|
||||
import org.alfresco.repo.domain.DbAccessControlList;
|
||||
import org.alfresco.repo.domain.DbAuthority;
|
||||
import org.alfresco.repo.domain.DbPermission;
|
||||
import org.alfresco.repo.domain.DbPermissionKey;
|
||||
import org.alfresco.repo.domain.Node;
|
||||
import org.alfresco.repo.domain.NodeStatus;
|
||||
import org.alfresco.repo.security.permissions.NodePermissionEntry;
|
||||
import org.alfresco.repo.security.permissions.PermissionEntry;
|
||||
import org.alfresco.repo.security.permissions.PermissionReference;
|
||||
import org.alfresco.repo.security.permissions.impl.AccessPermissionImpl;
|
||||
import org.alfresco.repo.security.permissions.impl.PermissionReferenceImpl;
|
||||
import org.alfresco.repo.security.permissions.impl.PermissionsDaoComponent;
|
||||
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.repo.domain.hibernate.AbstractPermissionsDaoComponentImpl.CreationReport;
|
||||
import org.alfresco.repo.security.permissions.ACLType;
|
||||
import org.alfresco.repo.security.permissions.AccessControlEntry;
|
||||
import org.alfresco.repo.security.permissions.AccessControlList;
|
||||
import org.alfresco.repo.security.permissions.SimpleAccessControlListProperties;
|
||||
import org.alfresco.repo.security.permissions.impl.AclChange;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessPermission;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.Session;
|
||||
import org.springframework.orm.hibernate3.HibernateCallback;
|
||||
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
|
||||
|
||||
/**
|
||||
* Support for accessing persisted permission information. This class maps between persisted objects and the external
|
||||
* API defined in the PermissionsDAO interface.
|
||||
*
|
||||
* @author andyh
|
||||
*/
|
||||
public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements PermissionsDaoComponent,
|
||||
TransactionalDao
|
||||
public class PermissionsDaoComponentImpl extends AbstractPermissionsDaoComponentImpl
|
||||
{
|
||||
private static final boolean INHERIT_PERMISSIONS_DEFAULT = true;
|
||||
|
||||
public static final String QUERY_GET_PERMISSION = "permission.GetPermission";
|
||||
|
||||
public static final String QUERY_GET_AC_ENTRIES_FOR_AUTHORITY = "permission.GetAccessControlEntriesForAuthority";
|
||||
|
||||
public static final String QUERY_GET_ALL_AC_ENTRIES_FOR_AUTHORITY = "permission.GetAllAccessControlEntriesForAuthority";
|
||||
|
||||
public static final String QUERY_GET_AC_ENTRIES_FOR_PERMISSION = "permission.GetAccessControlEntriesForPermission";
|
||||
|
||||
public static final String QUERY_FIND_NODES_BY_PERMISSION = "permission.FindNodesByPermission";
|
||||
|
||||
private Map<String, AccessControlListDAO> fProtocolToACLDAO;
|
||||
|
||||
private AccessControlListDAO fDefaultACLDAO;
|
||||
|
||||
/** a uuid identifying this unique instance */
|
||||
private String uuid;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PermissionsDaoComponentImpl()
|
||||
@Override
|
||||
protected CreationReport createAccessControlList(NodeRef nodeRef, boolean inherit, DbAccessControlList existing)
|
||||
{
|
||||
this.uuid = GUID.generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks equality by type and uuid
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
if (existing == null)
|
||||
{
|
||||
return false;
|
||||
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
|
||||
properties.setAclType(ACLType.DEFINING);
|
||||
// Accept default versioning
|
||||
Long id = aclDaoComponent.createAccessControlList(properties);
|
||||
List<AclChange> changes = new ArrayList<AclChange>();
|
||||
DbAccessControlList acl = aclDaoComponent.getDbAccessControlList(id);
|
||||
changes.add(new AclDaoComponentImpl.AclChangeImpl(null, id, null, acl.getAclType()));
|
||||
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, aclDaoComponent.getInheritedAccessControlList(id)));
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
|
||||
return new CreationReport(acl, changes);
|
||||
}
|
||||
else if (!(obj instanceof PermissionsDaoComponentImpl))
|
||||
SimpleAccessControlListProperties properties;
|
||||
Long id;
|
||||
List<AclChange> changes;
|
||||
DbAccessControlList acl;
|
||||
switch (existing.getAclType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
PermissionsDaoComponentImpl that = (PermissionsDaoComponentImpl) obj;
|
||||
return this.uuid.equals(that.uuid);
|
||||
}
|
||||
case OLD:
|
||||
throw new IllegalStateException("Can not mix old and new style permissions");
|
||||
case DEFINING:
|
||||
return new CreationReport(existing, Collections.<AclChange> emptyList());
|
||||
case FIXED:
|
||||
case GLOBAL:
|
||||
case SHARED:
|
||||
// create new defining, wire up and report changes to acl required.
|
||||
properties = new SimpleAccessControlListProperties();
|
||||
properties.setAclType(ACLType.DEFINING);
|
||||
properties.setInherits(existing.getInherits());
|
||||
// Accept default versioning
|
||||
id = aclDaoComponent.createAccessControlList(properties);
|
||||
changes = new ArrayList<AclChange>();
|
||||
acl = aclDaoComponent.getDbAccessControlList(id);
|
||||
changes.add(new AclDaoComponentImpl.AclChangeImpl(existing.getId(), id, existing.getAclType(), acl.getAclType()));
|
||||
changes.addAll(aclDaoComponent.mergeInheritedAccessControlList(existing.getId(), id));
|
||||
// set this to inherit to children
|
||||
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, aclDaoComponent.getInheritedAccessControlList(id)));
|
||||
|
||||
/**
|
||||
* @see #uuid
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return uuid.hashCode();
|
||||
}
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
|
||||
return new CreationReport(acl, changes);
|
||||
case LAYERED:
|
||||
// Need to get the indirected node ACL
|
||||
Long indirectAclId = getACLDAO(nodeRef).getIndirectAcl(nodeRef);
|
||||
Long inheritedAclId = getACLDAO(nodeRef).getInheritedAcl(nodeRef);
|
||||
|
||||
/**
|
||||
* Does this <tt>Session</tt> contain any changes which must be synchronized with the store?
|
||||
*
|
||||
* @return true => changes are pending
|
||||
*/
|
||||
public boolean isDirty()
|
||||
{
|
||||
// create a callback for the task
|
||||
HibernateCallback callback = new HibernateCallback()
|
||||
{
|
||||
public Object doInHibernate(Session session)
|
||||
// create new defining, wire up and report changes to acl required.
|
||||
properties = new SimpleAccessControlListProperties();
|
||||
properties.setAclType(ACLType.DEFINING);
|
||||
if (indirectAclId != null)
|
||||
{
|
||||
return session.isDirty();
|
||||
properties.setInherits(aclDaoComponent.getAccessControlListProperties(indirectAclId).getInherits());
|
||||
}
|
||||
};
|
||||
// execute the callback
|
||||
return ((Boolean) getHibernateTemplate().execute(callback)).booleanValue();
|
||||
}
|
||||
// Accept default versioning
|
||||
id = aclDaoComponent.createAccessControlList(properties);
|
||||
changes = new ArrayList<AclChange>();
|
||||
acl = aclDaoComponent.getDbAccessControlList(id);
|
||||
changes.add(new AclDaoComponentImpl.AclChangeImpl(existing.getId(), id, existing.getAclType(), acl.getAclType()));
|
||||
if (indirectAclId != null)
|
||||
{
|
||||
AccessControlList indirectAcl = aclDaoComponent.getAccessControlList(indirectAclId);
|
||||
for (AccessControlEntry entry : indirectAcl.getEntries())
|
||||
{
|
||||
if (entry.getPosition() == 0)
|
||||
{
|
||||
aclDaoComponent.setAccessControlEntry(id, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inheritedAclId != null)
|
||||
{
|
||||
changes.addAll(aclDaoComponent.mergeInheritedAccessControlList(inheritedAclId, id));
|
||||
}
|
||||
// set this to inherit to children
|
||||
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, aclDaoComponent.getInheritedAccessControlList(id)));
|
||||
|
||||
/**
|
||||
* Just flushes the session
|
||||
*/
|
||||
public void flush()
|
||||
{
|
||||
getSession().flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* NO-OP
|
||||
*/
|
||||
public void beforeCommit()
|
||||
{
|
||||
}
|
||||
|
||||
public void setProtocolToACLDAO(Map<String, AccessControlListDAO> map)
|
||||
{
|
||||
fProtocolToACLDAO = map;
|
||||
}
|
||||
|
||||
public void setDefaultACLDAO(AccessControlListDAO defaultACLDAO)
|
||||
{
|
||||
fDefaultACLDAO = defaultACLDAO;
|
||||
}
|
||||
|
||||
public NodePermissionEntry getPermissions(NodeRef nodeRef)
|
||||
{
|
||||
// Create the object if it is not found.
|
||||
// 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;
|
||||
try
|
||||
{
|
||||
acl = getAccessControlList(nodeRef, false);
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
|
||||
return new CreationReport(acl, changes);
|
||||
default:
|
||||
throw new IllegalStateException("Unknown type " + existing.getAclType());
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
if (acl == null)
|
||||
{
|
||||
// there isn't an access control list for the node - spoof a null one
|
||||
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections
|
||||
.<SimplePermissionEntry> emptySet());
|
||||
npe = snpe;
|
||||
}
|
||||
else
|
||||
{
|
||||
npe = createSimpleNodePermissionEntry(nodeRef);
|
||||
}
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Created access control list for node: \n" + " node: " + nodeRef + "\n" + " acl: " + npe);
|
||||
}
|
||||
return npe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the persisted access control list or create it if required.
|
||||
*
|
||||
* @param nodeRef -
|
||||
* the node for which to create the list
|
||||
* @param create -
|
||||
* create the object if it is missing
|
||||
* @return Returns the current access control list or null if not found
|
||||
*/
|
||||
private DbAccessControlList getAccessControlList(NodeRef nodeRef, boolean create)
|
||||
{
|
||||
DbAccessControlList acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
|
||||
if (acl == null && create)
|
||||
{
|
||||
acl = createAccessControlList(nodeRef);
|
||||
}
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Retrieved access control list: \n" + " node: " + nodeRef + "\n" + " list: " + acl);
|
||||
}
|
||||
return acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an access control list for the node and removes the entry from the nullPermsionCache.
|
||||
*/
|
||||
private DbAccessControlList createAccessControlList(NodeRef nodeRef)
|
||||
{
|
||||
DbAccessControlList acl = new DbAccessControlListImpl();
|
||||
acl.setInherits(INHERIT_PERMISSIONS_DEFAULT);
|
||||
getHibernateTemplate().save(acl);
|
||||
|
||||
// maintain inverse
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, acl);
|
||||
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Created Access Control List: \n" + " node: " + nodeRef + "\n" + " list: " + acl);
|
||||
}
|
||||
return acl;
|
||||
}
|
||||
|
||||
public void deletePermissions(NodeRef nodeRef)
|
||||
@@ -251,7 +132,7 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
|
||||
DbAccessControlList acl = null;
|
||||
try
|
||||
{
|
||||
acl = getAccessControlList(nodeRef, false);
|
||||
acl = getAccessControlList(nodeRef);
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
@@ -259,422 +140,32 @@ public class PermissionsDaoComponentImpl extends HibernateDaoSupport implements
|
||||
}
|
||||
if (acl != null)
|
||||
{
|
||||
// maintain referencial integrity
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, null);
|
||||
// delete the access control list - it will cascade to the entries
|
||||
getHibernateTemplate().delete(acl);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void deletePermissions(final String authority)
|
||||
{
|
||||
// get the authority
|
||||
HibernateCallback callback = new HibernateCallback()
|
||||
{
|
||||
public Object doInHibernate(Session session)
|
||||
if (acl.getInheritsFrom() != null)
|
||||
{
|
||||
Query query = session.getNamedQuery(QUERY_GET_AC_ENTRIES_FOR_AUTHORITY).setString("authorityRecipient",
|
||||
authority);
|
||||
return (Integer) HibernateHelper.deleteDbAccessControlEntries(session, query);
|
||||
Long deleted = acl.getId();
|
||||
Long inheritsFrom = acl.getInheritsFrom();
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, aclDaoComponent.getDbAccessControlList(inheritsFrom));
|
||||
aclDaoComponent.deleteAccessControlList(acl.getId());
|
||||
List<AclChange> changes = new ArrayList<AclChange>();
|
||||
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, inheritsFrom));
|
||||
getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
|
||||
}
|
||||
};
|
||||
Integer deletedCount = (Integer) getHibernateTemplate().execute(callback);
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Deleted " + deletedCount + " entries for authority " + authority);
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePermissions(final NodeRef nodeRef, final String authority)
|
||||
{
|
||||
DbAccessControlList acl = null;
|
||||
try
|
||||
{
|
||||
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int deletedCount = 0;
|
||||
if (acl != null)
|
||||
{
|
||||
deletedCount = acl.deleteEntriesForAuthority(authority);
|
||||
}
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Deleted "
|
||||
+ deletedCount + "entries for criteria: \n" + " node: " + nodeRef + "\n" + " authority: "
|
||||
+ authority);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all permission entries (access control list entries) that match the given criteria. Note that the access
|
||||
* control list for the node is not deleted.
|
||||
*/
|
||||
public void deletePermission(NodeRef nodeRef, String authority, PermissionReference permission)
|
||||
{
|
||||
DbAccessControlList acl = null;
|
||||
try
|
||||
{
|
||||
acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int deletedCount = 0;
|
||||
if (acl != null)
|
||||
{
|
||||
DbPermissionKey permissionKey = new DbPermissionKey(permission.getQName(), permission.getName());
|
||||
deletedCount = acl.deleteEntry(authority, permissionKey);
|
||||
}
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Deleted "
|
||||
+ deletedCount + "entries for criteria: \n" + " node: " + nodeRef + "\n" + " permission: "
|
||||
+ permission + "\n" + " authority: " + authority);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPermission(NodeRef nodeRef, String authority, PermissionReference permission, boolean allow)
|
||||
{
|
||||
// get the entry
|
||||
DbAccessControlEntry entry = getAccessControlEntry(nodeRef, authority, permission);
|
||||
if (entry == null)
|
||||
{
|
||||
// need to create it
|
||||
DbAccessControlList dbAccessControlList = getAccessControlList(nodeRef, true);
|
||||
DbPermission dbPermission = getPermission(permission, true);
|
||||
DbAuthority dbAuthority = getAuthority(authority, true);
|
||||
// set persistent objects
|
||||
entry = dbAccessControlList.newEntry(dbPermission, dbAuthority, allow);
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
else
|
||||
{
|
||||
logger.debug("Created new access control entry: " + entry);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.setAllowed(allow);
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Updated access control entry: " + entry);
|
||||
// TODO: could just cear out existing
|
||||
Long deleted = acl.getId();
|
||||
SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
|
||||
properties.setAclType(ACLType.DEFINING);
|
||||
properties.setInherits(Boolean.FALSE);
|
||||
// Accept default versioning
|
||||
Long id = aclDaoComponent.createAccessControlList(properties);
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, aclDaoComponent.getDbAccessControlList(id));
|
||||
aclDaoComponent.deleteAccessControlList(acl.getId());
|
||||
List<AclChange> changes = new ArrayList<AclChange>();
|
||||
changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, id));
|
||||
getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeRef
|
||||
* the node against which to join
|
||||
* @param authority
|
||||
* the authority against which to join
|
||||
* @param perm
|
||||
* the permission against which to join
|
||||
* @return Returns all access control entries that match the criteria
|
||||
*/
|
||||
private DbAccessControlEntry getAccessControlEntry(NodeRef nodeRef, String authority, PermissionReference permission)
|
||||
{
|
||||
DbAccessControlList acl = getAccessControlList(nodeRef, false);
|
||||
DbAccessControlEntry entry = null;
|
||||
if (acl != null)
|
||||
{
|
||||
DbPermissionKey permissionKey = new DbPermissionKey(permission.getQName(), permission.getName());
|
||||
entry = acl.getEntry(authority, permissionKey);
|
||||
}
|
||||
// done
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(""
|
||||
+ (entry == null ? "Did not find" : "Found") + " entry for criteria: \n" + " node: " + nodeRef
|
||||
+ "\n" + " authority: " + authority + "\n" + " permission: " + permission);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to find or create a persisted authority
|
||||
*/
|
||||
private DbAuthority getAuthority(String authority, boolean create)
|
||||
{
|
||||
DbAuthority entity = (DbAuthority) getHibernateTemplate().get(DbAuthorityImpl.class, authority);
|
||||
if ((entity == null) && create)
|
||||
{
|
||||
entity = new DbAuthorityImpl();
|
||||
entity.setRecipient(authority);
|
||||
getHibernateTemplate().save(entity);
|
||||
return entity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to find and optionally create a persisted permission.
|
||||
*/
|
||||
private DbPermission getPermission(PermissionReference permissionRef, final boolean create)
|
||||
{
|
||||
final QName qname = permissionRef.getQName();
|
||||
final String name = permissionRef.getName();
|
||||
Session session = getSession();
|
||||
|
||||
DbPermission dbPermission = DbPermissionImpl.find(session, qname, name);
|
||||
|
||||
// create if necessary
|
||||
if ((dbPermission == null) && create)
|
||||
{
|
||||
dbPermission = new DbPermissionImpl();
|
||||
dbPermission.setTypeQname(qname);
|
||||
dbPermission.setName(name);
|
||||
getHibernateTemplate().save(dbPermission);
|
||||
}
|
||||
return dbPermission;
|
||||
}
|
||||
|
||||
public void setPermission(PermissionEntry permissionEntry)
|
||||
{
|
||||
setPermission(permissionEntry.getNodeRef(), permissionEntry.getAuthority(), permissionEntry
|
||||
.getPermissionReference(), permissionEntry.isAllowed());
|
||||
}
|
||||
|
||||
public void setPermission(NodePermissionEntry nodePermissionEntry)
|
||||
{
|
||||
NodeRef nodeRef = nodePermissionEntry.getNodeRef();
|
||||
|
||||
// Get the access control list
|
||||
// Note the logic here requires to know whether it was created or not
|
||||
DbAccessControlList acl = getAccessControlList(nodeRef, false);
|
||||
if (acl != null)
|
||||
{
|
||||
// maintain referencial integrity
|
||||
getACLDAO(nodeRef).setAccessControlList(nodeRef, null);
|
||||
// drop the list
|
||||
getHibernateTemplate().delete(acl);
|
||||
}
|
||||
// create the access control list
|
||||
acl = createAccessControlList(nodeRef);
|
||||
|
||||
// set attributes
|
||||
acl.setInherits(nodePermissionEntry.inheritPermissions());
|
||||
|
||||
// add all entries
|
||||
for (PermissionEntry pe : nodePermissionEntry.getPermissionEntries())
|
||||
{
|
||||
PermissionReference permission = pe.getPermissionReference();
|
||||
String authority = pe.getAuthority();
|
||||
boolean isAllowed = pe.isAllowed();
|
||||
|
||||
DbPermission permissionEntity = getPermission(permission, true);
|
||||
DbAuthority authorityEntity = getAuthority(authority, true);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
DbAccessControlEntryImpl entry = acl.newEntry(permissionEntity, authorityEntity, isAllowed);
|
||||
}
|
||||
}
|
||||
|
||||
public void setInheritParentPermissions(NodeRef nodeRef, boolean inheritParentPermissions)
|
||||
{
|
||||
DbAccessControlList acl = null;
|
||||
if (!inheritParentPermissions)
|
||||
{
|
||||
// Inheritance == true is the default, so only force a create of the ACL if the value false
|
||||
acl = getAccessControlList(nodeRef, true);
|
||||
acl.setInherits(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
acl = getAccessControlList(nodeRef, false);
|
||||
if (acl != null)
|
||||
{
|
||||
acl.setInherits(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getInheritParentPermissions(NodeRef nodeRef)
|
||||
{
|
||||
DbAccessControlList acl = null;
|
||||
try
|
||||
{
|
||||
acl = getAccessControlList(nodeRef, false);
|
||||
}
|
||||
catch (InvalidNodeRefException e)
|
||||
{
|
||||
return INHERIT_PERMISSIONS_DEFAULT;
|
||||
}
|
||||
if (acl == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return acl.getInherits();
|
||||
}
|
||||
}
|
||||
|
||||
// Utility methods to create simple detached objects for the outside world
|
||||
// We do not pass out the hibernate objects
|
||||
|
||||
private SimpleNodePermissionEntry createSimpleNodePermissionEntry(NodeRef nodeRef)
|
||||
{
|
||||
DbAccessControlList acl = getACLDAO(nodeRef).getAccessControlList(nodeRef);
|
||||
if (acl == null)
|
||||
{
|
||||
// there isn't an access control list for the node - spoof a null one
|
||||
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, true, Collections
|
||||
.<SimplePermissionEntry> emptySet());
|
||||
return snpe;
|
||||
}
|
||||
else
|
||||
{
|
||||
Set<DbAccessControlEntry> entries = acl.getEntries();
|
||||
SimpleNodePermissionEntry snpe = new SimpleNodePermissionEntry(nodeRef, acl.getInherits(),
|
||||
createSimplePermissionEntries(nodeRef, entries));
|
||||
return snpe;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entries
|
||||
* access control entries
|
||||
* @return Returns a unique set of entries that can be given back to the outside world
|
||||
*/
|
||||
private Set<SimplePermissionEntry> createSimplePermissionEntries(NodeRef nodeRef,
|
||||
Collection<DbAccessControlEntry> entries)
|
||||
{
|
||||
if (entries == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
HashSet<SimplePermissionEntry> spes = new HashSet<SimplePermissionEntry>(entries.size(), 1.0f);
|
||||
if (entries.size() != 0)
|
||||
{
|
||||
for (DbAccessControlEntry entry : entries)
|
||||
{
|
||||
spes.add(createSimplePermissionEntry(nodeRef, entry));
|
||||
}
|
||||
}
|
||||
return spes;
|
||||
}
|
||||
|
||||
private static SimplePermissionEntry createSimplePermissionEntry(NodeRef nodeRef, DbAccessControlEntry ace)
|
||||
{
|
||||
if (ace == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new SimplePermissionEntry(nodeRef, createSimplePermissionReference(ace.getPermission()), ace
|
||||
.getAuthority().getRecipient(), ace.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED);
|
||||
}
|
||||
|
||||
private static SimplePermissionReference createSimplePermissionReference(DbPermission perm)
|
||||
{
|
||||
if (perm == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new SimplePermissionReference(perm.getTypeQname(), perm.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to choose appropriate NodeService for the given NodeRef
|
||||
*
|
||||
* @param nodeRef
|
||||
* The NodeRef to dispatch from.
|
||||
* @return The appropriate NodeService.
|
||||
*/
|
||||
private AccessControlListDAO getACLDAO(NodeRef nodeRef)
|
||||
{
|
||||
AccessControlListDAO ret = fProtocolToACLDAO.get(nodeRef.getStoreRef().getProtocol());
|
||||
if (ret == null)
|
||||
{
|
||||
return fDefaultACLDAO;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<NodeRef, Set<AccessPermission>> getAllSetPermissions(final String authority)
|
||||
{
|
||||
// get the authority
|
||||
HibernateCallback callback = new HibernateCallback()
|
||||
{
|
||||
public Object doInHibernate(Session session)
|
||||
{
|
||||
Query query = session.getNamedQuery(QUERY_GET_ALL_AC_ENTRIES_FOR_AUTHORITY).setString(
|
||||
"authorityRecipient", authority);
|
||||
|
||||
Map<NodeRef, Set<AccessPermission>> result = new HashMap<NodeRef, Set<AccessPermission>>();
|
||||
|
||||
ScrollableResults entities = query.scroll(ScrollMode.FORWARD_ONLY);
|
||||
while (entities.next())
|
||||
{
|
||||
DbAccessControlEntry entry = (DbAccessControlEntry) entities.get(0);
|
||||
// DbAccessControlList acl = (DbAccessControlList) entities.get(1);
|
||||
Node node = (Node) entities.get(2);
|
||||
DbPermission dbPermission = entry.getPermission();
|
||||
PermissionReferenceImpl pr = new PermissionReferenceImpl(dbPermission.getTypeQname(), dbPermission
|
||||
.getName());
|
||||
AccessStatus accessStatus = entry.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED;
|
||||
AccessPermission ap = new AccessPermissionImpl(pr.toString(), accessStatus, entry.getAuthority()
|
||||
.getRecipient());
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
Set<AccessPermission> nodeSet = result.get(nodeRef);
|
||||
if (nodeSet == null)
|
||||
{
|
||||
nodeSet = new HashSet<AccessPermission>();
|
||||
result.put(nodeRef, nodeSet);
|
||||
}
|
||||
nodeSet.add(ap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
return (Map<NodeRef, Set<AccessPermission>>) getHibernateTemplate().execute(callback);
|
||||
|
||||
}
|
||||
|
||||
public Set<NodeRef> findNodeByPermission(final String authority, final PermissionReference permission, final boolean allow)
|
||||
{
|
||||
// get the authority
|
||||
HibernateCallback callback = new HibernateCallback()
|
||||
{
|
||||
public Object doInHibernate(Session session)
|
||||
{
|
||||
Query query = session.getNamedQuery(QUERY_FIND_NODES_BY_PERMISSION).setString(
|
||||
"authorityRecipient", authority).setBoolean("allow", allow).setString("permissionName", permission.getName()).setString("permissionTypeQname", permission.getQName().toString());
|
||||
|
||||
Set<NodeRef> result = new HashSet<NodeRef>();
|
||||
|
||||
ScrollableResults entities = query.scroll(ScrollMode.FORWARD_ONLY);
|
||||
while (entities.next())
|
||||
{
|
||||
DbAccessControlEntry entry = (DbAccessControlEntry) entities.get(0);
|
||||
// DbAccessControlList acl = (DbAccessControlList) entities.get(1);
|
||||
Node node = (Node) entities.get(2);
|
||||
DbPermission dbPermission = entry.getPermission();
|
||||
PermissionReferenceImpl pr = new PermissionReferenceImpl(dbPermission.getTypeQname(), dbPermission
|
||||
.getName());
|
||||
AccessStatus accessStatus = entry.isAllowed() ? AccessStatus.ALLOWED : AccessStatus.DENIED;
|
||||
AccessPermission ap = new AccessPermissionImpl(pr.toString(), accessStatus, entry.getAuthority()
|
||||
.getRecipient());
|
||||
NodeRef nodeRef = node.getNodeRef();
|
||||
result.add(nodeRef);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
return (Set<NodeRef>) getHibernateTemplate().execute(callback);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user