Search in sources :

Example 21 with Relationship

use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.

the class PsoUtil method loadGraph.

/**
 * Read this ldap record,{@code cn=Hierarchies, ou=OS-P} into this entity, {@link Hier}, before loading into this collection class,{@code org.jgrapht.graph.SimpleDirectedGraph}
 * using 3rd party lib, <a href="http://www.jgrapht.org/">JGraphT</a>.
 *
 * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
 * @return handle to simple digraph containing perm ou hierarchies.
 */
private synchronized SimpleDirectedGraph<String, Relationship> loadGraph(String contextId) {
    Hier inHier = new Hier(Hier.Type.ROLE);
    inHier.setContextId(contextId);
    LOG.info("loadGraph initializing PSO context [{}]", inHier.getContextId());
    List<Graphable> descendants = null;
    try {
        OrgUnit orgUnit = new OrgUnit();
        orgUnit.setType(OrgUnit.Type.PERM);
        orgUnit.setContextId(contextId);
        descendants = orgUnitP.getAllDescendants(orgUnit);
    } catch (SecurityException se) {
        LOG.info("loadGraph caught SecurityException={}", se);
    }
    Hier hier = HierUtil.loadHier(contextId, descendants);
    SimpleDirectedGraph<String, Relationship> graph;
    graph = HierUtil.buildGraph(hier);
    psoCache.put(getKey(contextId), graph);
    return graph;
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) Relationship(org.apache.directory.fortress.core.model.Relationship) SecurityException(org.apache.directory.fortress.core.SecurityException) Graphable(org.apache.directory.fortress.core.model.Graphable) Hier(org.apache.directory.fortress.core.model.Hier)

Example 22 with Relationship

use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.

the class HierUtil method getAscendants.

/**
 * Utility function recursively traverses a given digraph to build a set of all ascendant names.
 *
 * @param vertex     contains the position of the cursor for traversal of graph.
 * @param graph      contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}.
 * @param ascendants contains the result set of ascendant names.
 * @return value contains the vertex of current position.
 */
private static String getAscendants(Map<String, String> vertex, SimpleDirectedGraph<String, Relationship> graph, Set<String> ascendants) {
    String v = vertex.get(VERTEX);
    if (v == null) {
        return null;
    } else if (graph == null) {
        return null;
    }
    LOG.debug("getAscendants [{}]", v);
    Set<Relationship> edges;
    try {
        edges = graph.outgoingEdgesOf(v);
    } catch (java.lang.IllegalArgumentException iae) {
        // vertex is leaf.
        return null;
    }
    for (Relationship edge : edges) {
        vertex.put(VERTEX, edge.getParent());
        ascendants.add(edge.getParent());
        v = getAscendants(vertex, graph, ascendants);
    }
    return v;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship)

Example 23 with Relationship

use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.

the class HierUtil method toGraph.

/**
 * This method converts from physical ldap entity format, {@link Hier} to logical {@code org.jgrapht.graph.SimpleDirectedGraph}.
 *
 * @param hier contains parent-child relationship in preparation to storing in ldap {@code ftRels} attribute of {@code ftHier} object class.
 * @return {@code org.jgrapht.graph.SimpleDirectedGraph} containing the vertices of {@code String}, and edges, as {@link Relationship}s that correspond to relational data.
 */
private static SimpleDirectedGraph<String, Relationship> toGraph(Hier hier) {
    LOG.debug("toGraph");
    SimpleDirectedGraph<String, Relationship> graph = new SimpleDirectedGraph<>(Relationship.class);
    List<Relationship> edges = hier.getRelationships();
    if (edges != null && edges.size() > 0) {
        for (Relationship edge : edges) {
            String child = edge.getChild();
            String parent = edge.getParent();
            try {
                graph.addVertex(child);
                graph.addVertex(parent);
                graph.addEdge(child, parent, edge);
            } catch (java.lang.IllegalArgumentException e) {
                String error = "toGraph child: " + child + " parent: " + parent + " caught IllegalArgumentException=" + e;
                LOG.error(error);
            }
            LOG.debug("toGraph child={}, parent={}", child, parent);
        }
    }
    return graph;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship) SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph)

