Search in sources :

Example 1 with AbstractHierarchicalEntity

use of com.epam.pipeline.entity.AbstractHierarchicalEntity in project cloud-pipeline by epam.

the class GrantPermissionManager method clearWriteExecutePermissions.

private void clearWriteExecutePermissions(AbstractSecuredEntity entity) {
    int readBits = AclPermission.READ.getMask() | AclPermission.NO_READ.getMask();
    MutableAcl acl = aclService.getOrCreateObjectIdentity(entity);
    List<AccessControlEntry> newAces = new ArrayList<>();
    List<AccessControlEntry> aces = acl.getEntries();
    for (int i = 0; i < aces.size(); i++) {
        AccessControlEntry ace = aces.get(i);
        if (permissionsService.isPermissionSet(ace.getPermission().getMask(), (AclPermission) AclPermission.READ)) {
            Permission updated = permissionFactory.buildFromMask(ace.getPermission().getMask() & readBits);
            AccessControlEntry newAce = new AccessControlEntryImpl(ace.getId(), ace.getAcl(), ace.getSid(), updated, true, false, false);
            newAces.add(newAce);
        }
    }
    clearAces(acl);
    for (int i = 0; i < newAces.size(); i++) {
        AccessControlEntry newAce = newAces.get(i);
        acl.insertAce(i, newAce.getPermission(), newAce.getSid(), true);
    }
    aclService.updateAcl(acl);
    if (entity instanceof AbstractHierarchicalEntity) {
        AbstractHierarchicalEntity tree = (AbstractHierarchicalEntity) entity;
        if (!CollectionUtils.isEmpty(tree.getChildren())) {
            tree.getChildren().forEach(this::clearWriteExecutePermissions);
        }
        if (!CollectionUtils.isEmpty(tree.getLeaves())) {
            tree.getLeaves().forEach(this::clearWriteExecutePermissions);
        }
    }
}
Also used : AccessControlEntryImpl(org.springframework.security.acls.domain.AccessControlEntryImpl) ArrayList(java.util.ArrayList) AclPermission(com.epam.pipeline.security.acl.AclPermission) EntityPermission(com.epam.pipeline.entity.security.acl.EntityPermission) Permission(org.springframework.security.acls.model.Permission) AccessControlEntry(org.springframework.security.acls.model.AccessControlEntry) MutableAcl(org.springframework.security.acls.model.MutableAcl) AbstractHierarchicalEntity(com.epam.pipeline.entity.AbstractHierarchicalEntity)

Example 2 with AbstractHierarchicalEntity

use of com.epam.pipeline.entity.AbstractHierarchicalEntity in project cloud-pipeline by epam.

the class FolderManager method deleteForce.

/**
 * Deletes a folder with all contents, specified by ID.
 * @param id of {@link Folder} to delete
 * @return deleted {@link Folder} instance
 */
public Folder deleteForce(Long id) {
    Folder folder = crudManager.load(id);
    if (!CollectionUtils.isEmpty(folder.getChildren())) {
        for (AbstractHierarchicalEntity hierarchicalEntity : folder.getChildren()) {
            deleteForce(hierarchicalEntity.getId());
        }
    }
    deleteChildren(folder);
    return folder;
}
Also used : AbstractHierarchicalEntity(com.epam.pipeline.entity.AbstractHierarchicalEntity) Folder(com.epam.pipeline.entity.pipeline.Folder)

Aggregations

AbstractHierarchicalEntity (com.epam.pipeline.entity.AbstractHierarchicalEntity)2 Folder (com.epam.pipeline.entity.pipeline.Folder)1 EntityPermission (com.epam.pipeline.entity.security.acl.EntityPermission)1 AclPermission (com.epam.pipeline.security.acl.AclPermission)1 ArrayList (java.util.ArrayList)1 AccessControlEntryImpl (org.springframework.security.acls.domain.AccessControlEntryImpl)1 AccessControlEntry (org.springframework.security.acls.model.AccessControlEntry)1 MutableAcl (org.springframework.security.acls.model.MutableAcl)1 Permission (org.springframework.security.acls.model.Permission)1