Search in sources :

Example 1 with ProxiedDLMembers

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

the class GetDistributionListMembers method getMembersFromLdap.

/*
     * We got here because the group is an internal group.
     *
     * If proxiedToHomeOfInternalGroup is true, this request was proxied to this server because
     * this is the home server of the group.  Just execute locally.
     *
     * If proxiedToHomeOfInternalGroup is false, we need to proxy to the home server of the group
     * if this is not the home server of the group.
     *
     * We could've just rely on the Provisioning.onLocalServer(group), the
     * proxiedToHomeOfInternalGroup flag is just an extra safety latch to ensure we don't get
     * into a proxy loop.
     */
private DLMembersResult getMembersFromLdap(Map<String, Object> context, Element request, Account account, Group group, boolean proxiedToHomeOfInternalGroup) throws ServiceException {
    // proxy to the home server of the group to get members from LDAP.
    // The isOwner/isMember/isHideInGal check will be executed on the
    // home server of the group, which has the most up-to-date data.
    boolean local = proxiedToHomeOfInternalGroup || Provisioning.onLocalServer(group);
    if (local) {
        // do it locally
        return getMembersFromLdap(account, group);
    } else {
        Server server = group.getServer();
        if (server == null) {
            // just execute locally
            ZimbraLog.account.warn("unable to find home server (%s) for group %s, getting members from LDAP on local server", group.getAttr(Provisioning.A_zimbraMailHost), group.getName());
            // do it locally
            return getMembersFromLdap(account, group);
        } else {
            // proxy to the home server of the group
            ZimbraLog.account.debug("Proxying request to home server (%s) of group %s", server.getName(), group.getName());
            request.addAttribute(A_PROXIED_TO_HOME_OF_GROUP, true);
            try {
                Element resp = proxyRequest(request, context, server);
                return new ProxiedDLMembers(resp);
            } catch (ServiceException e) {
                // delete attribute to avoid confusion in future proxied requests
                request.addAttribute(A_PROXIED_TO_HOME_OF_GROUP, (String) null);
                // the GAL search if appropriate.
                return null;
            }
        }
    }
}
Also used : ProxiedDLMembers(com.zimbra.cs.gal.GalGroupMembers.ProxiedDLMembers) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element)

Example 2 with ProxiedDLMembers

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

the class GetDistributionListMembers method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canAccessAccount(zsc, account)) {
        throw ServiceException.PERM_DENIED("can not access account");
    }
    Element eDL = request.getElement(AdminConstants.E_DL);
    String dlName = eDL.getText();
    int offset = getOffset(request);
    int limit = getLimit(request);
    // null offset/limit and set _offset/_limit before calling searchGal().
    request.addAttribute(MailConstants.A_QUERY_OFFSET, (String) null);
    request.addAttribute(MailConstants.A_LIMIT, (String) null);
    request.addAttribute(AccountConstants.A_OFFSET_INTERNAL, offset);
    request.addAttribute(AccountConstants.A_LIMIT_INTERNAL, limit);
    boolean proxiedToHomeOfInternalGroup = request.getAttributeBool(A_PROXIED_TO_HOME_OF_GROUP, false);
    DLMembersResult dlMembersResult = null;
    /*
         * see if the group is an internal group
         */
    Provisioning prov = Provisioning.getInstance();
    Group group = prov.getGroupBasic(DistributionListBy.name, dlName);
    if (group != null) {
        /*
             * Is an internal group, get members from LDAP instead of GAL
             * for group owners and members.
             *
             * This makes updates on internal groups reflected in the UI
             * sooner than the next GSA delta sync cycle for group owners and members.
             * (bug 72482 and bug 73460).
             */
        dlMembersResult = getMembersFromLdap(context, request, account, group, proxiedToHomeOfInternalGroup);
    }
    if (dlMembersResult == null) {
        /*
             * - this is not an internal group, or
             * - this is an internal group but the requesting account is not an owner
             *   or member of the group, or
             * - this is an internal hideInGal group and the requesting account is not
             *   an owner of the group.
             *
             * Do GAL search if this is not a hideInGal group.  This check is a small
             * optimization and is not necessary, because if the group is hideInGal, it
             * won't be found in GAL anyway, so just save the GAL search.
             *
             * If proxiedToHomeOfInternalGroup is true, we were proxied here from inside the
             * getMembersFromLdap() path in the previous hop.  We must have gone into the above
             * getMembersFromLdap() in this hop, and it returned null (or in a nearly
             * impossible case the group cannot be found in this server and we did not
             * even go into the above getMembersFromLdap).  In this case, do not do
             * a GAL search, because the GAL search could once again proxy the request
             * to the GAL sync account's home server.  We will just leave dlMembersResult
             * null and let the NO_SUCH_DISTRIBUTION_LIST be thrown.  When the
             * NO_SUCH_DISTRIBUTION_LIST got back to the previous hop, in
             * getMembersFromLdap, it will return null and control will reach here again
             * (in the "previous" hop).   Now, since the proxiedToHomeOfInternalGroup
             * flag is not on, we will proceed to do the GAL search if the group is not hideInGal.
             */
        boolean hideInGal = (group != null && group.hideInGal());
        if (!hideInGal && !proxiedToHomeOfInternalGroup) {
            dlMembersResult = GalGroupMembers.searchGal(zsc, account, dlName, request);
        }
    }
    if (dlMembersResult == null) {
        throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(dlName);
    }
    if (dlMembersResult instanceof ProxiedDLMembers) {
        return ((ProxiedDLMembers) dlMembersResult).getResponse();
    } else if (dlMembersResult instanceof DLMembers) {
        return processDLMembers(zsc, dlName, account, limit, offset, (DLMembers) dlMembersResult);
    } else {
        throw ServiceException.FAILURE("unsopported DLMembersResult class: " + dlMembersResult.getClass().getCanonicalName(), null);
    }
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) ProxiedDLMembers(com.zimbra.cs.gal.GalGroupMembers.ProxiedDLMembers) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) DLMembersResult(com.zimbra.cs.gal.GalGroupMembers.DLMembersResult) ProxiedDLMembers(com.zimbra.cs.gal.GalGroupMembers.ProxiedDLMembers) DLMembers(com.zimbra.cs.gal.GalGroupMembers.DLMembers) LdapDLMembers(com.zimbra.cs.gal.GalGroupMembers.LdapDLMembers)

Aggregations

Element (com.zimbra.common.soap.Element)2 ProxiedDLMembers (com.zimbra.cs.gal.GalGroupMembers.ProxiedDLMembers)2 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Group (com.zimbra.cs.account.Group)1 Provisioning (com.zimbra.cs.account.Provisioning)1 Server (com.zimbra.cs.account.Server)1 DLMembers (com.zimbra.cs.gal.GalGroupMembers.DLMembers)1 DLMembersResult (com.zimbra.cs.gal.GalGroupMembers.DLMembersResult)1 LdapDLMembers (com.zimbra.cs.gal.GalGroupMembers.LdapDLMembers)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1