Search in sources :

Example 6 with GalSearchType

use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.

the class AutoComplete method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(getZimbraSoapContext(context));
    OperationContext octxt = getOperationContext(zsc, context);
    String name = request.getAttribute(MailConstants.A_NAME);
    // remove commas (bug 46540)
    name = name.replace(",", " ").trim();
    GalSearchType type = GalSearchType.fromString(request.getAttribute(MailConstants.A_TYPE, "account"));
    int limit = account.getContactAutoCompleteMaxResults();
    boolean needCanExpand = request.getAttributeBool(MailConstants.A_NEED_EXP, false);
    AutoCompleteResult result = query(request, zsc, account, false, name, limit, type, needCanExpand, octxt);
    Element response = zsc.createElement(MailConstants.AUTO_COMPLETE_RESPONSE);
    toXML(response, result, zsc.getAuthtokenAccountId());
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) AutoCompleteResult(com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 7 with GalSearchType

use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.

the class TestLdapProvGal method searchGalADGroupMember.

@Test
@Ignore
public void searchGalADGroupMember() throws Exception {
    String DOMAIN_NAME = genDomainSegmentName() + "." + baseDomainName();
    Map<String, Object> domainAttrs = new HashMap<String, Object>();
    domainAttrs.put(Provisioning.A_zimbraGalMode, ZAttrProvisioning.GalMode.ldap.name());
    // replace XXX to real VMware AD credentials before checking in.
    // NEVER check in the crdentials
    domainAttrs.put(Provisioning.A_zimbraGalLdapURL, "ldap://XXX.vmware.com:3268");
    domainAttrs.put(Provisioning.A_zimbraGalLdapBindDn, "XXX@vmware.com");
    domainAttrs.put(Provisioning.A_zimbraGalLdapBindPassword, "XXX");
    domainAttrs.put(Provisioning.A_zimbraGalLdapFilter, "ad");
    domainAttrs.put(Provisioning.A_zimbraGalLdapGroupHandlerClass, "com.zimbra.cs.gal.ADGalGroupHandler");
    Domain galDomain = provUtil.createDomain(DOMAIN_NAME, domainAttrs);
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart("searchGalADGroupMember");
    Account user = provUtil.createAccount(ACCT_NAME_LOCALPART, galDomain, null);
    GalSearchType type = GalSearchType.group;
    String query = "server-pm@vmware.com";
    GalSearchParams params = new GalSearchParams(user);
    SearchGalResult result = SearchGalResult.newSearchGalResult(null);
    params.setOp(GalOp.search);
    params.setType(type);
    // has to be set before calling createSearchConfig
    params.setFetchGroupMembers(true);
    params.createSearchConfig(GalSearchConfig.GalType.ldap);
    params.setQuery(query);
    params.setGalResult(result);
    prov.searchGal(params);
    assertEquals(1, result.getMatches().size());
    GalContact galContact = result.getMatches().get(0);
    assertTrue(galContact.isGroup());
    Map<String, Object> galEntryAttrs = galContact.getAttrs();
    Object members = galEntryAttrs.get(ContactConstants.A_member);
    assertTrue(members instanceof String[]);
    assertEquals(6, ((String[]) members).length);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) GalContact(com.zimbra.cs.account.GalContact) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Domain(com.zimbra.cs.account.Domain) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 8 with GalSearchType

use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.

the class TestLdapProvGal method searchGal.

@Test
public void searchGal() throws Exception {
    SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.DN_SUBTREE_MATCH_FILTER);
    int NUM_ACCTS = 10;
    int SIZE_LIMIT = 5;
    Account user = null;
    for (int i = 0; i < NUM_ACCTS; i++) {
        String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart(String.valueOf(i)));
        Account acct = createAccount(ACCT_NAME_LOCALPART);
        // use the first one as the user
        if (user == null) {
            user = acct;
        }
    }
    GalSearchType type = GalSearchType.account;
    String query = "searchGal";
    GalSearchParams params = new GalSearchParams(user);
    SearchGalResult result = SearchGalResult.newSearchGalResult(null);
    params.setOp(GalOp.search);
    params.setType(type);
    params.createSearchConfig(GalSearchConfig.GalType.zimbra);
    params.setQuery(query);
    params.setLimit(SIZE_LIMIT);
    params.setGalResult(result);
    prov.searchGal(params);
    assertEquals(SIZE_LIMIT, result.getMatches().size());
    assertTrue(result.getHadMore());
    result = prov.searchGal(domain, query, type, 0, null);
    assertEquals(NUM_ACCTS, result.getMatches().size());
    assertFalse(result.getHadMore());
}
Also used : Account(com.zimbra.cs.account.Account) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 9 with GalSearchType

