Search in sources :

Example 1 with PermissionServiceTrait

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

the class VirtualPermissionServiceExtension method getSetPermissions.

@Override
public NodePermissionEntry getSetPermissions(NodeRef nodeRef) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getSetPermissions(nodeRef);
    } else {
        NodePermissionEntry virtualSetPermissions = smartStore.getSetPermissions(reference);
        NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
        List<? extends PermissionEntry> actualPermissionEntries;
        boolean inheritPermissions = false;
        if (nodeToAdhereTo != null) {
            NodePermissionEntry actualSetPermissions = theTrait.getSetPermissions(nodeToAdhereTo);
            actualPermissionEntries = actualSetPermissions.getPermissionEntries();
            inheritPermissions = actualSetPermissions.inheritPermissions();
        } else {
            actualPermissionEntries = Collections.emptyList();
            inheritPermissions = false;
        }
        List<PermissionEntry> mergedEntries = new LinkedList<>();
        List<? extends PermissionEntry> virtualPermissionEntries = virtualSetPermissions.getPermissionEntries();
        Set<QName> overridenPermissions = new HashSet<>();
        for (PermissionEntry permissionEntry : virtualPermissionEntries) {
            overridenPermissions.add(permissionEntry.getPermissionReference().getQName());
            mergedEntries.add(permissionEntry);
        }
        for (PermissionEntry permissionEntry : actualPermissionEntries) {
            if (!overridenPermissions.contains(permissionEntry.getPermissionReference().getQName())) {
                mergedEntries.add(permissionEntry);
            }
        }
        return new SimpleNodePermissionEntry(nodeRef, inheritPermissions, mergedEntries);
    }
}
Also used : PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) QName(org.alfresco.service.namespace.QName) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) PermissionEntry(org.alfresco.repo.security.permissions.PermissionEntry) NodePermissionEntry(org.alfresco.repo.security.permissions.NodePermissionEntry) SimpleNodePermissionEntry(org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry) HashSet(java.util.HashSet)

Example 2 with PermissionServiceTrait

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

the class VirtualPermissionServiceExtension method getPermissions.

@Override
public Set<AccessPermission> getPermissions(NodeRef nodeRef) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getPermissions(nodeRef);
    } else {
        Set<AccessPermission> virtualSetPermissions = smartStore.getAllSetPermissions(reference);
        NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
        Set<AccessPermission> mergedEntries = new HashSet<>(virtualSetPermissions);
        if (nodeToAdhereTo != null) {
            Set<AccessPermission> actualSetPermissions = theTrait.getPermissions(nodeToAdhereTo);
            mergedEntries.addAll(actualSetPermissions);
        }
        return mergedEntries;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) HashSet(java.util.HashSet)

Example 3 with PermissionServiceTrait

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

the class VirtualPermissionServiceExtension method getAllSetPermissions.

@Override
public Set<AccessPermission> getAllSetPermissions(NodeRef nodeRef) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.getAllSetPermissions(nodeRef);
    } else {
        Set<AccessPermission> virtualSetPermissions = smartStore.getAllSetPermissions(reference);
        NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
        Set<AccessPermission> actualSetPermissions;
        if (nodeToAdhereTo != null) {
            actualSetPermissions = theTrait.getAllSetPermissions(nodeToAdhereTo);
        } else {
            actualSetPermissions = Collections.emptySet();
        }
        Set<String> overridenPermissions = new HashSet<>();
        Set<AccessPermission> mergedEntries = new HashSet<>();
        for (AccessPermission permission : virtualSetPermissions) {
            overridenPermissions.add(permission.getPermission());
            mergedEntries.add(permission);
        }
        for (AccessPermission permission : actualSetPermissions) {
            if (!overridenPermissions.contains(permission.getPermission())) {
                mergedEntries.add(permission);
            }
        }
        return mergedEntries;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) AccessPermission(org.alfresco.service.cmr.security.AccessPermission) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) HashSet(java.util.HashSet)

Example 4 with PermissionServiceTrait

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

the class VirtualPermissionServiceExtension method hasPermission.

public AccessStatus hasPermission(NodeRef nodeRef, PermissionReference perm) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.hasPermission(nodeRef, perm);
    } else {
        AccessStatus virtualAccessStatus = smartStore.hasPermission(reference, perm);
        if (!AccessStatus.UNDETERMINED.equals(virtualAccessStatus)) {
            return virtualAccessStatus;
        } else {
            NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
            if (nodeToAdhereTo == null) {
                return AccessStatus.UNDETERMINED;
            } else {
                return theTrait.hasPermission(nodeToAdhereTo, perm);
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) AccessStatus(org.alfresco.service.cmr.security.AccessStatus)

Example 5 with PermissionServiceTrait

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

the class VirtualPermissionServiceExtension method hasPermission.

public AccessStatus hasPermission(NodeRef nodeRef, String perm) {
    PermissionServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(nodeRef);
    if (reference == null) {
        return theTrait.hasPermission(nodeRef, perm);
    } else {
        AccessStatus virtualAccessStatus = smartStore.hasPermission(reference, perm);
        if (!AccessStatus.UNDETERMINED.equals(virtualAccessStatus)) {
            return virtualAccessStatus;
        } else {
            NodeRef nodeToAdhereTo = establishPermisisonAdherence(reference);
            if (nodeToAdhereTo == null) {
                return AccessStatus.UNDETERMINED;
            } else {
                return theTrait.hasPermission(nodeToAdhereTo, perm);
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PermissionReference(org.alfresco.repo.security.permissions.PermissionReference) Reference(org.alfresco.repo.virtual.ref.Reference) PermissionServiceTrait(org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait) AccessStatus(org.alfresco.service.cmr.security.AccessStatus)

Aggregations

PermissionReference (org.alfresco.repo.security.permissions.PermissionReference)5 PermissionServiceTrait (org.alfresco.repo.security.permissions.impl.traitextender.PermissionServiceTrait)5 Reference (org.alfresco.repo.virtual.ref.Reference)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 HashSet (java.util.HashSet)3 AccessPermission (org.alfresco.service.cmr.security.AccessPermission)2 AccessStatus (org.alfresco.service.cmr.security.AccessStatus)2 LinkedList (java.util.LinkedList)1 NodePermissionEntry (org.alfresco.repo.security.permissions.NodePermissionEntry)1 PermissionEntry (org.alfresco.repo.security.permissions.PermissionEntry)1 SimpleNodePermissionEntry (org.alfresco.repo.security.permissions.impl.SimpleNodePermissionEntry)1 QName (org.alfresco.service.namespace.QName)1