Search in sources :

Example 76 with FinderException

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

the class OrgUnitDAO method findOrgs.

/**
 * @param orgUnit
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<OrgUnit> findOrgs(OrgUnit orgUnit) throws FinderException {
    List<OrgUnit> orgUnitList = new ArrayList<>();
    LdapConnection ld = null;
    String orgUnitRoot = getOrgRoot(orgUnit);
    try {
        String searchVal = encodeSafeText(orgUnit.getName(), GlobalIds.ROLE_LEN);
        String filter = GlobalIds.FILTER_PREFIX + ORGUNIT_OBJECT_CLASS_NM + ")(" + SchemaConstants.OU_AT + "=" + searchVal + "*))";
        ld = getAdminConnection();
        SearchCursor searchResults = search(ld, orgUnitRoot, SearchScope.ONELEVEL, filter, ORGUNIT_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            orgUnitList.add(getEntityFromLdapEntry(searchResults.getEntry(), sequence++, orgUnit.getContextId()));
        }
    } catch (LdapException e) {
        String error = "findOrgs search val [" + orgUnit.getName() + "] type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught LdapException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } catch (CursorException e) {
        String error = "findOrgs search val [" + orgUnit.getName() + "] type [" + orgUnit.getType() + "] root [" + orgUnitRoot + "] caught CursorException=" + e;
        int errCode;
        if (orgUnit.getType() == OrgUnit.Type.PERM) {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_PERM;
        } else {
            errCode = GlobalErrIds.ORG_SEARCH_FAILED_USER;
        }
        throw new FinderException(errCode, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return orgUnitList;
}
Also used : OrgUnit(org.apache.directory.fortress.core.model.OrgUnit) 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 77 with FinderException

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

Example 78 with FinderException

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

the class AuditDAO method searchAdminMods.

/**
 * @param audit
 * @return
 * @throws FinderException
 */