use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.

the class GalSearchControl method ldapSearch.

public void ldapSearch() throws ServiceException {
    Domain domain = mParams.getDomain();
    GalMode galMode = domain.getGalMode();
    GalSearchType stype = mParams.getType();
    Provisioning prov = Provisioning.getInstance();
    if (needResources()) {
        mParams.setType(GalSearchType.resource);
        mParams.createSearchConfig(GalType.zimbra);
        try {
            prov.searchGal(mParams);
        } catch (Exception e) {
            throw ServiceException.FAILURE("ldap search failed", e);
        }
        mParams.setType(stype);
    }
    Integer ldapLimit = mParams.getLdapLimit();
    int limit;
    if (ldapLimit == null)
        limit = mParams.getLimit();
    else
        limit = ldapLimit;
    // restrict to domain config if we are not syncing, and there is no specific ldap limit set
    if (limit == 0 && GalOp.sync != mParams.getOp() && ldapLimit == null) {
        limit = domain.getGalMaxResults();
    }
    // Return the GAL definition last modified time so that clients can use it to decide if fullsync is required.
    if ((mParams.getOp() == GalOp.sync) && (mParams.getResultCallback() != null)) {
        String galLastModified = domain.getGalDefinitionLastModifiedTimeAsString();
        if (galLastModified != null) {
            mParams.getResultCallback().setGalDefinitionLastModified(galLastModified);
        }
    }
    ZimbraLog.gal.info("Using limit %d for ldapSearch", limit);
    mParams.setLimit(limit);
    if (galMode == GalMode.both) {
        // make two gal searches for 1/2 results each
        mParams.setLimit(limit / 2);
    }
    GalType type = GalType.ldap;
    if (galMode != GalMode.ldap) {
        // do zimbra gal search
        type = GalType.zimbra;
    }
    mParams.createSearchConfig(type);
    GalSyncToken galSyncToken = mParams.getGalSyncToken();
    if (galSyncToken != null) {
        mParams.setLdapTimeStamp(galSyncToken.getIntLdapTs());
        mParams.setLdapMatchCount(galSyncToken.getIntLdapMatchCount());
        mParams.setLdapHasMore(galSyncToken.intLdapHasMore());
        mParams.setMaxLdapTimeStamp(galSyncToken.getIntMaxLdapTs());
    }
    try {
        prov.searchGal(mParams);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ldap search failed", e);
    }
    String resultToken = null;
    boolean intLdapHasMore = false;
    boolean extLdapHasMore = false;
    if (mParams.getResult() != null) {
        intLdapHasMore = mParams.getResult().getHadMore();
        if (mParams.getOp() == GalOp.sync) {
            resultToken = getLdapSearchResultToken(mParams.getResult(), "");
        }
    }
    if (galMode == GalMode.both) {
        // do the second query
        mParams.createSearchConfig(GalType.ldap);
        if (galSyncToken != null) {
            mParams.setLdapTimeStamp(galSyncToken.getExtLdapTs());
            mParams.setLdapMatchCount(galSyncToken.getExtLdapMatchCount());
            mParams.setLdapHasMore(galSyncToken.extLdapHasMore());
            mParams.setMaxLdapTimeStamp(galSyncToken.getExtMaxLdapTs());
        }
        try {
            prov.searchGal(mParams);
        } catch (Exception e) {
            throw ServiceException.FAILURE("ldap search failed", e);
        }
        if (mParams.getResult() != null) {
            extLdapHasMore = mParams.getResult().getHadMore();
            if (mParams.getOp() == GalOp.sync) {
                resultToken = getLdapSearchResultToken(mParams.getResult(), resultToken);
            }
        }
    }
    if (mParams.getResultCallback() != null) {
        if (mParams.getOp() == GalOp.sync) {
            mParams.getResultCallback().setNewToken(resultToken);
        }
        mParams.getResultCallback().setHasMoreResult(intLdapHasMore || extLdapHasMore);
    }
}
Also used : GalMode(com.zimbra.common.account.ZAttrProvisioning.GalMode) GalType(com.zimbra.cs.gal.GalSearchConfig.GalType) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 10 with GalSearchType

