use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class LdapGalSearch method searchLdapGal.
private static void searchLdapGal(GalParams.ExternalGalParams galParams, GalOp galOp, String query, int maxResults, LdapGalMapRules rules, String token, SearchGalResult result) throws ServiceException {
ZLdapContext zlc = null;
try {
LdapGalCredential credential = galParams.credential();
ExternalLdapConfig ldapConfig = new ExternalLdapConfig(galParams.url(), galParams.requireStartTLS(), credential.getAuthMech(), credential.getBindDn(), credential.getBindPassword(), rules.getBinaryLdapAttrs(), "external GAL");
zlc = LdapClient.getExternalContext(ldapConfig, LdapUsage.fromGalOpLegacy(galOp));
searchGal(zlc, GalSearchConfig.GalType.ldap, galParams.pageSize(), galParams.searchBase(), query, maxResults, rules, token, result);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class LdapGalSearch method doGalSearch.
private static void doGalSearch(GalSearchParams params) throws ServiceException {
ZLdapContext zlc = null;
try {
GalSearchConfig cfg = params.getConfig();
GalSearchConfig.GalType galType = params.getConfig().getGalType();
if (galType == GalSearchConfig.GalType.zimbra) {
zlc = LdapClient.getContext(LdapUsage.fromGalOp(params.getOp()));
} else {
ExternalLdapConfig ldapConfig = new ExternalLdapConfig(cfg.getUrl(), cfg.getStartTlsEnabled(), cfg.getAuthMech(), cfg.getBindDn(), cfg.getBindPassword(), cfg.getRules().getBinaryLdapAttrs(), "external GAL");
zlc = LdapClient.getExternalContext(ldapConfig, LdapUsage.fromGalOp(params.getOp()));
}
String fetchEntryByDn = params.getSearchEntryByDn();
if (fetchEntryByDn == null) {
SearchGalResult sgr = params.getResult();
if (sgr != null && GalOp.sync.equals(params.getOp())) {
sgr.setLdapTimeStamp(params.getLdapTimeStamp());
sgr.setLdapMatchCount(params.getLdapMatchCount());
sgr.setHadMore(params.ldapHasMore());
sgr.setMaxLdapTimeStamp(params.getMaxLdapTimeStamp());
}
if (params.isExpandQuery()) {
searchGal(zlc, galType, cfg.getPageSize(), cfg.getSearchBase(), params.generateLdapQuery(), params.getLimit(), cfg.getRules(), params.getSyncToken(), params.getResult(), params.getOp());
} else {
searchGal(zlc, galType, cfg.getPageSize(), cfg.getSearchBase(), params.getQuery(), params.getLimit(), cfg.getRules(), params.getSyncToken(), params.getResult(), params.getOp());
}
} else {
getGalEntryByDn(zlc, galType, fetchEntryByDn, cfg.getRules(), params.getResult());
}
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class LdapHelper method countEntries.
public long countEntries(String baseDN, ZLdapFilter filter, ZSearchControls searchControls, ZLdapContext initZlc, LdapServerType ldapServerType) throws ServiceException {
boolean noopSearchSupported = !InMemoryLdapServer.isOn() && DebugConfig.ldapNoopSearchSupported;
if (noopSearchSupported) {
return countEntriesByNoopSearch(baseDN, filter, searchControls, initZlc, ldapServerType);
} else {
CountObjectsVisitor visitor = new CountObjectsVisitor();
SearchLdapOptions searchOptions = new SearchLdapOptions(baseDN, filter, null, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
ZLdapContext zlc = initZlc;
try {
if (zlc == null) {
zlc = LdapClient.getContext(ldapServerType, LdapUsage.SEARCH);
}
zlc.searchPaged(searchOptions);
} finally {
if (initZlc == null) {
LdapClient.closeContext(zlc);
}
}
return visitor.getCount();
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class ADGroupHandler method getDelegatedAdminGroups.
private List<String> getDelegatedAdminGroups(Account acct, boolean asAdmin) throws ServiceException {
LdapProv prov = LdapProv.getInst();
Domain domain = prov.getDomain(acct);
if (domain == null) {
throw ServiceException.FAILURE("unable to get domain for account " + acct.getName(), null);
}
// try explicit external DN on account first
String extDN = acct.getAuthLdapExternalDn();
if (extDN == null) {
// then try bind DN template on domain
// note: for AD auth, zimbraAuthLdapSearchFilter is not used, so we
// skip that. See LdapProvisioning.externalLdapAuth
String dnTemplate = domain.getAuthLdapBindDn();
if (dnTemplate != null) {
extDN = LdapUtil.computeDn(acct.getName(), dnTemplate);
}
}
if (extDN == null) {
throw ServiceException.FAILURE("unable to get external DN for account " + acct.getName(), null);
}
ZLdapContext zlc = null;
try {
zlc = getExternalDelegatedAdminGroupsLdapContext(domain, asAdmin);
ZAttributes attrs = prov.getHelper().getAttributes(zlc, extDN, new String[] { MEMBER_OF_ATTR });
return attrs.getMultiAttrStringAsList(MEMBER_OF_ATTR, CheckBinary.NOCHECK);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.
the class TestLdapProvDomain method verifyAllDomains.
private void verifyAllDomains(List<Domain> allDomains) throws Exception {
// domains created by r-t-w
// TODO: this verification is very fragile
Set<String> expectedDomains = new HashSet<String>();
String defaultDomainName = prov.getInstance().getConfig().getDefaultDomainName();
expectedDomains.add(defaultDomainName);
expectedDomains.add("example.com");
assertEquals(expectedDomains.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(expectedDomains.contains(domain.getName()));
}
//
// another verification
//
LdapHelper ldapHelper = ((LdapProv) prov).getHelper();
final List<String> /* zimbraId */
domainIds = new ArrayList<String>();
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
try {
domainIds.add(ldapAttrs.getAttrString(Provisioning.A_zimbraId));
} catch (ServiceException e) {
fail();
}
}
};
SearchLdapOptions searchOpts = new SearchLdapOptions(LdapConstants.DN_ROOT_DSE, ZLdapFilterFactory.getInstance().fromFilterString(FilterId.UNITTEST, "(objectclass=zimbraDomain)"), new String[] { Provisioning.A_zimbraId }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapUsage.UNITTEST);
ldapHelper.searchLdap(zlc, searchOpts);
} finally {
LdapClient.closeContext(zlc);
}
assertEquals(domainIds.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(domainIds.contains(domain.getId()));
}
}
Aggregations