Search in sources :

Example 1 with EntrySearchFilter

use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.

the class SearchCalendarResources method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    int limit = (int) request.getAttributeLong(AdminConstants.A_LIMIT, Integer.MAX_VALUE);
    if (limit == 0)
        limit = Integer.MAX_VALUE;
    int offset = (int) request.getAttributeLong(AdminConstants.A_OFFSET, 0);
    String domain = request.getAttribute(AdminConstants.A_DOMAIN, null);
    boolean applyCos = request.getAttributeBool(AdminConstants.A_APPLY_COS, true);
    String sortBy = request.getAttribute(AdminConstants.A_SORT_BY, null);
    boolean sortAscending = request.getAttributeBool(AdminConstants.A_SORT_ASCENDING, true);
    String attrsStr = request.getAttribute(AdminConstants.A_ATTRS, null);
    String[] attrs = attrsStr == null ? null : attrsStr.split(",");
    EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
    // Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager
    if (isDomainAdminOnly(zsc)) {
        if (domain == null) {
            domain = getAuthTokenAccountDomain(zsc).getName();
        } else {
            checkDomainRight(zsc, domain, AdminRight.PR_ALWAYS_ALLOW);
        }
    }
    Domain d = null;
    if (domain != null) {
        d = prov.get(Key.DomainBy.name, domain);
        if (d == null)
            throw AccountServiceException.NO_SUCH_DOMAIN(domain);
    }
    AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(zsc);
    AdminAccessControl.SearchDirectoryRightChecker rightChecker = new AdminAccessControl.SearchDirectoryRightChecker(aac, prov, null);
    // filter is not RFC 2254 escaped
    // query is RFC 2254 escaped
    String query = LdapEntrySearchFilter.toLdapCalendarResourcesFilter(filter);
    SearchDirectoryOptions options = new SearchDirectoryOptions();
    options.setDomain(d);
    options.setTypes(SearchDirectoryOptions.ObjectType.resources);
    options.setFilterString(FilterId.ADMIN_SEARCH, query);
    options.setReturnAttrs(attrs);
    options.setSortOpt(sortAscending ? SortOpt.SORT_ASCENDING : SortOpt.SORT_DESCENDING);
    options.setSortAttr(sortBy);
    options.setConvertIDNToAscii(true);
    List<NamedEntry> resources;
    int limitMax = offset + limit;
    AdminSession session = (AdminSession) getSession(zsc, Session.Type.ADMIN);
    if (session != null) {
        resources = session.searchDirectory(options, offset, rightChecker);
    } else {
        resources = prov.searchDirectory(options);
        resources = rightChecker.getAllowed(resources, limitMax);
    }
    Element response = zsc.createElement(AdminConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
    int numEntries;
    for (numEntries = offset; numEntries < limitMax && numEntries < resources.size(); numEntries++) {
        NamedEntry entry = resources.get(numEntries);
        ToXML.encodeCalendarResource(response, (CalendarResource) entry, applyCos, null, aac.getAttrRightChecker(entry));
    }
    response.addAttribute(AdminConstants.A_MORE, numEntries < resources.size());
    response.addAttribute(AdminConstants.A_SEARCH_TOTAL, resources.size());
    return response;
}
Also used : SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) Element(com.zimbra.common.soap.Element) LdapEntrySearchFilter(com.zimbra.cs.account.ldap.LdapEntrySearchFilter) EntrySearchFilter(com.zimbra.cs.account.EntrySearchFilter) Provisioning(com.zimbra.cs.account.Provisioning) NamedEntry(com.zimbra.cs.account.NamedEntry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AdminSession(com.zimbra.cs.session.AdminSession) Domain(com.zimbra.cs.account.Domain)

Example 2 with EntrySearchFilter

use of com.zimbra.cs.account.EntrySearchFilter 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 3 with EntrySearchFilter

use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.

the class LdapEntrySearchFilter method toLdapIDNFilter.

/**
     * Takes a RFC 2254 filter and converts assertions value from unicode to ACE 
     * for IDN attributes.  IDN attributes are those storing the ACE representation 
     * of the unicode.   For non-IDN attributes, assertion values are just passed through. 
     * 
     * e.g.
     * (zimbraMailDeliveryAddress=*@test.中文.com) will be converted to
     * (zimbraMailDeliveryAddress=*@test.xn--fiq228c.com)
     * because zimbraMailDeliveryAddress is an IDN attribute.
     * 
     * (zimbraDomainName=*中文*) will remain the same because zimbraDomainName 
     * is not an IDN attribute.
     *   
     * @param filterStr a RFC 2254 filter (assertion values must be already RFC 2254 escaped)
     * @return
     */
public static String toLdapIDNFilter(String filterStr) {
    String asciiQuery;
    try {
        Term term = LdapFilterParser.parse(filterStr);
        EntrySearchFilter filter = new EntrySearchFilter(term);
        asciiQuery = toLdapIDNFilter(filter);
        ZimbraLog.account.debug("original query=[" + filterStr + "], converted ascii query=[" + asciiQuery + "]");
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to convert query to ascii, using original query: " + filterStr, e);
        asciiQuery = filterStr;
    }
    return asciiQuery;
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) Term(com.zimbra.cs.account.EntrySearchFilter.Term) EntrySearchFilter(com.zimbra.cs.account.EntrySearchFilter)

Example 4 with EntrySearchFilter

use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.

the class SearchCalendarResources method searchGal.

private static Element searchGal(ZimbraSoapContext zsc, Account account, Element request) throws ServiceException {
    Element name = request.getOptionalElement(AccountConstants.E_NAME);
    EntrySearchFilter filter = GalExtraSearchFilter.parseSearchFilter(request);
    GalSearchParams params = new GalSearchParams(account, zsc);
    params.setQuery(name == null ? null : name.getText());
    if (filter != null) {
        params.setExtraQueryCallback(new CalendarResourceExtraQueryCallback(filter));
    }
    params.setType(GalSearchType.resource);
    params.setRequest(request);
    params.setResponseName(AccountConstants.SEARCH_CALENDAR_RESOURCES_RESPONSE);
    // 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);
    // set limit for the LDAP search
    // paging is not supported for LDAP search, set a high limit
    params.setLimit(LC.calendar_resource_ldap_search_maxsize.intValue());
    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 CalendarResourceGalSearchResultCallback(params, filter, attrsSet));
    GalSearchControl gal = new GalSearchControl(params);
    gal.search();
    return params.getResultCallback().getResponse();
}
Also used : GalSearchControl(com.zimbra.cs.gal.GalSearchControl) Element(com.zimbra.common.soap.Element) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) EntrySearchFilter(com.zimbra.cs.account.EntrySearchFilter)

