Search in sources :

Example 1 with SearchGalResult

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");
    }
}
Also used : PublishedShareInfoVisitor(com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 2 with SearchGalResult

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);
        }
    }
}
Also used : PublishedShareInfoVisitor(com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 3 with SearchGalResult

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;
}
Also used : SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult)

Example 4 with SearchGalResult

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);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) GalSearchConfig(com.zimbra.cs.gal.GalSearchConfig) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult)

Example 5 with SearchGalResult

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();
}
Also used : SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Domain(com.zimbra.cs.account.Domain)

Aggregations

SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)14 Domain (com.zimbra.cs.account.Domain)5 Account (com.zimbra.cs.account.Account)3 GalContact (com.zimbra.cs.account.GalContact)3 PublishedShareInfoVisitor (com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)3 LdapProv (com.zimbra.cs.account.ldap.LdapProv)2 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)2 GalSearchType (com.zimbra.soap.type.GalSearchType)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 Control (com.unboundid.ldap.sdk.Control)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 SearchScope (com.unboundid.ldap.sdk.SearchScope)1 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)1 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)1