Search in sources :

Example 6 with AclChange

use of org.alfresco.repo.security.permissions.impl.AclChange in project alfresco-repository by Alfresco.

the class AclDAOImpl method getInheritedAccessControlList.

/**
 * {@inheritDoc}
 */
@Override
public Long getInheritedAccessControlList(Long id) {
    AclUpdateEntity acl = aclCrudDAO.getAclForUpdate(id);
    if (acl.getAclType() == ACLType.OLD) {
        return null;
    }
    if ((acl.getInheritedAcl() != null) && (acl.getInheritedAcl() != -1)) {
        return acl.getInheritedAcl();
    }
    Long inheritedAclId = null;
    if ((acl.getAclType() == ACLType.DEFINING) || (acl.getAclType() == ACLType.LAYERED)) {
        List<AclChange> changes = new ArrayList<AclChange>();
        // created shared acl
        SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
        properties.setAclType(ACLType.SHARED);
        properties.setInherits(Boolean.TRUE);
        properties.setVersioned(acl.isVersioned());
        Long sharedId = createAccessControlList(properties, null, null).getId();
        getWritable(sharedId, id, null, null, id, true, changes, WriteMode.ADD_INHERITED);
        acl.setInheritedAcl(sharedId);
        inheritedAclId = sharedId;
    } else {
        acl.setInheritedAcl(acl.getId());
        inheritedAclId = acl.getId();
    }
    acl.setAclChangeSetId(getCurrentChangeSetId());
    aclCrudDAO.updateAcl(acl);
    return inheritedAclId;
}
Also used : ArrayList(java.util.ArrayList) AclChange(org.alfresco.repo.security.permissions.impl.AclChange) SimpleAccessControlListProperties(org.alfresco.repo.security.permissions.SimpleAccessControlListProperties)

Example 7 with AclChange

use of org.alfresco.repo.security.permissions.impl.AclChange in project alfresco-repository by Alfresco.

the class ADMPermissionsDaoComponentImpl method replaceWithCleanDefiningAcl.

/**
 * @param nodeRef NodeRef
 * @param acl Acl
 */
private void replaceWithCleanDefiningAcl(NodeRef nodeRef, Acl acl) {
    // TODO: could just clear out existing
    SimpleAccessControlListProperties properties = new SimpleAccessControlListProperties();
    properties = new SimpleAccessControlListProperties();
    properties.setAclType(ACLType.DEFINING);
    properties.setInherits(Boolean.FALSE);
    properties.setVersioned(false);
    Acl newAcl = aclDaoComponent.createAccessControlList(properties);
    long id = newAcl.getId();
    getACLDAO(nodeRef).setAccessControlList(nodeRef, newAcl);
    List<AclChange> changes = new ArrayList<AclChange>();
    changes.addAll(getACLDAO(nodeRef).setInheritanceForChildren(nodeRef, id, acl.getInheritedAcl()));
    getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
    aclDaoComponent.deleteAccessControlList(acl.getId());
}
Also used : ArrayList(java.util.ArrayList) SimpleAccessControlListProperties(org.alfresco.repo.security.permissions.SimpleAccessControlListProperties) AclChange(org.alfresco.repo.security.permissions.impl.AclChange)

Example 8 with AclChange

use of org.alfresco.repo.security.permissions.impl.AclChange in project alfresco-repository by Alfresco.

the class AbstractPermissionsDaoComponentImpl method setPermission.

public void setPermission(NodeRef nodeRef, String authority, PermissionReference permission, boolean allow) {
    CreationReport report = null;
    try {
        report = getMutableAccessControlList(nodeRef);
    } catch (InvalidNodeRefException e) {
        return;
    }
    if (report.getCreated() != null) {
        SimpleAccessControlEntry entry = new SimpleAccessControlEntry();
        entry.setAuthority(authority);
        entry.setPermission(permission);
        entry.setAccessStatus(allow ? AccessStatus.ALLOWED : AccessStatus.DENIED);
        entry.setAceType(ACEType.ALL);
        entry.setPosition(Integer.valueOf(0));
        List<AclChange> changes = aclDaoComponent.setAccessControlEntry(report.getCreated().getId(), entry);
        List<AclChange> all = new ArrayList<AclChange>(changes.size() + report.getChanges().size());
        all.addAll(report.getChanges());
        all.addAll(changes);
        getACLDAO(nodeRef).updateChangedAcls(nodeRef, all);
    }
}
Also used : ArrayList(java.util.ArrayList) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AclChange(org.alfresco.repo.security.permissions.impl.AclChange) SimpleAccessControlEntry(org.alfresco.repo.security.permissions.SimpleAccessControlEntry)

