use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class AutoProvision method getExternalAttrsByName.
protected ExternalEntry getExternalAttrsByName(String loginName) throws ServiceException {
String url = domain.getAutoProvLdapURL();
boolean wantStartTLS = domain.isAutoProvLdapStartTlsEnabled();
String adminDN = domain.getAutoProvLdapAdminBindDn();
String adminPassword = domain.getAutoProvLdapAdminBindPassword();
String[] attrs = getAttrsToFetch();
// always use the admin bind DN/password, not the user's bind DN/password
ExternalLdapConfig config = new ExternalLdapConfig(url, wantStartTLS, null, adminDN, adminPassword, null, "auto provision account");
ZLdapContext zlc = null;
try {
zlc = LdapClient.getExternalContext(config, LdapUsage.AUTO_PROVISION);
String searchFilterTemplate = domain.getAutoProvLdapSearchFilter();
if (searchFilterTemplate != null) {
// get attrs by search
String searchBase = domain.getAutoProvLdapSearchBase();
if (searchBase == null) {
searchBase = LdapConstants.DN_ROOT_DSE;
}
String searchFilter = LdapUtil.computeDn(loginName, searchFilterTemplate);
ZimbraLog.autoprov.debug("AutoProvision: computed search filter" + searchFilter);
ZSearchResultEntry entry = prov.getHelper().searchForEntry(searchBase, ZLdapFilterFactory.getInstance().fromFilterString(FilterId.AUTO_PROVISION_SEARCH, searchFilter), zlc, attrs);
if (entry == null) {
throw AccountServiceException.NO_SUCH_EXTERNAL_ENTRY(loginName);
}
return new ExternalEntry(entry.getDN(), entry.getAttributes());
}
String bindDNTemplate = domain.getAutoProvLdapBindDn();
if (bindDNTemplate != null) {
// get attrs by external DN template
String dn = LdapUtil.computeDn(loginName, bindDNTemplate);
ZimbraLog.autoprov.debug("AutoProvision: computed external DN" + dn);
return new ExternalEntry(dn, prov.getHelper().getAttributes(zlc, dn, attrs));
}
} finally {
LdapClient.closeContext(zlc);
}
throw ServiceException.FAILURE("One of " + Provisioning.A_zimbraAutoProvLdapBindDn + " or " + Provisioning.A_zimbraAutoProvLdapSearchFilter + " must be set", null);
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class BySearchResultEntrySearcher method doSearch.
public void doSearch(ZLdapFilter filter, Set<ObjectType> types) throws ServiceException {
String[] bases = prov.getSearchBases(domain, types);
for (String base : bases) {
try {
ZSearchControls ctrl = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration results = prov.getHelper().searchDir(base, filter, ctrl, zlc, LdapServerType.REPLICA);
while (results.hasMore()) {
ZSearchResultEntry sr = results.next();
visitor.processSearchEntry(sr);
}
results.close();
} catch (ServiceException e) {
ZimbraLog.search.debug("Unexpected exception whilst searching", e);
}
}
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class TestLdapHelper method searchForEntryMultipleMatchedEntries.
@Test
public void searchForEntryMultipleMatchedEntries() throws Exception {
LdapDIT dit = prov.getDIT();
String base = dit.configBranchBaseDN();
ZLdapFilter filter = filterFactory.allAccounts();
boolean caughtException = false;
try {
ZSearchResultEntry entry = ldapHelper.searchForEntry(base, filter, null, false);
assertNotNull(entry);
} catch (LdapMultipleEntriesMatchedException e) {
caughtException = true;
}
assertTrue(caughtException);
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class TestLdapHelper method searchDir.
@Test
public void searchDir() throws Exception {
LdapDIT dit = prov.getDIT();
String base = dit.configBranchBaseDN();
ZLdapFilter filter = filterFactory.anyEntry();
String[] returnAttrs = new String[] { "objectClass" };
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_ONELEVEL, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration ne = ldapHelper.searchDir(base, filter, searchControls);
Set<String> expected = new HashSet<String>();
expected.add(dit.adminBaseDN());
expected.add(dit.appAdminBaseDN());
expected.add(dit.zimletBaseDN());
expected.add(dit.cosBaseDN());
expected.add(dit.globalDynamicGroupBaseDN());
expected.add(dit.serverBaseDN());
expected.add(dit.xmppcomponentBaseDN());
expected.add(dit.globalGrantDN());
expected.add(dit.configDN());
expected.add(dit.shareLocatorBaseDN());
expected.add(dit.ucServiceBaseDN());
int numFound = 0;
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
assertTrue(expected.contains(sr.getDN()));
numFound++;
}
ne.close();
assertEquals(expected.size(), numFound);
}
use of com.zimbra.cs.ldap.ZSearchResultEntry in project zm-mailbox by Zimbra.
the class TestLdapHelper method searchForEntryNotFound.
@Test
public void searchForEntryNotFound() throws Exception {
LdapDIT dit = prov.getDIT();
String base = dit.configBranchBaseDN();
ZLdapFilter filter = filterFactory.fromFilterString(FilterId.UNITTEST, "(cn=bogus)");
ZSearchResultEntry sr = ldapHelper.searchForEntry(base, filter, null, false);
assertNull(sr);
}
Aggregations