Search in sources :

Example 1 with MemberOfSelector

use of com.zimbra.soap.account.type.MemberOfSelector 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 2 with MemberOfSelector

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

the class GetAccountDistributionLists method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account acct = getRequestedAccount(zsc);
    Provisioning prov = Provisioning.getInstance();
    if (!canAccessAccount(zsc, acct)) {
        throw ServiceException.PERM_DENIED("can not access account");
    }
    boolean needOwnerOf = request.getAttributeBool(AccountConstants.A_OWNER_OF, false);
    MemberOfSelector needMemberOf = MemberOfSelector.fromString(request.getAttribute(AccountConstants.A_MEMBER_OF, MemberOfSelector.directOnly.name()));
    Iterable<String> needAttrs = Splitter.on(',').trimResults().split(request.getAttribute(AccountConstants.A_ATTRS, ""));
    Set<Group> ownerOf = null;
    List<Group> memberOf = null;
    HashMap<String, String> via = new HashMap<String, String>();
    if (needOwnerOf) {
        ownerOf = Group.GroupOwner.getOwnedGroups(acct);
    }
    if (MemberOfSelector.none != needMemberOf) {
        memberOf = prov.getGroups(acct, MemberOfSelector.directOnly == needMemberOf, via);
    }
    /*
         * merge the two results into one locale-sensitive sorted list
         */
    Set<Entry> combined = Sets.newHashSet();
    Set<String> combinedIds = Sets.newHashSet();
    Set<String> ownerOfGroupIds = Sets.newHashSet();
    Set<String> memberOfGroupIds = Sets.newHashSet();
    if (ownerOf != null) {
        for (Group group : ownerOf) {
            String groupId = group.getId();
            ownerOfGroupIds.add(groupId);
            if (!combinedIds.contains(groupId)) {
                combined.add(group);
                combinedIds.add(groupId);
            }
        }
    }
    if (memberOf != null) {
        for (Group group : memberOf) {
            String groupId = group.getId();
            memberOfGroupIds.add(groupId);
            if (!combinedIds.contains(groupId)) {
                combined.add(group);
                combinedIds.add(groupId);
            }
        }
    }
    // sort it
    List<Entry> sortedGroups = Entry.sortByDisplayName(combined, acct.getLocale());
    Element response = zsc.createElement(AccountConstants.GET_ACCOUNT_DISTRIBUTION_LISTS_RESPONSE);
    for (Entry entry : sortedGroups) {
        Group group = (Group) entry;
        Element eDL = response.addElement(AccountConstants.E_DL);
        eDL.addAttribute(AccountConstants.A_NAME, group.getName());
        if (group.isDynamic()) {
            eDL.addAttribute(AccountConstants.A_REF, ((LdapDynamicGroup) group).getDN());
        } else {
            eDL.addAttribute(AccountConstants.A_REF, ((LdapDistributionList) group).getDN());
        }
        eDL.addAttribute(AccountConstants.A_ID, group.getId());
        eDL.addAttribute(AccountConstants.A_DISPLAY, group.getDisplayName());
        eDL.addAttribute(AccountConstants.A_DYNAMIC, group.isDynamic());
        boolean isOwner = ownerOfGroupIds.contains(group.getId());
        if (needOwnerOf) {
            eDL.addAttribute(AccountConstants.A_IS_OWNER, isOwner);
        }
        if (MemberOfSelector.none != needMemberOf) {
            boolean isMember = memberOfGroupIds.contains(group.getId());
            eDL.addAttribute(AccountConstants.A_IS_MEMBER, isMember);
            if (isMember) {
                String viaDl = via.get(group.getName());
                if (viaDl != null) {
                    eDL.addAttribute(AccountConstants.A_VIA, viaDl);
                }
            }
        }
        Set<String> returnAttrs = GetDistributionList.visibleAttrs(needAttrs, isOwner);
        if (!returnAttrs.isEmpty()) {
            GetDistributionList.encodeAttrs(group, eDL, returnAttrs);
        }
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) Group(com.zimbra.cs.account.Group) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) Entry(com.zimbra.cs.account.Entry) MemberOfSelector(com.zimbra.soap.account.type.MemberOfSelector) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Aggregations

MemberOfSelector (com.zimbra.soap.account.type.MemberOfSelector)2 Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 Entry (com.zimbra.cs.account.Entry)1 EntrySearchFilter (com.zimbra.cs.account.EntrySearchFilter)1 Group (com.zimbra.cs.account.Group)1 Provisioning (com.zimbra.cs.account.Provisioning)1 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)1 GalSearchControl (com.zimbra.cs.gal.GalSearchControl)1 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GalSearchType (com.zimbra.soap.type.GalSearchType)1 HashMap (java.util.HashMap)1