use of org.opends.server.protocols.internal.SearchRequest 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.SearchRequest 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);
}
}
use of org.opends.server.protocols.internal.SearchRequest in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method getSubEntries.
private Set<String> getSubEntries(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
// Get the sub entries
try {
SearchRequest request = Requests.newSearchRequest(dn, SearchScope.SINGLE_LEVEL, filter, orgUnitAttr.toArray(new String[orgUnitAttr.size()]));
InternalSearchOperation iso = icConn.processSearch(request);
ResultCode resultCode = iso.getResultCode();
if (resultCode == ResultCode.NO_SUCH_OBJECT) {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.getSubEntries(): " + "entry not present:" + dn);
}
} else if (resultCode == ResultCode.SIZE_LIMIT_EXCEEDED) {
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.getSubEntries: " + "size limit " + numOfEntries + " exceeded for " + "sub-entries: " + dn);
}
} else if (resultCode != ResultCode.SUCCESS) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.getSubEntries: " + "Unable to search for " + "sub-entries: " + dn);
}
throw new SMSException("", "sms-entry-cannot-search");
}
// Construct the results and return
Set<String> answer = new LinkedHashSet<>();
LinkedList searchResult = iso.getSearchEntries();
for (Iterator iter = searchResult.iterator(); iter.hasNext(); ) {
SearchResultEntry entry = (SearchResultEntry) iter.next();
String edn = entry.getName().toString();
if (!edn.toLowerCase().startsWith("ou=")) {
continue;
}
String rdn = entry.getName().getRDN(0).getAttributeValue(0).toString();
answer.add(rdn);
}
if (debug.messageEnabled()) {
debug.message("SMSEmbeddedLdapObject.getSubEntries: " + "Successfully obtained sub-entries for : " + dn);
}
return answer;
} catch (DirectoryException dex) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.getSubEntries: " + "Unable to search for " + "sub-entries: " + dn, dex);
}
throw new SMSException(dex, "sms-entry-cannot-search");
}
}
use of org.opends.server.protocols.internal.SearchRequest in project OpenAM by OpenRock.
the class SMSEmbeddedLdapObject method searchObjects.
private InternalSearchOperation searchObjects(String startDN, String filter, SearchScope scope, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SSOException, SMSException {
// sorting is not implemented
try {
// Get the sub entries
SearchRequest request = Requests.newSearchRequest(startDN, scope, filter);
request.setSizeLimit(numOfEntries);
InternalSearchOperation iso = icConn.processSearch(request);
return iso;
} catch (DirectoryException dex) {
if (debug.warningEnabled()) {
debug.warning("SMSEmbeddedLdapObject.searchObjects: " + "Unable to " + "search. startDN = " + startDN + ", filter = " + filter, dex);
}
throw new SMSException(dex, "sms-error-in-searching");
}
}
Aggregations