Search in sources :

Example 1 with GalSearchParams

use of com.zimbra.cs.gal.GalSearchParams in project zm-mailbox by Zimbra.

the class LdapProvisioning method searchGal.

@Override
public SearchGalResult searchGal(Domain domain, String query, GalSearchType type, int limit, GalContact.Visitor visitor) throws ServiceException {
    SearchGalResult searchResult = SearchGalResult.newSearchGalResult(visitor);
    GalSearchParams params = new GalSearchParams(domain, null);
    params.setQuery(query);
    params.setType(type);
    params.setOp(GalOp.search);
    params.setLimit(limit);
    params.setGalResult(searchResult);
    LdapOnlyGalSearchResultCallback callback = new LdapOnlyGalSearchResultCallback(params, visitor);
    params.setResultCallback(callback);
    GalSearchControl gal = new GalSearchControl(params);
    gal.ldapSearch();
    return searchResult;
}
Also used : GalSearchControl(com.zimbra.cs.gal.GalSearchControl) GalSearchParams(com.zimbra.cs.gal.GalSearchParams)

Example 2 with GalSearchParams

use of com.zimbra.cs.gal.GalSearchParams in project zm-mailbox by Zimbra.

the class SearchGal method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    String domainName = request.getAttribute(AdminConstants.A_DOMAIN);
    Provisioning prov = Provisioning.getInstance();
    Domain domain = prov.get(Key.DomainBy.name, domainName);
    if (domain == null)
        throw AccountServiceException.NO_SUCH_DOMAIN(domainName);
    checkDomainRight(zsc, domain, Admin.R_accessGAL);
    String name = request.getAttribute(AdminConstants.E_NAME, "");
    int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, 0);
    String typeStr = request.getAttribute(AdminConstants.A_TYPE, GalSearchType.account.name());
    GalSearchType type = GalSearchType.fromString(typeStr);
    String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
    String token = request.getAttribute(AdminConstants.A_TOKEN, null);
    GalSearchParams params = new GalSearchParams(domain, zsc);
    if (token != null)
        params.setToken(token);
    params.setType(type);
    params.setRequest(request);
    params.setQuery(name);
    params.setLimit(limit);
    params.setResponseName(AdminConstants.SEARCH_GAL_RESPONSE);
    if (galAcctId != null)
        params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
    params.setResultCallback(new SearchGal.AdminGalCallback(params));
    GalSearchControl gal = new GalSearchControl(params);
    if (token != null)
        gal.sync();
    else
        gal.search();
    return params.getResultCallback().getResponse();
}
Also used : GalSearchControl(com.zimbra.cs.gal.GalSearchControl) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 3 with GalSearchParams

use of com.zimbra.cs.gal.GalSearchParams in project zm-mailbox by Zimbra.

the class SearchGal method searchGal.

private static Element searchGal(ZimbraSoapContext zsc, Account account, Element request) throws ServiceException {
    // if searhc by ref is requested, honor it
    String ref = request.getAttribute(AccountConstants.A_REF, null);
    // otherwise require a query
    String name = null;
    if (ref == null) {
        name = request.getAttribute(AccountConstants.E_NAME);
    }
    EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
    String typeStr = request.getAttribute(AccountConstants.A_TYPE, "all");
    GalSearchType type = GalSearchType.fromString(typeStr);
    boolean needCanExpand = request.getAttributeBool(AccountConstants.A_NEED_EXP, false);
    boolean needIsOwner = request.getAttributeBool(AccountConstants.A_NEED_IS_OWNER, false);
    MemberOfSelector needIsMember = MemberOfSelector.fromString(request.getAttribute(AccountConstants.A_NEED_IS_MEMBER, MemberOfSelector.none.name()));
    // internal attr, for proxied GSA search from GetSMIMEPublicCerts only
    boolean needSMIMECerts = request.getAttributeBool(AccountConstants.A_NEED_SMIME_CERTS, false);
    String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
    GalSearchParams params = new GalSearchParams(account, zsc);
    if (ref == null) {
        params.setQuery(name);
    } else {
        // search GAL by ref, which is a dn
        params.setSearchEntryByDn(ref);
    }
    params.setType(type);
    params.setRequest(request);
    params.setNeedCanExpand(needCanExpand);
    params.setNeedIsOwner(needIsOwner);
    params.setNeedIsMember(needIsMember);
    params.setNeedSMIMECerts(needSMIMECerts);
    params.setResponseName(AccountConstants.SEARCH_GAL_RESPONSE);
    if (galAcctId != null) {
        params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
    }
    if (filter != null) {
        params.setExtraQueryCallback(new SearchGalExtraQueryCallback(filter));
    }
    // also note that mailbox search has a hard limit of 1000
    if (request.getAttribute(MailConstants.A_QUERY_LIMIT, null) == null) {
        request.addAttribute(MailConstants.A_QUERY_LIMIT, 100);
    }
    /* do not support specified attrs yet
        String attrsStr = request.getAttribute(AccountConstants.A_ATTRS, null);
        String[] attrs = attrsStr == null ? null : attrsStr.split(",");
        Set<String> attrsSet = attrs == null ? null : new HashSet<String>(Arrays.asList(attrs));
        */
    params.setResultCallback(new SearchGalResultCallback(params, filter, null));
    GalSearchControl gal = new GalSearchControl(params);
    gal.search();
    return params.getResultCallback().getResponse();
}
Also used : MemberOfSelector(com.zimbra.soap.account.type.MemberOfSelector) GalSearchControl(com.zimbra.cs.gal.GalSearchControl) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) EntrySearchFilter(com.zimbra.cs.account.EntrySearchFilter) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 4 with GalSearchParams

