Search in sources :

Example 11 with Relationship

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

the class HierUtil method getParents.

/**
 * Private utility to return the parents (direct ascendants) of a given child node.
 *
 * @param vertex contains node name and acts as cursor for current location.
 * @param graph  contains a reference to simple digraph {@code org.jgrapht.graph.SimpleDirectedGraph}.
 * @return Set of names that are parents of given child.
 */
static Set<String> getParents(String vertex, SimpleDirectedGraph<String, Relationship> graph) {
    Set<String> parents = new HashSet<>();
    if (graph == null) {
        // graph is null
        return null;
    }
    LOG.debug("getParents [{}]", vertex);
    Set<Relationship> edges;
    try {
        edges = graph.outgoingEdgesOf(vertex);
    } catch (java.lang.IllegalArgumentException iae) {
        // vertex is leaf.
        return null;
    }
    for (Relationship edge : edges) {
        parents.add(edge.getParent());
    }
    return parents;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship) HashSet(java.util.HashSet)

Example 12 with Relationship

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

the class HierUtil method getDescendants.

/**
 * Utility function recursively traverses a given digraph to build a set of all descendants 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 descendants contains the result set of names of all descendants of node.
 * @return value contains the vertex of current position.
 */
private static String getDescendants(Map<String, String> vertex, SimpleDirectedGraph<String, Relationship> graph, Set<String> descendants) {
    String v = vertex.get(VERTEX);
    if (v == null) {
        // vertex is null
        return null;
    } else if (graph == null) {
        // graph is null
        return null;
    }
    LOG.debug("getDescendants [{}]", v);
    Set<Relationship> edges;
    try {
        edges = graph.incomingEdgesOf(v);
    } catch (java.lang.IllegalArgumentException iae) {
        // vertex is leaf.
        return null;
    }
    for (Relationship edge : edges) {
        vertex.put(VERTEX, edge.getChild());
        descendants.add(edge.getChild());
        v = getDescendants(vertex, graph, descendants);
    }
    return v;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship)

Example 13 with Relationship

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

the class RoleUtil 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 role hierarchies.
 */
private synchronized SimpleDirectedGraph<String, Relationship> loadGraph(String contextId) {
    Hier inHier = new Hier(Hier.Type.ROLE);
    inHier.setContextId(contextId);
    LOG.info("loadGraph initializing ROLE context [{}]", inHier.getContextId());
    List<Graphable> descendants = null;
    try {
        descendants = roleP.getAllDescendants(inHier.getContextId());
    } catch (SecurityException se) {
        LOG.info("loadGraph caught SecurityException={}", se);
    }
    Hier hier = HierUtil.loadHier(contextId, descendants);
    SimpleDirectedGraph<String, Relationship> graph;
    graph = HierUtil.buildGraph(hier);
    roleCache.put(getKey(contextId), graph);
    return graph;
}
Also used : 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 14 with Relationship

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

the class AdminMgrConsole method getParents.

/**
 * @param g
 */
private static String getParents(Map vertex, SimpleDirectedGraph<String, Relationship> g, List<String> parents) {
    String v;
    // ReaderUtil.clearScreen();
    // System.out.println("addJGraph");
    // String vertex = "Max";
    v = (String) vertex.get("Vertex");
    if (g == null) {
        System.out.println("getAscendants simple directed graph is null");
        return null;
    }
    if (v == null) {
        System.out.println("getAscendants simple directed graph is null");
        return null;
    }
    System.out.println("getAscendants V [" + v + "]");
    Set<Relationship> edges = g.outgoingEdgesOf(v);
    for (Relationship edge : edges) {
        if (v == null)
            return null;
        else {
            System.out.println("Edge:" + edge);
            // parents.add(edge.toString());
            v = edge.toString();
            // Max : Super
            // getAscendants V <Super)>
            int indx = v.indexOf(GlobalIds.PROP_SEP);
            int indx2 = v.indexOf(')');
            if (indx >= 0) {
                v = v.substring(indx + 2, indx2);
            }
            // String parent =
            vertex.put("Vertex", v);
            if (!v.equalsIgnoreCase("Root"))
                parents.add(v);
            v = getParents(vertex, g, parents);
        }
    }
    return v;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship) Constraint(org.apache.directory.fortress.core.model.Constraint)

Example 15 with Relationship

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

the class Options method getRelationship.

/**
 */
public Relationship getRelationship() {
    Relationship relationship = new Relationship();
    relationship.setChild(getDescendant());
    relationship.setParent(getAscendant());
    return relationship;
}
Also used : Relationship(org.apache.directory.fortress.core.model.Relationship)

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