use of com.unboundid.ldap.sdk.SearchResult in project gitblit by gitblit.
the class LdapAuthenticationTest method checkIfUsersConfContainsAllUsersFromSampleDataLdif.
@Test
public void checkIfUsersConfContainsAllUsersFromSampleDataLdif() throws Exception {
SearchResult searchResult = getDS().search(ACCOUNT_BASE, SearchScope.SUB, "objectClass=person");
assertEquals("Number of ldap users in gitblit user model", searchResult.getEntryCount(), countLdapUsersInUserManager());
}
use of com.unboundid.ldap.sdk.SearchResult in project gitblit by gitblit.
the class LdapConnection method search.
public SearchResult search(String base, boolean dereferenceAliases, String filter, List<String> attributes) {
try {
SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
if (dereferenceAliases) {
searchRequest.setDerefPolicy(DereferencePolicy.SEARCHING);
}
if (attributes != null) {
searchRequest.setAttributes(attributes);
}
SearchResult result = search(searchRequest);
return result;
} catch (LDAPException e) {
logger.error("Problem creating LDAP search", e);
return null;
}
}
use of com.unboundid.ldap.sdk.SearchResult in project zm-mailbox by Zimbra.
the class UBIDLdapContext method searchDir.
@Override
public ZSearchResultEnumeration searchDir(String baseDN, ZLdapFilter filter, ZSearchControls searchControls) throws LdapException {
UBIDSearchControls sc = (UBIDSearchControls) searchControls;
try {
SearchRequest searchRequest = new SearchRequest(baseDN, sc.getSearchScope(), derefAliasPolicy, sc.getSizeLimit(), sc.getTimeLimit(), sc.getTypesOnly(), ((UBIDLdapFilter) filter).getNative());
searchRequest.setAttributes(sc.getReturnAttrs());
SearchResult result = UBIDLdapOperation.SEARCH.execute(this, searchRequest, filter);
return new UBIDSearchResultEnumeration(result);
} catch (LDAPException e) {
throw mapToLdapException("unable to search ldap", e);
}
}
use of com.unboundid.ldap.sdk.SearchResult in project zm-mailbox by Zimbra.
the class UBIDLdapContext method countEntries.
@Override
public long countEntries(String baseDN, ZLdapFilter filter, ZSearchControls searchControls) throws LdapException {
UBIDSearchControls sc = (UBIDSearchControls) searchControls;
try {
SearchRequest searchRequest = new SearchRequest(baseDN, sc.getSearchScope(), derefAliasPolicy, sc.getSizeLimit(), sc.getTimeLimit(), sc.getTypesOnly(), ((UBIDLdapFilter) filter).getNative());
NoopSearchControl noopSearchCtl = new NoopSearchControl();
searchRequest.addControl(noopSearchCtl);
// no point to request attributes
if (sc.getReturnAttrs() != null) {
throw LdapException.INVALID_REQUEST("return attributes are not allowed for countEntries", null);
}
SearchResult result = UBIDLdapOperation.SEARCH.execute(this, searchRequest, filter);
NoopSearchControl control = NoopSearchControl.get(result);
if (control == null) {
throw LdapException.LDAP_ERROR("Noop search control is not present in response", null);
}
return control.getCount();
} catch (LDAPException e) {
throw mapToLdapException("unable to search ldap", e);
}
}
use of com.unboundid.ldap.sdk.SearchResult in project zm-mailbox by Zimbra.
the class UBIDLdapContext method moveChildren.
@Override
public void moveChildren(String oldDn, String newDn) throws ServiceException {
try {
// use ZLdapFilter instead of just the native Filter so it's
// convenient for stating
ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
// Filter filter = Filter.createPresenceFilter(LdapConstants.ATTR_OBJECTCLASS);
SearchRequest searchRequest = new SearchRequest(oldDn, SearchScope.ONE, derefAliasPolicy, // size limit
0, // time limit
0, // getTypesOnly
false, ((UBIDLdapFilter) filter).getNative());
searchRequest.setAttributes("dn");
SearchResult result = UBIDLdapOperation.SEARCH.execute(this, searchRequest, filter);
List<SearchResultEntry> entries = result.getSearchEntries();
for (SearchResultEntry entry : entries) {
DN entryDN = entry.getParsedDN();
String childDn = entryDN.toNormalizedString();
String childRdn = entryDN.getRDNString();
UBIDLdapOperation.MODIFY_DN.execute(this, childDn, childRdn, true, newDn);
}
} catch (LDAPException e) {
throw mapToLdapException("unable to move children", e);
}
}
Aggregations