Search in sources :

Example 6 with Graphable

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;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) Graphable(org.apache.directory.fortress.core.model.Graphable) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 7 with Graphable

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;
}
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 8 with Graphable

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;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) ArrayList(java.util.ArrayList) SearchCursor(org.apache.directory.api.ldap.model.cursor.SearchCursor) Graphable(org.apache.directory.fortress.core.model.Graphable) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

Graphable (org.apache.directory.fortress.core.model.Graphable)8 Hier (org.apache.directory.fortress.core.model.Hier)5 Relationship (org.apache.directory.fortress.core.model.Relationship)5 SecurityException (org.apache.directory.fortress.core.SecurityException)4 ArrayList (java.util.ArrayList)3 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)3 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 FinderException (org.apache.directory.fortress.core.FinderException)3 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)3 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)2