Example 5 with EntrySearchFilter

use of com.zimbra.cs.account.EntrySearchFilter in project zm-mailbox by Zimbra.

the class GalExtraSearchFilter method parseSearchFilter.

public static EntrySearchFilter parseSearchFilter(Element request) throws ServiceException {
    Element filterElem = request.getOptionalElement(AccountConstants.E_ENTRY_SEARCH_FILTER);
    if (filterElem == null) {
        return null;
    }
    Element termElem = filterElem.getOptionalElement(AccountConstants.E_ENTRY_SEARCH_FILTER_MULTICOND);
    if (termElem == null)
        termElem = filterElem.getElement(AccountConstants.E_ENTRY_SEARCH_FILTER_SINGLECOND);
    Term term = GalExtraSearchFilter.parseFilterTermElem(termElem);
    EntrySearchFilter filter = new EntrySearchFilter(term);
    return filter;
}
Also used : Element(com.zimbra.common.soap.Element) Term(com.zimbra.cs.account.EntrySearchFilter.Term) EntrySearchFilter(com.zimbra.cs.account.EntrySearchFilter)

Aggregations

EntrySearchFilter (com.zimbra.cs.account.EntrySearchFilter)5 Element (com.zimbra.common.soap.Element)3 Term (com.zimbra.cs.account.EntrySearchFilter.Term)2 GalSearchControl (com.zimbra.cs.gal.GalSearchControl)2 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)2 ServiceException (com.zimbra.common.service.ServiceException)1 Domain (com.zimbra.cs.account.Domain)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 Provisioning (com.zimbra.cs.account.Provisioning)1 SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)1 LdapEntrySearchFilter (com.zimbra.cs.account.ldap.LdapEntrySearchFilter)1 AdminSession (com.zimbra.cs.session.AdminSession)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 MemberOfSelector (com.zimbra.soap.account.type.MemberOfSelector)1 GalSearchType (com.zimbra.soap.type.GalSearchType)1