use of org.forgerock.opendj.ldap.Connection 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.Connection 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.Connection in project OpenAM by OpenRock.
the class SMSLdapObject method search.
/**
* Returns LDAP entries that match the filter, using the start DN provided
* in method
*/
public Iterator<SMSDataEntry> search(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Set<String> excludes) throws SSOException, SMSException {
Connection conn = getConnection(adminPrincipal);
ConnectionEntryReader results = searchObjectsEx(token, startDN, filter, numOfEntries, timeLimit, sortResults, ascendingOrder, conn);
return new SearchResultIterator(results, excludes, conn);
}
use of org.forgerock.opendj.ldap.Connection 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.Connection in project OpenAM by OpenRock.
the class SMDataLayer method getConnection.
/**
* Get connection from pool, not through LDAPProxy. Reauthenticate if
* necessary
*
* @return connection that is available to use
*/
protected Connection getConnection() {
if (_ldapPool == null)
return null;
debug.message("SMDataLayer:getConnection() - Invoking _ldapPool.getConnection()");
Connection conn = null;
try {
conn = _ldapPool.getConnection();
debug.message("SMDataLayer:getConnection() - Got Connection : {}", conn);
} catch (LdapException e) {
debug.error("SMDataLayer:getConnection() - Failed to get Connection", e);
}
return conn;
}
Aggregations