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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations