use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class ProvUtil method doSyncGal.
private void doSyncGal(String[] args) throws ServiceException {
String domain = args[1];
String token = args.length == 3 ? args[2] : "";
Domain d = lookupDomain(domain);
SearchGalResult result = null;
if (prov instanceof LdapProv) {
GalContact.Visitor visitor = new GalContact.Visitor() {
@Override
public void visit(GalContact gc) throws ServiceException {
dumpContact(gc);
}
};
result = prov.syncGal(d, token, visitor);
} else {
result = ((SoapProvisioning) prov).searchGal(d, "", GalSearchType.all, token, 0, 0, null);
for (GalContact contact : result.getMatches()) {
dumpContact(contact);
}
}
if (result.getToken() != null) {
console.println("\n# token = " + result.getToken() + "\n");
}
}
use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class ProvUtil method doSearchGal.
private void doSearchGal(String[] args) throws ServiceException, ArgException {
if (args.length < 3) {
usage();
return;
}
String domain = args[1];
String query = args[2];
Map<String, Object> attrs = getMap(args, 3);
String limitStr = (String) attrs.get("limit");
int limit = limitStr == null ? 0 : Integer.parseInt(limitStr);
String offsetStr = (String) attrs.get("offset");
int offset = offsetStr == null ? 0 : Integer.parseInt(offsetStr);
String sortBy = (String) attrs.get("sortBy");
Domain d = lookupDomain(domain);
SearchGalResult result;
if (prov instanceof LdapProv) {
if (offsetStr != null) {
throw ServiceException.INVALID_REQUEST("offset is not supported with -l", null);
}
if (sortBy != null) {
throw ServiceException.INVALID_REQUEST("sortBy is not supported with -l", null);
}
GalContact.Visitor visitor = new GalContact.Visitor() {
@Override
public void visit(GalContact gc) throws ServiceException {
dumpContact(gc);
}
};
result = prov.searchGal(d, query, GalSearchType.all, limit, visitor);
} else {
result = ((SoapProvisioning) prov).searchGal(d, query, GalSearchType.all, null, limit, offset, sortBy);
for (GalContact contact : result.getMatches()) {
dumpContact(contact);
}
}
}
use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class LdapGalSearch method searchLdapGal.
public static SearchGalResult searchLdapGal(GalParams.ExternalGalParams galParams, GalOp galOp, String n, int maxResults, LdapGalMapRules rules, String token, GalContact.Visitor visitor) throws ServiceException {
String[] url = galParams.url();
String base = galParams.searchBase();
String filter = galParams.filter();
SearchGalResult result = SearchGalResult.newSearchGalResult(visitor);
String tokenize = GalUtil.tokenizeKey(galParams, galOp);
result.setTokenizeKey(tokenize);
if (url == null || url.length == 0 || base == null || filter == null) {
if (url == null || url.length == 0)
ZimbraLog.gal.warn("searchLdapGal url is null");
if (base == null)
ZimbraLog.gal.warn("searchLdapGal base is null");
if (filter == null)
ZimbraLog.gal.warn("searchLdapGal queryExpr is null");
return result;
}
if (filter.indexOf("(") == -1) {
String queryExpr = GalSearchConfig.getFilterDef(filter);
if (queryExpr != null)
filter = queryExpr;
}
String query = GalUtil.expandFilter(tokenize, filter, n, token);
String authMech = galParams.credential().getAuthMech();
if (authMech.equals(Provisioning.LDAP_AM_KERBEROS5))
searchLdapGalKrb5(galParams, galOp, query, maxResults, rules, token, result);
else
searchLdapGal(galParams, galOp, query, maxResults, rules, token, result);
return result;
}
use of com.zimbra.cs.account.Provisioning.SearchGalResult 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());
}
searchGal(zlc, galType, cfg.getPageSize(), cfg.getSearchBase(), params.generateLdapQuery(), 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.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class TestGal method syncGal.
private String syncGal(int numResultsExpected, int numTotal, String token) throws Exception {
/*
if (DEBUG)
System.out.format(" syncGal: numResultsExpected=%d, numTotal=%d, token=%s\n",
numResultsExpected, numTotal, token);
*/
Domain domain = mProv.get(Key.DomainBy.name, DOMAIN_NAME);
SearchGalResult galResult = mProv.syncGal(domain, token, null);
assertEquals(numResultsExpected, galResult.getNumMatches());
boolean expectedHasMore = numResultsExpected < numTotal;
// SyncGal SOAP response does not encode the more flag.
if (!SOAP_PROV)
assertEquals(expectedHasMore, galResult.getHadMore());
return galResult.getToken();
}
Aggregations