use of org.forgerock.opendj.ldap.requests.SearchRequest in project admin-console-beta by connexta.
the class ServerGuesser method getClaimAttributeOptions.
public Set<String> getClaimAttributeOptions(String baseUserDn) {
try {
// Find all object classes with names like *person* in the core schema
// this will catch person, organizationalPerson, inetOrgPerson, etc. if present
SortedSet<String> attributes = extractAttributes(Schema.getCoreSchema().getObjectClasses(), oc -> oc.getNameOrOID().toLowerCase().matches(".*person.*"));
// Find any given user with the clearance attribute
SearchRequest clearanceReq = Requests.newSearchRequest(DN.valueOf(baseUserDn), SearchScope.WHOLE_SUBTREE, Filter.present("2.16.840.1.101.2.2.1.203"), "objectClass");
ConnectionEntryReader clearanceReader = connection.search(clearanceReq);
if (clearanceReader.hasNext()) {
SearchResultEntry entry = clearanceReader.readEntry();
RootDSE rootDSE = RootDSE.readRootDSE(connection);
DN subschemaDN = rootDSE.getSubschemaSubentry();
Schema subschema = Schema.readSchema(connection, subschemaDN);
// Check against both the subschema and the default schema
attributes.addAll(extractAttributes(Entries.getObjectClasses(entry, subschema), STRUCT_OR_AUX));
attributes.addAll(extractAttributes(Entries.getObjectClasses(entry), STRUCT_OR_AUX));
}
return attributes;
} catch (SearchResultReferenceIOException | LdapException e) {
LOGGER.warn("Error retrieving attributes from LDAP server; this may indicate a configuration issue with config.");
return Collections.emptySet();
}
}
use of org.forgerock.opendj.ldap.requests.SearchRequest in project OpenAM by OpenRock.
the class SMSLdapObject method getSubEntries.
private Set<String> getSubEntries(SSOToken token, String dn, String filter, int numOfEntries, boolean sortResults, boolean ascendingOrder) throws SMSException, SSOException {
SearchRequest request = getSearchRequest(dn, filter, SearchScope.SINGLE_LEVEL, numOfEntries, 0, sortResults, ascendingOrder, getNamingAttribute(), O_ATTR);
int retry = 0;
Set<String> answer = new LinkedHashSet<>();
ConnectionEntryReader results;
while (retry <= connNumRetry) {
debug.message("SMSLdapObject.subEntries() retry: {}", retry);
try (Connection conn = getConnection(token.getPrincipal())) {
// Get the sub entries
ConnectionEntryReader iterResults = conn.search(request);
iterResults.hasNext();
results = iterResults;
// Construct the results and return
try {
while (results != null && results.hasNext()) {
try {
if (results.isReference()) {
debug.warning("Skipping reference result: {}", results.readReference());
continue;
}
SearchResultEntry entry = results.readEntry();
// Workaround for 3823, where (objectClass=*) is used
if (entry.getName().toString().toLowerCase().startsWith("ou=")) {
answer.add(entry.getName().rdn().getFirstAVA().getAttributeValue().toString());
}
} catch (SearchResultReferenceIOException e) {
debug.error("SMSLdapObject.subEntries: Reference should be handled already for dn {}", dn, e);
}
}
} catch (LdapException e) {
debug.warning("SMSLdapObject.subEntries: Error in obtaining sub-entries: {}", dn, e);
throw new SMSException(e, "sms-entry-cannot-obtain");
}
break;
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.NO_SUCH_OBJECT)) {
debug.message("SMSLdapObject.subEntries(): entry not present: {}", dn);
break;
}
if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
debug.warning("SMSLdapObject.subEntries: Unable to search for sub-entries: {}", dn, e);
throw new SMSException(e, "sms-entry-cannot-search");
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
// ignored
}
}
}
debug.message("SMSLdapObject.subEntries: Successfully obtained sub-entries for {}", dn);
return answer;
}
use of org.forgerock.opendj.ldap.requests.SearchRequest in project OpenAM by OpenRock.
the class SMSLdapObject method searchObjects.
private ConnectionEntryReader searchObjects(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Connection conn) throws SSOException, SMSException {
ConnectionEntryReader results = null;
int retry = 0;
SearchRequest request = getSearchRequest(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, timeLimit);
while (retry <= connNumRetry) {
if (debug.messageEnabled()) {
debug.message("SMSLdapObject.search() retry: " + retry);
}
try {
results = conn.search(request);
results.hasNext();
return results;
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
debug.warning("SMSLdapObject.search(): LDAP exception in search for filter match: {}", filter, e);
throw new SMSException(e, "sms-error-in-searching");
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
//ignored
}
}
}
return null;
}
use of org.forgerock.opendj.ldap.requests.SearchRequest in project OpenAM by OpenRock.
the class SMSLdapObject method searchObjectsEx.
private ConnectionEntryReader searchObjectsEx(SSOToken token, String startDN, String filter, int numOfEntries, int timeLimit, boolean sortResults, boolean ascendingOrder, Connection conn) throws SSOException, SMSException {
ConnectionEntryReader results = null;
int retry = 0;
SearchRequest request = getSearchRequest(startDN, filter, SearchScope.WHOLE_SUBTREE, numOfEntries, timeLimit, SMSEntry.ATTR_KEYVAL, SMSEntry.ATTR_XML_KEYVAL);
while (retry <= connNumRetry) {
if (debug.messageEnabled()) {
debug.message("SMSLdapObject.search() retry: " + retry);
}
try {
ConnectionEntryReader iterResults = conn.search(request);
iterResults.hasNext();
results = iterResults;
break;
} catch (LdapException e) {
ResultCode errorCode = e.getResult().getResultCode();
if (errorCode.equals(ResultCode.SIZE_LIMIT_EXCEEDED)) {
debug.warning("SMSLdapObject.search: size limit {} exceeded", numOfEntries);
break;
}
if (!retryErrorCodes.contains(errorCode) || retry >= connNumRetry) {
debug.warning("SMSLdapObject.search(): LDAP exception in search for filter match: {}", filter, e);
throw new SMSException(e, "sms-error-in-searching");
}
retry++;
try {
Thread.sleep(connRetryInterval);
} catch (InterruptedException ex) {
//ignored
}
}
}
return results;
}
use of org.forgerock.opendj.ldap.requests.SearchRequest 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();
}
Aggregations