use of com.zimbra.soap.type.GalSearchType in project zm-mailbox by Zimbra.

the class GalSearchControl method generateSearchQuery.

private void generateSearchQuery(Account galAcct) throws ServiceException {
    String query = mParams.getQuery();
    String searchByDn = mParams.getSearchEntryByDn();
    GalSearchType type = mParams.getType();
    StringBuilder searchQuery = new StringBuilder();
    if (searchByDn != null) {
        searchQuery.append("#dn:(" + searchByDn + ")");
    } else if (!Strings.isNullOrEmpty(query)) {
        searchQuery.append("contact:\"");
        // escape quotes
        searchQuery.append(query.replace("\"", "\\\""));
        searchQuery.append("\" AND");
    }
    GalSearchQueryCallback queryCallback = mParams.getExtraQueryCallback();
    if (queryCallback != null) {
        String extraQuery = queryCallback.getMailboxSearchQuery();
        if (extraQuery != null) {
            ZimbraLog.gal.debug("extra search query: " + extraQuery);
            searchQuery.append(" (").append(extraQuery).append(") AND");
        }
    }
    GalMode galMode = mParams.getDomain().getGalMode();
    boolean first = true;
    for (DataSource ds : galAcct.getAllDataSources()) {
        if (ds.getType() != DataSourceType.gal)
            continue;
        String galType = ds.getAttr(Provisioning.A_zimbraGalType);
        if (galMode == GalMode.ldap && galType.compareTo("zimbra") == 0)
            continue;
        if (galMode == GalMode.zimbra && galType.compareTo("ldap") == 0)
            continue;
        if (first)
            searchQuery.append("(");
        else
            searchQuery.append(" OR");
        first = false;
        searchQuery.append(" inid:").append(ds.getFolderId());
    }
    if (!first)
        searchQuery.append(")");
    switch(type) {
        case resource:
            searchQuery.append(" AND #zimbraAccountCalendarUserType:RESOURCE");
            break;
        case group:
            searchQuery.append(" AND #type:group");
            break;
        case account:
            searchQuery.append(" AND !(#zimbraAccountCalendarUserType:RESOURCE)");
            break;
        case all:
            break;
    }
    ZimbraLog.gal.debug("query: %s", searchQuery);
    mParams.parseSearchParams(mParams.getRequest(), searchQuery.toString());
}
Also used : GalMode(com.zimbra.common.account.ZAttrProvisioning.GalMode) GalSearchType(com.zimbra.soap.type.GalSearchType) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

GalSearchType (com.zimbra.soap.type.GalSearchType)10 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)6 Account (com.zimbra.cs.account.Account)4 Domain (com.zimbra.cs.account.Domain)4 GalSearchControl (com.zimbra.cs.gal.GalSearchControl)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Provisioning (com.zimbra.cs.account.Provisioning)3 GalMode (com.zimbra.common.account.ZAttrProvisioning.GalMode)2 SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)2 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 DataSource (com.zimbra.cs.account.DataSource)1 EntrySearchFilter (com.zimbra.cs.account.EntrySearchFilter)1 GalContact (com.zimbra.cs.account.GalContact)1 DavResource (com.zimbra.cs.dav.resource.DavResource)1 DbDataSource (com.zimbra.cs.db.DbDataSource)1 GalType (com.zimbra.cs.gal.GalSearchConfig.GalType)1 AutoCompleteResult (com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1