use of org.apache.directory.api.ldap.model.cursor.SearchCursor 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.api.ldap.model.cursor.SearchCursor 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.api.ldap.model.cursor.SearchCursor 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.api.ldap.model.cursor.SearchCursor in project directory-fortress-core by apache.
the class LdapDataProvider method deleteRecursive.
/**
* Used to recursively remove all nodes up to record pointed to by dn attribute.
*
* @param dn contains distinguished node of entry targeted for removal..
* @param connection handle to ldap connection.
* @param recursiveCount keeps track of how many iterations have been performed.
* @throws LdapException in the event system error occurs.
* @throws CursorException
*/
private void deleteRecursive(String dn, LdapConnection connection, int recursiveCount) throws LdapException, CursorException {
String method = "deleteRecursive";
// Sanity check - only allow max tree depth of 100
if (recursiveCount++ > MAX_DEPTH) {
// too deep inside of a recursive sequence;
String error = "." + method + " dn [" + dn + "] depth error in recursive";
throw new LdapOperationErrorException(error);
}
String theDN;
// Find child nodes
SearchCursor cursor = search(connection, dn, SearchScope.ONELEVEL, "(objectclass=*)", SchemaConstants.NO_ATTRIBUTE_ARRAY, false, 0);
// Iterate over all entries under this entry
while (cursor.next()) {
try {
// Next directory entry
Entry entry = cursor.getEntry();
theDN = entry.getDn().getName();
// continue down:
deleteRecursive(theDN, connection, recursiveCount);
recursiveCount--;
} catch (LdapException le) {
// cannot continue;
String error = "." + method + " dn [" + dn + "] caught LdapException=" + le.getMessage();
throw new LdapException(error);
}
}
// delete the node:
COUNTERS.incrementDelete();
delete(connection, dn);
}
use of org.apache.directory.api.ldap.model.cursor.SearchCursor in project midpoint by Evolveum.
the class AbstractLdapTest method ldapSearch.
protected List<Entry> ldapSearch(LdapNetworkConnection connection, String baseDn, String filter, SearchScope scope, String... attributes) throws LdapException, CursorException {
logger.trace("LDAP search base={}, filter={}, scope={}, attributes={}", baseDn, filter, scope, attributes);
SearchRequest searchRequest = new SearchRequestImpl();
searchRequest.setBase(new Dn(baseDn));
searchRequest.setFilter(filter);
searchRequest.setScope(scope);
searchRequest.addAttributes(attributes);
searchRequest.ignoreReferrals();
List<Entry> entries = new ArrayList<>();
try {
SearchCursor searchCursor = connection.search(searchRequest);
while (searchCursor.next()) {
Response response = searchCursor.get();
if (response instanceof SearchResultEntry) {
Entry entry = ((SearchResultEntry) response).getEntry();
entries.add(entry);
}
}
searchCursor.close();
} catch (IOException e) {
throw new IllegalStateException("IO Error: " + e.getMessage(), e);
} catch (CursorLdapReferralException e) {
throw new IllegalStateException("Got referral to: " + e.getReferralInfo(), e);
}
return entries;
}
Aggregations