use of com.novell.ldapchai.util.SearchHelper in project ldapchai by ldapchai.
the class JLDAPProviderImpl method searchImpl.
public Map<String, Map<String, List<String>>> searchImpl(final String baseDN, final SearchHelper searchHelper, final boolean onlyFirstValue) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
// make a copy so if it changes somewhere else we won't be affected.
final SearchHelper effectiveSearchHelper = new SearchHelper(searchHelper);
// replace a null dn with an empty string
final String effectiveBaseDN = baseDN != null ? baseDN : "";
final int ldapScope;
switch(effectiveSearchHelper.getSearchScope()) {
case ONE:
ldapScope = LDAPConnection.SCOPE_ONE;
break;
case BASE:
ldapScope = LDAPConnection.SCOPE_BASE;
break;
case SUBTREE:
ldapScope = LDAPConnection.SCOPE_SUB;
break;
default:
ldapScope = -1;
}
final Map<String, Map<String, List<String>>> returnMap = new LinkedHashMap<>();
final LDAPSearchConstraints constraints = new LDAPSearchConstraints();
constraints.setMaxResults(effectiveSearchHelper.getMaxResults());
constraints.setTimeLimit(effectiveSearchHelper.getTimeLimit());
final String[] returnAttributes = effectiveSearchHelper.getAttributes() == null ? null : effectiveSearchHelper.getAttributes().toArray(new String[effectiveSearchHelper.getAttributes().size()]);
final LDAPSearchResults results;
try {
results = ldapConnection.search(effectiveBaseDN, ldapScope, effectiveSearchHelper.getFilter(), returnAttributes, false, constraints);
while (results.hasMore()) {
final LDAPEntry loopEntry = results.next();
final String loopDN = loopEntry.getDN();
final Map<String, List<String>> loopAttributes = new LinkedHashMap<>();
final LDAPAttributeSet attrSet = loopEntry.getAttributeSet();
for (final Object anAttrSet : attrSet) {
final LDAPAttribute loopAttr = (LDAPAttribute) anAttrSet;
if (onlyFirstValue) {
loopAttributes.put(loopAttr.getName(), Collections.singletonList(loopAttr.getStringValue()));
} else {
loopAttributes.put(loopAttr.getName(), Arrays.asList(loopAttr.getStringValueArray()));
}
}
returnMap.put(loopDN, loopAttributes);
}
} catch (LDAPException e) {
if (!returnMap.isEmpty()) {
return Collections.unmodifiableMap(returnMap);
}
throw ChaiOperationException.forErrorMessage(e.getLDAPErrorMessage());
}
return Collections.unmodifiableMap(returnMap);
}
use of com.novell.ldapchai.util.SearchHelper in project ldapchai by ldapchai.
the class JLDAPProviderImpl method search.
@ChaiProvider.LdapOperation
public Map<String, Map<String, String>> search(final String baseDN, final String filter, final Set<String> attributes, final SearchScope searchScope) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().search(baseDN, filter, attributes, searchScope);
final SearchHelper searchHelper = new SearchHelper();
searchHelper.setFilter(filter);
searchHelper.setAttributes(attributes);
searchHelper.setSearchScope(searchScope);
return search(baseDN, searchHelper);
}
use of com.novell.ldapchai.util.SearchHelper in project ldapchai by ldapchai.
the class JNDIProviderImpl method searchMultiValues.
public final Map<String, Map<String, List<String>>> searchMultiValues(final String baseDN, final String filter, final Set<String> attributes, final SearchScope searchScope) throws ChaiUnavailableException, ChaiOperationException {
activityPreCheck();
getInputValidator().searchMultiValues(baseDN, filter, attributes, searchScope);
final SearchHelper searchHelper = new SearchHelper();
searchHelper.setFilter(filter);
searchHelper.setAttributes(attributes);
searchHelper.setSearchScope(searchScope);
final SearchEngine searchEngine = new SearchEngine(chaiConfig, baseDN, searchHelper, true);
return searchEngine.getResults();
}
use of com.novell.ldapchai.util.SearchHelper in project ldapchai by ldapchai.
the class ApacheLdapProviderImpl method searchMultiValues.
public Map<String, Map<String, List<String>>> searchMultiValues(final String baseDN, final String filter, final Set<String> attributes, final SearchScope searchScope) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
activityPreCheck();
getInputValidator().searchMultiValues(baseDN, filter, attributes, searchScope);
final SearchHelper searchHelper = new SearchHelper();
searchHelper.setFilter(filter);
searchHelper.setAttributes(attributes);
searchHelper.setSearchScope(searchScope);
return searchImpl(baseDN, searchHelper, true);
}
use of com.novell.ldapchai.util.SearchHelper in project ldapchai by ldapchai.
the class SearchHelperTester method testAndFilter.
public void testAndFilter() throws Exception {
final LinkedHashMap<String, String> props = new LinkedHashMap<String, String>();
props.put("objectClass", "inetOrgPerson");
props.put("cn", "joe");
final SearchHelper sh = new SearchHelper();
sh.setFilterAnd(props);
final String expectedFilter = "(&(objectClass=inetOrgPerson)(cn=joe))";
final String filterFromHelper = sh.getFilter();
Assert.assertEquals(expectedFilter, filterFromHelper);
}
Aggregations