Search in sources :

Example 1 with PermissionPropagation

use of org.structr.common.PermissionPropagation in project structr by structr.

the class AbstractNode method hasEffectivePermissions.

private boolean hasEffectivePermissions(final BFSInfo parent, final Principal principal, final Permission permission, final PermissionResolutionMask mask, final int level, final AlreadyTraversed alreadyTraversed, final Queue<BFSInfo> bfsNodes, final boolean doLog) {
    // check nodes here to avoid circles in permission-propagating relationships
    if (alreadyTraversed.contains("Node", dbNode.getId())) {
        return false;
    }
    for (final Class<Relation> propagatingType : SchemaRelationshipNode.getPropagatingRelationshipTypes()) {
        final Relation template = getRelationshipForType(propagatingType);
        final Direction direction = template.getDirectionForType(entityType);
        // skip relationship type if it is not applicable for the current node type
        if (Direction.BOTH.equals(direction)) {
            continue;
        }
        // iterate over list of relationships
        final Iterable<Relation> iterable = getRelationshipsAsSuperUser(propagatingType);
        for (final Relation source : iterable) {
            if (source instanceof PermissionPropagation) {
                final PermissionPropagation perm = (PermissionPropagation) source;
                final RelationshipInterface rel = (RelationshipInterface) source;
                // check propagation direction vs. evaluation direction
                if (propagationAllowed(this, rel, perm.getPropagationDirection(), doLog)) {
                    applyCurrentStep(perm, mask);
                    if (mask.allowsPermission(permission)) {
                        final AbstractNode otherNode = (AbstractNode) rel.getOtherNode(this);
                        if (otherNode.isGranted(permission, principal, mask, level + 1, alreadyTraversed, false, doLog)) {
                            otherNode.storePermissionResolutionResult(principal.getId(), permission, true);
                            // break early
                            return true;
                        } else {
                            // add node to BFS queue
                            bfsNodes.add(new BFSInfo(parent, otherNode));
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : PermissionPropagation(org.structr.common.PermissionPropagation) RelationshipInterface(org.structr.core.graph.RelationshipInterface) Direction(org.structr.api.graph.Direction)

Aggregations

Direction (org.structr.api.graph.Direction)1 PermissionPropagation (org.structr.common.PermissionPropagation)1 RelationshipInterface (org.structr.core.graph.RelationshipInterface)1