Search in sources :

Example 66 with FinderException

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

the class AdminRoleDAO method getRole.

/**
 * This method will retrieve the AdminRole from {@link GlobalIds#ADMIN_ROLE_ROOT} container by name.
 *
 * @param adminRole maps to {@link AdminRole#name}.
 * @return AdminRole back to client.
 * @throws FinderException in the event LDAP errors occur.
 */
AdminRole getRole(AdminRole adminRole) throws FinderException {
    AdminRole entity = null;
    LdapConnection ld = null;
    String dn = getDn(adminRole);
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, ROLE_ATRS);
        if (findEntry != null) {
            entity = unloadLdapEntry(findEntry, 0, adminRole.getContextId());
        }
        if (entity == null) {
            String warning = "getRole name [" + adminRole.getName() + "] no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.ARLE_NOT_FOUND, warning);
        }
    } catch (LdapNoSuchObjectException e) {
        String warning = "getRole name [" + adminRole.getName() + "] Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.ARLE_NOT_FOUND, warning, e);
    } catch (LdapException e) {
        String error = "getRole dn [" + dn + "] LEXCD=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) FinderException(org.apache.directory.fortress.core.FinderException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AdminRole(org.apache.directory.fortress.core.model.AdminRole) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 67 with FinderException

use of org.apache.directory.fortress.core.FinderException 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 68 with FinderException

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

the class RoleDAO method groupRoles.

/**
 * Pull back all roles that are assigned to a particular group.
 * @param group
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Role> groupRoles(Group group) throws FinderException {
    List<Role> roleList = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(group.getContextId(), GlobalIds.ROLE_ROOT);
    StringBuilder filterbuf = new StringBuilder();
    try {
        // loop for each group member....
        // add role name to search filter
        // 
        List<String> members = group.getMembers();
        if (CollectionUtils.isNotEmpty(members)) {
            filterbuf.append(GlobalIds.FILTER_PREFIX);
            filterbuf.append(GlobalIds.ROLE_OBJECT_CLASS_NM);
            filterbuf.append(")(");
            filterbuf.append("|");
            for (String memberdn : members) {
                filterbuf.append("(");
                filterbuf.append(SchemaConstants.ENTRY_DN_AT);
                filterbuf.append("=");
                filterbuf.append(memberdn);
                filterbuf.append(")");
            }
            filterbuf.append("))");
            ld = getAdminConnection();
            SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filterbuf.toString(), ROLE_ATRS, false, GlobalIds.BATCH_SIZE);
            long sequence = 0;
            while (searchResults.next()) {
                roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, group.getContextId()));
            }
        } else {
            String error = "groupRoles passed empty member list";
            throw new FinderException(GlobalErrIds.GROUP_MEMBER_NULL, error);
        }
    } catch (LdapException e) {
        String error = "groupRoles filter [" + filterbuf.toString() + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "groupRoles filter [" + filterbuf.toString() + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) 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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 69 with FinderException

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

the class RoleDAO method getRole.

/**
 * @param role
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Role getRole(Role role) throws FinderException {
    Role entity = null;
    LdapConnection ld = null;
    String dn = getDn(role.getName(), role.getContextId());
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, ROLE_ATRS);
        if (findEntry != null) {
            entity = unloadLdapEntry(findEntry, 0, role.getContextId());
        }
        if (entity == null) {
            String warning = "getRole no entry found dn [" + dn + "]";
            throw new FinderException(GlobalErrIds.ROLE_NOT_FOUND, warning);
        }
    } catch (LdapNoSuchObjectException e) {
        String warning = "getRole Obj COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.ROLE_NOT_FOUND, warning);
    } catch (LdapException e) {
        String error = "getRole dn [" + dn + "] LEXCD=" + e;
        throw new FinderException(GlobalErrIds.ROLE_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return entity;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) LdapNoSuchObjectException(org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException) FinderException(org.apache.directory.fortress.core.FinderException) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 70 with FinderException

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

the class RoleDAO method findRoles.

/**
 * @param role
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Role> findRoles(Role role) throws FinderException {
    List<Role> roleList = new ArrayList<>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(role.getContextId(), GlobalIds.ROLE_ROOT);
    String filter = null;
    try {
        String searchVal = encodeSafeText(role.getName(), GlobalIds.ROLE_LEN);
        filter = GlobalIds.FILTER_PREFIX + GlobalIds.ROLE_OBJECT_CLASS_NM + ")(" + ROLE_NM + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, roleRoot, SearchScope.ONELEVEL, filter, ROLE_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            roleList.add(unloadLdapEntry(searchResults.getEntry(), sequence++, role.getContextId()));
        }
    } catch (LdapException e) {
        String error = "findRoles filter [" + filter + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findRoles filter [" + filter + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ROLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) 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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

FinderException (org.apache.directory.fortress.core.FinderException)80 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)72 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)72 ArrayList (java.util.ArrayList)49 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)48 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)48 Entry (org.apache.directory.api.ldap.model.entry.Entry)22 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)21 LdapNoSuchObjectException (org.apache.directory.api.ldap.model.exception.LdapNoSuchObjectException)17 Permission (org.apache.directory.fortress.core.model.Permission)10 User (org.apache.directory.fortress.core.model.User)8 SecurityException (org.apache.directory.fortress.core.SecurityException)7 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)6 Modification (org.apache.directory.api.ldap.model.entry.Modification)6 UpdateException (org.apache.directory.fortress.core.UpdateException)6 Role (org.apache.directory.fortress.core.model.Role)6 UserRole (org.apache.directory.fortress.core.model.UserRole)6 OrgUnit (org.apache.directory.fortress.core.model.OrgUnit)5 AdminRole (org.apache.directory.fortress.core.model.AdminRole)4 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)4