use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SMSLdapObject method read.
/**
* Reads in the object from persistent store, assuming that the guid and the
* SSOToken are valid
*/
public Map<String, Set<String>> read(SSOToken token, String dn) throws SMSException, SSOException {
if (dn == null || dn.length() == 0) {
// This must not be possible return an exception.
debug.error("SMSLdapObject: read():Null or Empty DN=" + dn);
throw new SMSException(LdapException.newLdapException(ResultCode.NO_SUCH_OBJECT, getBundleString(IUMSConstants.SMS_INVALID_DN, dn)), "sms-NO_SUCH_OBJECT");
}
if (!LDAPUtils.isDN(dn)) {
debug.warning("SMSLdapObject: 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)) {
debug.message("SMSLdapObject:read Entry not present: {} (checked in cache)", dn);
return null;
}
Entry ldapEntry = null;
int retry = 0;
while (retry <= connNumRetry) {
debug.message("SMSLdapObject.read() retry: {}", retry);
ResultCode errorCode = null;
try (Connection conn = getConnection(token.getPrincipal())) {
ldapEntry = conn.searchSingleEntry(LDAPRequests.newSingleEntrySearchRequest(DN.valueOf(dn), getAttributeNames()));
break;
} catch (LdapException e) {
errorCode = e.getResult().getResultCode();
if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
// Add to not present Set
objectChanged(dn, DELETE);
debug.message("SMSLdapObject.read: entry not present: {}", dn);
break;
} else {
debug.warning("SMSLdapObject.read: Error in accessing entry DN: {}", dn, e);
throw new SMSException(e, "sms-entry-cannot-access");
}
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
// ignored
}
}
}
if (ldapEntry != null) {
if (debug.messageEnabled()) {
debug.message("SMSLdapObject.read(): reading entry: " + dn);
}
return SMSUtils.convertEntryToAttributesMap(ldapEntry);
} else {
return null;
}
}
use of org.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SMSLdapObject method getOrgNames.
private Set<String> getOrgNames(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
ConnectionEntryReader results = null;
int retry = 0;
SearchRequest request = getSearchRequest(dn, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, 0, sortResults, ascendingOrder, getOrgNamingAttribute(), O_ATTR);
while (retry <= connNumRetry) {
if (debug.messageEnabled()) {
debug.message("SMSLdapObject.getOrgNames() retry: " + retry);
}
try (Connection conn = getConnection(token.getPrincipal())) {
// Get the organization names
results = conn.search(request);
results.hasNext();
return toDNStrings(results, dn, ORG_CANNOT_OBTAIN);
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (!retryErrorCodes.contains(errorCode) || retry == connNumRetry) {
if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
debug.message("SMSLdapObject.getOrgNames(): org not present: {}", dn);
break;
} else {
debug.warning("SMSLdapObject.getOrgNames: Unable to search for organization names: {}", dn, e);
throw new SMSException(e, "sms-org-cannot-search");
}
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
// ignored
}
}
}
return Collections.emptySet();
}
use of org.forgerock.opendj.ldap.ResultCode 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.forgerock.opendj.ldap.ResultCode in project OpenAM by OpenRock.
the class SMSLdapObject method searchSubOrganizationNames.
private Set<String> searchSubOrganizationNames(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder, boolean recursive) throws SMSException, SSOException {
SearchRequest request = getSearchRequest(dn, filter, recursive ? SearchScope.WHOLE_SUBTREE : SearchScope.SINGLE_LEVEL, numOfEntries, 0, sortResults, ascendingOrder, getOrgNamingAttribute(), O_ATTR);
int retry = 0;
while (retry <= connNumRetry) {
if (debug.messageEnabled()) {
debug.message("SMSLdapObject.searchSubOrganizationNames() retry: " + retry);
}
try (Connection conn = getConnection(token.getPrincipal())) {
// Get the suborganization names
ConnectionEntryReader iterResults = conn.search(request);
iterResults.hasNext();
return toDNStrings(iterResults, dn, SUBORG_CANNOT_OBTAIN);
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
debug.message("SMSLdapObject.searchSubOrganizationNames(): suborg not present: {}", dn);
break;
} else {
debug.warning("SMSLdapObject.searchSubOrganizationName(): Unable to search: {}", dn, e);
throw new SMSException(e, "sms-suborg-cannot-search");
}
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
// ignored
}
}
}
return Collections.emptySet();
}
use of org.forgerock.opendj.ldap.ResultCode 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");
}
}
Aggregations