use of org.apache.directory.fortress.core.model.Graphable in project directory-fortress-core by apache.
the class RoleDAO method getAllDescendants.
/**
* @param contextId
* @return
* @throws FinderException
*/
List<Graphable> getAllDescendants(String contextId) throws FinderException {
String[] DESC_ATRS = { ROLE_NM, GlobalIds.PARENT_NODES };
List<Graphable> descendants = new ArrayList<>();
LdapConnection ld = null;
String roleRoot = getRootDn(contextId, GlobalIds.ROLE_ROOT);
String filter = null;
try {
filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + GlobalIds.PARENT_NODES + "=*))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, DESC_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
descendants.add(unloadDescendants(searchResults.getEntry(), sequence++, contextId));
}
} catch (LdapException e) {
String error = "getAllDescendants filter [" + filter + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "getAllDescendants filter [" + filter + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return descendants;
}
use of org.apache.directory.fortress.core.model.Graphable 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.Graphable in project directory-fortress-core by apache.
the class OrgUnitDAO method getAllDescendants.
/**
* @param orgUnit
* @return
* @throws FinderException
*/
List<Graphable> getAllDescendants(OrgUnit orgUnit) throws FinderException {
String orgUnitRoot = getOrgRoot(orgUnit);
String[] DESC_ATRS = { SchemaConstants.OU_AT, GlobalIds.PARENT_NODES };
List<Graphable> descendants = new ArrayList<>();
LdapConnection ld = null;
String filter = null;
try {
filter = GlobalIds.FILTER_PREFIX + ORGUNIT_OBJECT_CLASS_NM + ")(" + GlobalIds.PARENT_NODES + "=*))";
ld = getAdminConnection();
SearchCursor searchResults = search(ld, orgUnitRoot, SearchScope.ONELEVEL, filter, DESC_ATRS, false, GlobalIds.BATCH_SIZE);
long sequence = 0;
while (searchResults.next()) {
descendants.add(unloadDescendants(searchResults.getEntry(), sequence++, orgUnit.getContextId()));
}
} catch (LdapException e) {
String error = "getAllDescendants filter [" + filter + "] caught LdapException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} catch (CursorException e) {
String error = "getAllDescendants filter [" + filter + "] caught CursorException=" + e.getMessage();
throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
} finally {
closeAdminConnection(ld);
}
return descendants;
}
Aggregations