use of org.opends.server.protocols.internal.InternalSearchOperation in project midpoint by Evolveum.
the class OpenDJController method dumpEntries.
public String dumpEntries() throws DirectoryException {
InternalSearchOperation op = getInternalConnection().processSearch(ldapSuffix, SearchScope.WHOLE_SUBTREE, DereferencePolicy.NEVER_DEREF_ALIASES, 100, 100, false, "(objectclass=*)", getSearchAttributes());
StringBuilder sb = new StringBuilder();
for (SearchResultEntry searchEntry : op.getSearchEntries()) {
sb.append(toHumanReadableLdifoid(searchEntry));
sb.append("\n");
}
return sb.toString();
}
use of org.opends.server.protocols.internal.InternalSearchOperation in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method search.
/**
* Returns LDAP entries that match the filter, using the start DN provided
* in method
*/
public Set<String> search(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder) throws SSOException, SMSException {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.search: startDN = " + startDN + ", filter: " + filter);
}
InternalSearchOperation iso = searchObjects(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, sortResults, ascendingOrder);
ResultCode resultCode = iso.getResultCode();
if (resultCode == ResultCode.SIZE_LIMIT_EXCEEDED) {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.search:" + " size limit exceeded. numOfEntries = " + numOfEntries);
}
} else if (resultCode != ResultCode.SUCCESS) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.search: Unable to " + "search. startDN = " + startDN + ", filter = " + filter + ", resultCode = " + resultCode);
}
throw new SMSException("", "sms-error-in-searching");
}
Set<String> answer = new LinkedHashSet<>();
for (SearchResultEntry entry : iso.getSearchEntries()) {
String dn = entry.getName().toString();
answer.add(dn);
}
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.search: returned " + "successfully: " + filter + "\n\tObjects: " + answer);
}
return answer;
}
use of org.opends.server.protocols.internal.InternalSearchOperation in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method read.
/**
* Reads in the object from persistent store, assuming that the guid and the
* SSOToken are valid
*/
public Map read(SSOToken token, String dn) throws SMSException, SSOException {
if (dn == null || dn.length() == 0) {
// This must not be possible return an exception.
debug.error("SMSEmbeddedLdapObject.read: Null or Empty DN=" + dn);
throw new SMSException("", "sms-NO_SUCH_OBJECT");
}
if (!LDAPUtils.isDN(dn)) {
debug.warning("SMSEmbeddedLdapObject: Invalid DN=" + dn);
String[] args = { dn };
throw new SMSException(IUMSConstants.UMS_BUNDLE_NAME, "sms-INVALID_DN", args);
}
// Check if entry does not exist
if (SMSNotificationManager.isCacheEnabled() && entriesNotPresent.contains(dn)) {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject:read Entry not present: " + dn + " (checked in cached)");
}
return (null);
}
try {
SearchRequest request = Requests.newSearchRequest(dn, SearchScope.BASE_OBJECT, "(objectclass=*)", smsAttributes.toArray(new String[smsAttributes.size()]));
InternalSearchOperation iso = icConn.processSearch(request);
ResultCode resultCode = iso.getResultCode();
if (resultCode == ResultCode.SUCCESS) {
LinkedList searchResult = iso.getSearchEntries();
if (!searchResult.isEmpty()) {
SearchResultEntry entry = (SearchResultEntry) searchResult.get(0);
List attributes = entry.getAttributes();
return EmbeddedSearchResultIterator.convertLDAPAttributeSetToMap(attributes);
} else {
return null;
}
} else if (resultCode == ResultCode.NO_SUCH_OBJECT) {
// Add to not present Set
objectChanged(dn, DELETE);
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.read: " + "entry not present:" + dn);
}
return null;
} else {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.read: " + "Error in accessing entry DN: " + dn + ", error code = " + resultCode);
}
throw new SMSException("", "sms-entry-cannot-access");
}
} catch (DirectoryException dex) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.read: " + "Error in accessing entry DN: " + dn, dex);
}
throw new SMSException(dex, "sms-entry-cannot-access");
}
}
use of org.opends.server.protocols.internal.InternalSearchOperation in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method search.
public Iterator<SMSDataEntry> search(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Set excludes) throws SSOException, SMSException {
InternalSearchOperation iso = searchObjects(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, sortResults, ascendingOrder);
ResultCode resultCode = iso.getResultCode();
if (resultCode == ResultCode.SIZE_LIMIT_EXCEEDED) {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.search:" + " size limit exceeded. numOfEntries = " + numOfEntries);
}
} else if (resultCode != ResultCode.SUCCESS) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.searchEx: Unable to " + "search. startDN = " + startDN + ", filter = " + filter + ", resultCode = " + resultCode);
}
throw new SMSException("", "sms-error-in-searching");
}
LinkedList searchResult = iso.getSearchEntries();
return new EmbeddedSearchResultIterator(searchResult, excludes);
}
use of org.opends.server.protocols.internal.InternalSearchOperation in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method entryExists.
/**
* Checks if the provided DN exists.
*/
private static boolean entryExists(String dn) throws SMSException {
try {
SearchRequest request = Requests.newSearchRequest(dn, SearchScope.BASE_OBJECT, "(objectclass=*)");
InternalSearchOperation iso = icConn.processSearch(request);
ResultCode resultCode = iso.getResultCode();
if (resultCode == ResultCode.SUCCESS) {
return true;
} else if (resultCode == ResultCode.NO_SUCH_OBJECT || resultCode == ResultCode.CLIENT_SIDE_NO_RESULTS_RETURNED) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject:entryExists: " + dn + " does not exist. resultCode = " + resultCode);
}
return false;
} else {
throw new SMSException("Failed to find entry with DN: " + dn + " LDAP error result: " + resultCode, IUMSConstants.SMS_LDAP_OPERATION_FAILED);
}
} catch (DirectoryException dex) {
throw new SMSException("Failed to find entry with DN: " + dn, dex, IUMSConstants.SMS_LDAP_OPERATION_FAILED);
}
}
Aggregations