Search in sources :

Example 61 with FinderException

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

the class PermDAO method findPermissions.

/**
 * @param permObj
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<PermObj> findPermissions(PermObj permObj) throws FinderException {
    List<PermObj> permList = new ArrayList<>();
    LdapConnection ld = null;
    String permRoot = getRootDn(permObj.isAdmin(), permObj.getContextId());
    try {
        String permObjVal = encodeSafeText(permObj.getObjName(), GlobalIds.PERM_LEN);
        StringBuilder filterbuf = new StringBuilder();
        filterbuf.append(GlobalIds.FILTER_PREFIX);
        filterbuf.append(PERM_OBJ_OBJECT_CLASS_NAME);
        filterbuf.append(")(");
        filterbuf.append(GlobalIds.POBJ_NAME);
        filterbuf.append("=");
        filterbuf.append(permObjVal);
        filterbuf.append("*))");
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, permRoot, SearchScope.SUBTREE, filterbuf.toString(), PERMISION_OBJ_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            permList.add(unloadPobjLdapEntry(searchResults.getEntry(), sequence++, permObj.isAdmin()));
        }
    } catch (LdapException e) {
        String error = "findPermissions caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findPermissions caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PERM_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return permList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) PermObj(org.apache.directory.fortress.core.model.PermObj) 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 62 with FinderException

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

the class PolicyDAO method findPolicy.

/**
 * @param policy
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<PwPolicy> findPolicy(PwPolicy policy) throws FinderException {
    List<PwPolicy> policyArrayList = new ArrayList<>();
    LdapConnection ld = null;
    String policyRoot = getPolicyRoot(policy.getContextId());
    String searchVal = null;
    try {
        searchVal = encodeSafeText(policy.getName(), GlobalIds.PWPOLICY_NAME_LEN);
        String szFilter = GlobalIds.FILTER_PREFIX + PW_POLICY_CLASS + ")(" + PW_PWD_ID + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, policyRoot, SearchScope.ONELEVEL, szFilter, PASSWORD_POLICY_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            policyArrayList.add(unloadLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "findPolicy name [" + searchVal + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PSWD_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findPolicy name [" + searchVal + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PSWD_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return policyArrayList;
}
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) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) PwPolicy(org.apache.directory.fortress.core.model.PwPolicy) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 63 with FinderException

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

the class PolicyDAO method getPolicies.

/**
 * @return
 * @throws FinderException
 */
Set<String> getPolicies(String contextId) throws FinderException {
    Set<String> policySet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    LdapConnection ld = null;
    String policyRoot = getPolicyRoot(contextId);
    try {
        String szFilter = "(objectclass=" + PW_POLICY_CLASS + ")";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, policyRoot, SearchScope.ONELEVEL, szFilter, PASSWORD_POLICY_NAME_ATR, false, GlobalIds.BATCH_SIZE);
        while (searchResults.next()) {
            Entry entry = searchResults.getEntry();
            policySet.add(getAttribute(entry, PW_PWD_ID));
        }
    } catch (LdapException e) {
        String error = "getPolicies caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PSWD_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "getPolicies caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.PSWD_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return policySet;
}
Also used : 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) TreeSet(java.util.TreeSet) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) 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 64 with FinderException

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

the class AdminRoleDAO method findRoles.

/**
 * @param adminRole
 * @return
 * @throws FinderException
 */
List<AdminRole> findRoles(AdminRole adminRole) throws FinderException {
    List<AdminRole> roleList = new ArrayList<AdminRole>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(adminRole.getContextId(), GlobalIds.ADMIN_ROLE_ROOT);
    String filter;
    try {
        String searchVal = encodeSafeText(adminRole.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++, adminRole.getContextId()));
        }
    } catch (LdapException e) {
        String error = "findRoles name [" + adminRole.getName() + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findRoles name [" + adminRole.getName() + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
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) 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 65 with FinderException

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

the class AdminRoleDAO method findRoles.

/**
 * @param adminRole
 * @param limit
 * @return
 * @throws FinderException
 */
List<String> findRoles(AdminRole adminRole, int limit) throws FinderException {
    List<String> roleList = new ArrayList<String>();
    LdapConnection ld = null;
    String roleRoot = getRootDn(adminRole.getContextId(), GlobalIds.ADMIN_ROLE_ROOT);
    String filter;
    String searchVal = null;
    try {
        searchVal = encodeSafeText(adminRole.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_NM_ATR, false, limit);
        while (searchResults.next()) {
            Entry entry = searchResults.getEntry();
            roleList.add(getAttribute(entry, ROLE_NM));
        }
    } catch (LdapException e) {
        String error = "findRoles name [" + searchVal + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "findRoles name [" + searchVal + "] caught CursorException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.ARLE_SEARCH_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return roleList;
}
Also used : 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) 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