use of com.zimbra.cs.gal.GalSearchParams in project zm-mailbox by Zimbra.

the class SyncGal method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    disableJettyTimeout(context);
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(getZimbraSoapContext(context));
    if (!canAccessAccount(zsc, account))
        throw ServiceException.PERM_DENIED("can not access account");
    String tokenAttr = request.getAttribute(MailConstants.A_TOKEN, "");
    String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
    boolean idOnly = request.getAttributeBool(AccountConstants.A_ID_ONLY, false);
    int limit = request.getAttributeInt(MailConstants.A_LIMIT, 0);
    GalSearchParams params = new GalSearchParams(account, zsc);
    params.setType(GalSearchType.all);
    ZimbraLog.gal.debug("SyncGalRequest token: %s  limit: %d", tokenAttr, limit);
    params.setToken(tokenAttr);
    params.setRequest(request);
    params.setResponseName(AccountConstants.SYNC_GAL_RESPONSE);
    params.setIdOnly(idOnly);
    params.setUserAgent(zsc.getUserAgent());
    params.setLimit(limit);
    if (galAcctId != null)
        params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
    params.setResultCallback(new SyncGalCallback(params));
    GalSearchControl gal = new GalSearchControl(params);
    gal.sync();
    return params.getResultCallback().getResponse();
}
Also used : Account(com.zimbra.cs.account.Account) GalSearchControl(com.zimbra.cs.gal.GalSearchControl) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GalSearchParams(com.zimbra.cs.gal.GalSearchParams)

Example 5 with GalSearchParams

use of com.zimbra.cs.gal.GalSearchParams in project zm-mailbox by Zimbra.

the class AutoCompleteGal method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(getZimbraSoapContext(context));
    if (!canAccessAccount(zsc, account))
        throw ServiceException.PERM_DENIED("can not access account");
    String name = request.getAttribute(AccountConstants.E_NAME);
    String typeStr = request.getAttribute(AccountConstants.A_TYPE, "account");
    GalSearchType type = GalSearchType.fromString(typeStr);
    boolean needCanExpand = request.getAttributeBool(AccountConstants.A_NEED_EXP, false);
    String galAcctId = request.getAttribute(AccountConstants.A_GAL_ACCOUNT_ID, null);
    GalSearchParams params = new GalSearchParams(account, zsc);
    params.setType(type);
    params.setRequest(request);
    params.setQuery(name);
    params.setLimit(account.getContactAutoCompleteMaxResults());
    params.setNeedCanExpand(needCanExpand);
    params.setResponseName(AccountConstants.AUTO_COMPLETE_GAL_RESPONSE);
    if (galAcctId != null)
        params.setGalSyncAccount(Provisioning.getInstance().getAccountById(galAcctId));
    GalSearchControl gal = new GalSearchControl(params);
    gal.autocomplete();
    return params.getResultCallback().getResponse();
}
Also used : Account(com.zimbra.cs.account.Account) GalSearchControl(com.zimbra.cs.gal.GalSearchControl) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) GalSearchType(com.zimbra.soap.type.GalSearchType)

Aggregations

GalSearchParams (com.zimbra.cs.gal.GalSearchParams)12 GalSearchControl (com.zimbra.cs.gal.GalSearchControl)10 GalSearchType (com.zimbra.soap.type.GalSearchType)6 Account (com.zimbra.cs.account.Account)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Domain (com.zimbra.cs.account.Domain)3 EntrySearchFilter (com.zimbra.cs.account.EntrySearchFilter)2 Provisioning (com.zimbra.cs.account.Provisioning)2 SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)2 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 GalContact (com.zimbra.cs.account.GalContact)1 MemberOfSelector (com.zimbra.soap.account.type.MemberOfSelector)1 HashMap (java.util.HashMap)1