Example 9 with AclChange

use of org.alfresco.repo.security.permissions.impl.AclChange in project alfresco-repository by Alfresco.

the class AbstractPermissionsDaoComponentImpl method deletePermissions.

public void deletePermissions(NodeRef nodeRef, final String authority) {
    Acl acl = null;
    try {
        AccessControlListDAO aclDAO = getACLDAO(nodeRef);
        if (aclDAO == null) {
            return;
        }
        acl = aclDAO.getAccessControlList(nodeRef);
        if (acl == null) {
            return;
        }
    } catch (InvalidNodeRefException e) {
        return;
    }
    switch(acl.getAclType()) {
        case FIXED:
        case GLOBAL:
            throw new IllegalStateException("Can not delete from this acl in a node context " + acl.getAclType());
        case SHARED:
            // Nothing to do
            break;
        case DEFINING:
        case LAYERED:
        case OLD:
        default:
            CreationReport report = getMutableAccessControlList(nodeRef);
            SimpleAccessControlEntry pattern = new SimpleAccessControlEntry();
            pattern.setAuthority(authority);
            pattern.setPosition(Integer.valueOf(0));
            List<AclChange> changes = aclDaoComponent.deleteAccessControlEntries(report.getCreated().getId(), pattern);
            getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
            break;
    }
}
Also used : InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AclChange(org.alfresco.repo.security.permissions.impl.AclChange) SimpleAccessControlEntry(org.alfresco.repo.security.permissions.SimpleAccessControlEntry)

Example 10 with AclChange

use of org.alfresco.repo.security.permissions.impl.AclChange in project alfresco-repository by Alfresco.

the class AbstractPermissionsDaoComponentImpl method deletePermission.

/**
 * 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) {
    Acl acl = null;
    try {
        AccessControlListDAO aclDAO = getACLDAO(nodeRef);
        if (aclDAO == null) {
            return;
        }
        acl = aclDAO.getAccessControlList(nodeRef);
        if (acl == null) {
            return;
        }
    } catch (InvalidNodeRefException e) {
        return;
    }
    // avoid NullPointerException if it was not created
    if (acl == null) {
        return;
    }
    switch(acl.getAclType()) {
        case FIXED:
        case GLOBAL:
        case SHARED:
            throw new IllegalStateException("Can not delete from this acl in a node context " + acl.getAclType());
        case DEFINING:
        case LAYERED:
        case OLD:
        default:
            CreationReport report = getMutableAccessControlList(nodeRef);
            SimpleAccessControlEntry pattern = new SimpleAccessControlEntry();
            pattern.setAuthority(authority);
            pattern.setPermission(permission);
            pattern.setPosition(Integer.valueOf(0));
            List<AclChange> changes = aclDaoComponent.deleteAccessControlEntries(report.getCreated().getId(), pattern);
            getACLDAO(nodeRef).updateChangedAcls(nodeRef, changes);
            break;
    }
}
Also used : InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AclChange(org.alfresco.repo.security.permissions.impl.AclChange) SimpleAccessControlEntry(org.alfresco.repo.security.permissions.SimpleAccessControlEntry)

Aggregations

AclChange (org.alfresco.repo.security.permissions.impl.AclChange)16 ArrayList (java.util.ArrayList)12 SimpleAccessControlEntry (org.alfresco.repo.security.permissions.SimpleAccessControlEntry)10 SimpleAccessControlListProperties (org.alfresco.repo.security.permissions.SimpleAccessControlListProperties)4 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)3 AccessControlEntry (org.alfresco.repo.security.permissions.AccessControlEntry)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 AccessControlList (org.alfresco.repo.security.permissions.AccessControlList)1 NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)1 PermissionEntry (org.alfresco.repo.security.permissions.PermissionEntry)1 SimpleAccessControlList (org.alfresco.repo.security.permissions.SimpleAccessControlList)1 SimpleNodePermissionEntry (org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry)1 SimplePermissionEntry (org.alfresco.repo.security.permissions.impl.SimplePermissionEntry)1 SimplePermissionReference (org.alfresco.repo.security.permissions.impl.SimplePermissionReference)1 QName (org.alfresco.service.namespace.QName)1