Example 24 with Relationship

use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.

the class HierUtil method loadHier.

/**
 * This method will retrieve the list of all parent-child relationships for a given node.  If the node was not found in
 * ldap this method will create a new node and store default data.
 * The following ldap nodes are currently storing hierarchical data:
 * <ol>
 * <li>RBAC Role relations are stored in {@code cn=Hierarchies,ou=Roles,ou=RBAC} ldap node and cached as singleton in {@link RoleUtil}</li>
 * <li>ARBAC Admin Role relations are stored in {@code cn=Hierarchies,ou=AdminRoles,ou=ARBAC} ldap node and cached as singleton in {@link AdminRoleUtil}</li>
 * <li>User Organizational Unit relations are stored in {@code cn=Hierarchies,ou=OS-U,ou=ARBAC} node and cached as {@link org.apache.directory.fortress.core.impl.UsoUtil}</li>
 * <li>Permission Organizational Unit relations are stored in {@code cn=Hierarchies,ou=OS-P,ou=ARBAC} node and cached as {@link org.apache.directory.fortress.core.impl.PsoUtil}</li>
 * </ol>
 *
 * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
 * @return reference the the Hier result set retrieved from ldap.
 */
static Hier loadHier(String contextId, List<Graphable> descendants) {
    Hier hier = new Hier();
    if (CollectionUtils.isNotEmpty(descendants)) {
        hier.setContextId(contextId);
        for (Graphable descendant : descendants) {
            Set<String> parents = descendant.getParents();
            if (CollectionUtils.isNotEmpty(parents)) {
                for (String parent : parents) {
                    Relationship relationship = new Relationship();
                    relationship.setChild(descendant.getName().toUpperCase());
                    relationship.setParent(parent.toUpperCase());
                    hier.setRelationship(relationship);
                }
            }
        }
    }
    return hier;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship) Graphable(org.apache.directory.fortress.core.model.Graphable) Hier(org.apache.directory.fortress.core.model.Hier)

Example 25 with Relationship

use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.

the class HierUtil method getChildren.

/**
 * Utility function returns a set of all children (direct descendant) names.
 *
 * @param vertex contains the position of the cursor for traversal of graph.
 * @param graph  contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}.
 * @return value contains the vertex of current position.
 */
static Set<String> getChildren(String vertex, SimpleDirectedGraph<String, Relationship> graph) {
    Set<String> descendants = new HashSet<>();
    if (graph == null) {
        // graph is null
        return null;
    }
    LOG.debug("getChildren [{}]", vertex);
    Set<Relationship> edges;
    try {
        edges = graph.incomingEdgesOf(vertex);
    } catch (java.lang.IllegalArgumentException iae) {
        // vertex is leaf.
        return null;
    }
    for (Relationship edge : edges) {
        descendants.add(edge.getChild());
    }
    return descendants;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship) HashSet(java.util.HashSet)

Aggregations

Relationship (org.apache.directory.fortress.core.model.Relationship)32 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)15 AdminRole (org.apache.directory.fortress.core.model.AdminRole)10 SecurityException (org.apache.directory.fortress.core.SecurityException)9 Role (org.apache.directory.fortress.core.model.Role)7 UserRole (org.apache.directory.fortress.core.model.UserRole)7 Hier (org.apache.directory.fortress.core.model.Hier)6 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)6 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)6 Graphable (org.apache.directory.fortress.core.model.Graphable)5 User (org.apache.directory.fortress.core.model.User)4 PermObj (org.apache.directory.fortress.core.model.PermObj)3 HashSet (java.util.HashSet)2 Permission (org.apache.directory.fortress.core.model.Permission)2 SimpleDirectedGraph (org.jgrapht.graph.SimpleDirectedGraph)2 org.apache.directory.fortress.core (org.apache.directory.fortress.core)1 Constraint (org.apache.directory.fortress.core.model.Constraint)1 Group (org.apache.directory.fortress.core.model.Group)1 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)1 SDSet (org.apache.directory.fortress.core.model.SDSet)1