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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations