use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class AdminMgrConsole method toGraphNotUsed.
/**
* @param hier
* @return
* @throws org.apache.directory.fortress.core.SecurityException
*/
public static SimpleDirectedGraph<String, Relationship> toGraphNotUsed(Hier hier) {
LOG.info("toGraphX");
SimpleDirectedGraph<String, Relationship> graph = new SimpleDirectedGraph<>(Relationship.class);
// List<String> roles = hier.getRoles();
// if (roles != null)
// {
// for (String role : roles)
// {
// graph.addVertex(role);
// }
// }
List<Relationship> edges = hier.getRelationships();
if (edges != null && edges.size() > 0) {
for (Relationship edge : edges) {
String child = edge.getChild();
String parent = edge.getParent();
graph.addVertex(child);
graph.addVertex(parent);
graph.addEdge(child, parent, edge);
if (LOG.isDebugEnabled())
LOG.debug("toGraphX child=" + child + " parent=" + parent);
}
}
return graph;
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class AdminMgrConsole method toHierTest.
/**
* @param graph
* @return
* @throws org.apache.directory.fortress.core.SecurityException
*/
public static Hier toHierTest(UndirectedGraph<String, Relationship> graph) {
Hier he = new Hier();
Set<Relationship> eSet = graph.edgeSet();
for (Relationship edge : eSet) {
// Edge:(User : Root)
he.setRelationship(edge);
}
Set<String> vSet = graph.vertexSet();
for (String vertice : vSet) {
// he.addRole(vertice);
}
return he;
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class UsoUtil 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 user ou hierarchies.
*/
private synchronized SimpleDirectedGraph<String, Relationship> loadGraph(String contextId) {
Hier inHier = new Hier(Hier.Type.ROLE);
inHier.setContextId(contextId);
LOG.info("loadGraph initializing USO context [{}]", inHier.getContextId());
List<Graphable> descendants = null;
try {
OrgUnit orgUnit = new OrgUnit();
orgUnit.setType(OrgUnit.Type.USER);
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);
usoCache.put(getKey(contextId), graph);
return graph;
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class AdminMgrImpl method addDescendant.
/**
* {@inheritDoc}
*/
@Override
@AdminPermissionOperation
public void addDescendant(Role parentRole, Role childRole) throws SecurityException {
String methodName = "addDescendant";
assertContext(CLS_NM, methodName, parentRole, GlobalErrIds.PARENT_ROLE_NULL);
assertContext(CLS_NM, methodName, childRole, GlobalErrIds.CHILD_ROLE_NULL);
setEntitySession(CLS_NM, methodName, childRole);
// make sure the parent role is already there:
Role role = new Role(parentRole.getName());
role.setContextId(this.contextId);
roleP.read(role);
RoleUtil.getInstance().validateRelationship(childRole, parentRole, false);
childRole.setParent(parentRole.getName());
roleP.add(childRole);
RoleUtil.getInstance().updateHier(this.contextId, new Relationship(childRole.getName().toUpperCase(), parentRole.getName().toUpperCase()), Hier.Op.ADD);
}
use of org.apache.directory.fortress.core.model.Relationship in project directory-fortress-core by apache.
the class AdminMgrImpl method deleteRole.
/**
* {@inheritDoc}
*/
@Override
@AdminPermissionOperation
public void deleteRole(Role role) throws SecurityException {
String methodName = "deleteRole";
assertContext(CLS_NM, methodName, role, GlobalErrIds.ROLE_NULL);
setEntitySession(CLS_NM, methodName, role);
int numChildren = RoleUtil.getInstance().numChildren(role.getName(), role.getContextId());
if (numChildren > 0) {
String error = methodName + " role [" + role.getName() + "] must remove [" + numChildren + "] descendants before deletion";
LOG.error(error);
throw new SecurityException(GlobalErrIds.HIER_DEL_FAILED_HAS_CHILD, error, null);
}
// Read the Role from LDAP:
Role outRole = roleP.read(role);
outRole.setContextId(role.getContextId());
// deassign all groups assigned to this role first (because of schema's configGroup class constraints)
List<Group> groups = groupP.roleGroups(outRole);
for (Group group : groups) {
group.setContextId(this.contextId);
groupP.deassign(group, outRole.getDn());
}
// If user membership associated with role, remove the role object:
if (Config.getInstance().isRoleOccupant()) {
// this reads the role object itself:
List<User> users = userP.getAssignedUsers(role);
if (users != null) {
for (User ue : users) {
UserRole uRole = new UserRole(ue.getUserId(), role.getName());
setAdminData(CLS_NM, methodName, uRole);
deassignUser(uRole);
}
}
} else {
// search for all users assigned this role and deassign:
List<String> userIds = userP.getAssignedUserIds(role);
for (String userId : userIds) {
UserRole uRole = new UserRole(userId, role.getName());
setAdminData(CLS_NM, methodName, uRole);
deassignUser(uRole);
}
}
// Now remove the role association from all permissions:
permP.remove(role);
// remove all parent relationships from the role graph:
Set<String> parents = RoleUtil.getInstance().getParents(role.getName(), this.contextId);
if (parents != null) {
for (String parent : parents) {
RoleUtil.getInstance().updateHier(this.contextId, new Relationship(role.getName().toUpperCase(), parent.toUpperCase()), Hier.Op.REM);
}
}
// Finally, delete the role object:
roleP.delete(role);
}
Aggregations