List<Mod> searchAdminMods(UserAudit audit) throws FinderException {
    List<Mod> modList = new ArrayList<>();
    LdapConnection ld = null;
    String auditRoot = Config.getInstance().getProperty(AUDIT_ROOT);
    try {
        String filter = "(&(|(objectclass=" + ACCESS_MOD_CLASS_NM + ")";
        filter += "(objectclass=" + ACCESS_ADD_CLASS_NM + "))";
        if (StringUtils.isNotEmpty(audit.getDn())) {
            filter += "(" + REQDN + "=" + audit.getDn() + ")";
        }
        if (StringUtils.isNotEmpty(audit.getObjName())) {
            filter += "(|(" + REQMOD + "=" + GlobalIds.FT_MODIFIER_CODE + ":= " + audit.getObjName() + ".";
            if (StringUtils.isNotEmpty(audit.getOpName())) {
                filter += audit.getOpName();
            }
            filter += "*)";
            filter += "(" + REQMOD + "=" + GlobalIds.FT_MODIFIER_CODE + ":+ " + audit.getObjName() + ".";
            if (StringUtils.isNotEmpty(audit.getOpName())) {
                filter += audit.getOpName();
            }
            filter += "*))";
        }
        if (StringUtils.isNotEmpty(audit.getInternalUserId())) {
            filter += "(|(" + REQMOD + "=" + GlobalIds.FT_MODIFIER + ":= " + audit.getInternalUserId() + ")";
            filter += "(" + REQMOD + "=" + GlobalIds.FT_MODIFIER + ":+ " + audit.getInternalUserId() + "))";
        }
        if (audit.getBeginDate() != null) {
            String szTime = TUtil.encodeGeneralizedTime(audit.getBeginDate());
            filter += "(" + REQEND + ">=" + szTime + ")";
        }
        if (audit.getEndDate() != null) {
            String szTime = TUtil.encodeGeneralizedTime(audit.getEndDate());
            filter += "(" + REQEND + "<=" + szTime + ")";
        }
        filter += ")";
        // log.warn("filter=" + filter);
        ld = getLogConnection();
        SearchCursor searchResults = search(ld, auditRoot, SearchScope.ONELEVEL, filter, AUDIT_MOD_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            modList.add(getModEntityFromLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "searchAdminMods caught LdapException id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_MOD_ADMIN_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "searchAdminMods caught CursorException id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_MOD_ADMIN_SEARCH_FAILED, error, e);
    } finally {
        closeLogConnection(ld);
    }
    return modList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) Mod(org.apache.directory.fortress.core.model.Mod) 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 79 with FinderException

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

the class AuditDAO method searchBinds.

/**
 * @param audit
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
List<Bind> searchBinds(UserAudit audit) throws FinderException {
    List<Bind> auditList = new ArrayList<>();
    LdapConnection ld = null;
    String auditRoot = Config.getInstance().getProperty(AUDIT_ROOT);
    String userRoot = getRootDn(audit.getContextId(), GlobalIds.USER_ROOT);
    try {
        String filter;
        if (audit.getUserId() != null && audit.getUserId().length() > 0) {
            filter = GlobalIds.FILTER_PREFIX + ACCESS_BIND_CLASS_NM + ")(" + REQDN + "=" + SchemaConstants.UID_AT + "=" + audit.getUserId() + "," + userRoot + ")";
            if (audit.isFailedOnly()) {
                filter += "(" + REQRESULT + ">=" + 1 + ")";
            }
            if (audit.getBeginDate() != null) {
                String szTime = TUtil.encodeGeneralizedTime(audit.getBeginDate());
                filter += "(" + REQEND + ">=" + szTime + ")";
            }
            filter += ")";
        } else {
            filter = GlobalIds.FILTER_PREFIX + ACCESS_BIND_CLASS_NM + ")";
            if (audit.isFailedOnly()) {
                filter += "(" + REQRESULT + ">=" + 1 + ")";
            }
            if (audit.getBeginDate() != null) {
                String szTime = TUtil.encodeGeneralizedTime(audit.getBeginDate());
                filter += "(" + REQEND + ">=" + szTime + ")";
            }
            filter += ")";
        }
        // log.warn("filter=" + filter);
        ld = getLogConnection();
        SearchCursor searchResults = search(ld, auditRoot, SearchScope.ONELEVEL, filter, AUDIT_BIND_ATRS, false, GlobalIds.BATCH_SIZE);
        long sequence = 0;
        while (searchResults.next()) {
            auditList.add(getBindEntityFromLdapEntry(searchResults.getEntry(), sequence++));
        }
    } catch (LdapException e) {
        String error = "LdapException in AuditDAO.searchBinds id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_BIND_SEARCH_FAILED, error, e);
    } catch (CursorException e) {
        String error = "CursorException in AuditDAO.searchBinds id=" + e.getMessage();
        throw new FinderException(GlobalErrIds.AUDT_BIND_SEARCH_FAILED, error, e);
    } finally {
        closeLogConnection(ld);
    }
    return auditList;
}
Also used : FinderException(org.apache.directory.fortress.core.FinderException) Bind(org.apache.directory.fortress.core.model.Bind) 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 80 with FinderException

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

the class ConfigDAO method getConfig.

/**
 * @param name
 * @return
 * @throws org.apache.directory.fortress.core.FinderException
 */
Properties getConfig(String name) throws FinderException {
    Properties props = null;
    LdapConnection ld = null;
    String dn = getDn(name);
    LOG.info("getConfig dn [{}]", dn);
    try {
        ld = getAdminConnection();
        Entry findEntry = read(ld, dn, CONFIG_ATRS);
        props = PropUtil.getProperties(getAttributes(findEntry, GlobalIds.PROPS));
    } catch (LdapNoSuchObjectException e) {
        String warning = "getConfig COULD NOT FIND ENTRY for dn [" + dn + "]";
        throw new FinderException(GlobalErrIds.USER_NOT_FOUND, warning, e);
    } catch (LdapException e) {
        String error = "getConfig dn [" + dn + "] caught LdapException=" + e.getMessage();
        throw new FinderException(GlobalErrIds.FT_CONFIG_READ_FAILED, error, e);
    } finally {
        closeAdminConnection(ld);
    }
    return props;
}
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) Properties(java.util.Properties) 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