Search in sources :

Example 6 with Security

use of org.structr.core.entity.Security in project structr by structr.

the class DeployCommand method exportOwnershipAndSecurity.

private void exportOwnershipAndSecurity(final NodeInterface node, final Map<String, Object> config) {
    // export unique name of owner node to pages.json
    final Principal owner = node.getOwnerNode();
    if (owner != null) {
        final Map<String, Object> map = new HashMap<>();
        map.put("name", owner.getName());
        config.put("owner", map);
    }
    // export security grants
    final List<Map<String, Object>> grantees = new LinkedList<>();
    for (final Security security : node.getSecurityRelationships()) {
        if (security != null) {
            final Map<String, Object> grant = new TreeMap<>();
            grant.put("name", security.getSourceNode().getProperty(AbstractNode.name));
            final String allowedActions = StringUtils.join(security.getPermissions(), ",");
            grant.put("allowed", allowedActions);
            if (allowedActions.length() > 0) {
                grantees.add(grant);
            }
        }
    }
    // export non-empty collection only
    if (!grantees.isEmpty()) {
        config.put("grantees", grantees);
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Security(org.structr.core.entity.Security) TreeMap(java.util.TreeMap) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PropertyMap(org.structr.core.property.PropertyMap) TreeMap(java.util.TreeMap) Principal(org.structr.core.entity.Principal) LinkedList(java.util.LinkedList)

Aggregations

Security (org.structr.core.entity.Security)6 Principal (org.structr.core.entity.Principal)5 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 FrameworkException (org.structr.common.error.FrameworkException)2 GraphObject (org.structr.core.GraphObject)2 AbstractNode (org.structr.core.entity.AbstractNode)2 PrincipalOwnsNode (org.structr.core.entity.relationship.PrincipalOwnsNode)2 NodeInterface (org.structr.core.graph.NodeInterface)2 PropertyKey (org.structr.core.property.PropertyKey)2 PropertyMap (org.structr.core.property.PropertyMap)2 IOException (java.io.IOException)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1