Search in sources :

Example 1 with DistributionListSelector

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

the class GetAdminConsoleUIComp method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetAdminConsoleUICompRequest req = JaxbUtil.elementToJaxb(request);
    AccountSelector accountSel = req.getAccount();
    DistributionListSelector dlSel = req.getDl();
    Element resp = zsc.createElement(AdminConstants.GET_ADMIN_CONSOLE_UI_COMP_RESPONSE);
    if ((null != accountSel) && (null != dlSel)) {
        throw ServiceException.INVALID_REQUEST("can only specify eith account or dl", null);
    }
    Account authedAcct = getAuthenticatedAccount(zsc);
    Set<String> added = new HashSet<String>();
    GroupMembership aclGroups = null;
    if (accountSel != null) {
        AccountBy by = accountSel.getBy().toKeyAccountBy();
        String key = accountSel.getKey();
        Account acct = prov.get(by, key);
        AccountHarvestingCheckerUsingCheckRight checker = new AccountHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewAccountAdminUI);
        if (acct == null) {
            defendAgainstAccountHarvestingWhenAbsent(by, key, zsc, checker);
        } else {
            if (!authedAcct.getId().equals(acct.getId())) {
                defendAgainstAccountHarvesting(acct, by, key, zsc, checker);
            }
            addValues(acct, resp, added, false);
            aclGroups = prov.getGroupMembership(acct, true);
        }
    } else if (dlSel != null) {
        Key.DistributionListBy by = dlSel.getBy().toKeyDistributionListBy();
        String key = dlSel.getKey();
        DistributionList dl = prov.getDLBasic(by, key);
        GroupHarvestingCheckerUsingCheckRight checker = new GroupHarvestingCheckerUsingCheckRight(zsc, context, Admin.R_viewDistributionListAdminUI);
        if (dl == null) {
            defendAgainstGroupHarvestingWhenAbsent(by, key, zsc, checker);
        } else {
            defendAgainstGroupHarvesting(dl, by, key, zsc, checker);
            addValues(dl, resp, added, false);
            aclGroups = prov.getGroupMembership(dl, true);
        }
    } else {
        // use the authed account
        addValues(authedAcct, resp, added, false);
        aclGroups = prov.getGroupMembership(authedAcct, true);
    }
    if (aclGroups != null) {
        for (String groupId : aclGroups.groupIds()) {
            DistributionList dl = prov.get(Key.DistributionListBy.id, groupId);
            addValues(dl, resp, added, true);
        }
    }
    return resp;
}
Also used : Account(com.zimbra.cs.account.Account) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) GroupMembership(com.zimbra.cs.account.Provisioning.GroupMembership) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetAdminConsoleUICompRequest(com.zimbra.soap.admin.message.GetAdminConsoleUICompRequest) HashSet(java.util.HashSet) DistributionList(com.zimbra.cs.account.DistributionList)

Example 2 with DistributionListSelector

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

the class GetDistributionList method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    GetDistributionListRequest req = JaxbUtil.elementToJaxb(request);
    int limit = (req.getLimit() == null) ? 0 : req.getLimit();
    if (limit < 0) {
        throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
    }
    int offset = (req.getOffset() == null) ? 0 : req.getOffset();
    if (offset < 0) {
        throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
    }
    boolean sortAscending = !Boolean.FALSE.equals(req.isSortAscending());
    Set<String> reqAttrs = getReqAttrs(req.getAttrs(), AttributeClass.distributionList);
    DistributionListSelector dlSel = req.getDl();
    DistributionListBy dlBy = dlSel.getBy().toKeyDistributionListBy();
    AttrRightChecker arc = null;
    Group group = getGroupFromContext(context);
    if (group == null) {
        if (DistributionListBy.name.equals(dlBy)) {
            Entry pseudoTarget = pseudoTargetInSameDomainAsEmail(TargetType.dl, dlSel.getKey());
            if (null != pseudoTarget) {
                AdminAccessControl aac = checkDistributionListRight(zsc, (DistributionList) pseudoTarget, AdminRight.PR_ALWAYS_ALLOW);
                arc = aac.getAttrRightChecker(pseudoTarget);
            }
        }
        if (arc != null) {
            defendAgainstGroupHarvestingWhenAbsent(dlBy, dlSel.getKey(), zsc, new GroupHarvestingCheckerUsingGetAttrsPerms(zsc, arc, Arrays.asList(minimumAttrs)));
        } else {
            defendAgainstGroupHarvestingWhenAbsent(dlBy, dlSel.getKey(), zsc, Admin.R_getDistributionList);
        }
    } else if (group.isDynamic()) {
        AdminAccessControl aac = checkDynamicGroupRight(zsc, (DynamicGroup) group, AdminRight.PR_ALWAYS_ALLOW);
        arc = aac.getAttrRightChecker(group);
    } else {
        AdminAccessControl aac = checkDistributionListRight(zsc, (DistributionList) group, AdminRight.PR_ALWAYS_ALLOW);
        arc = aac.getAttrRightChecker(group);
    }
    defendAgainstGroupHarvesting(group, dlBy, dlSel.getKey(), zsc, new GroupHarvestingCheckerUsingGetAttrsPerms(zsc, arc, Arrays.asList(minimumAttrs)));
    Element response = zsc.createElement(AdminConstants.GET_DISTRIBUTION_LIST_RESPONSE);
    Element eDL = encodeDistributionList(response, group, true, false, reqAttrs, arc);
    // return member info only if the authed has right to see zimbraMailForwardingAddress
    boolean allowMembers = true;
    if (group.isDynamic()) {
        allowMembers = arc == null ? true : arc.allowAttr(Provisioning.A_member);
    } else {
        allowMembers = arc == null ? true : arc.allowAttr(Provisioning.A_zimbraMailForwardingAddress);
    }
    if (allowMembers) {
        encodeMembers(response, eDL, group, offset, limit, sortAscending);
    }
    return response;
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) DistributionListBy(com.zimbra.common.account.Key.DistributionListBy) Element(com.zimbra.common.soap.Element) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) GetDistributionListRequest(com.zimbra.soap.admin.message.GetDistributionListRequest) AttrRightChecker(com.zimbra.cs.account.AccessManager.AttrRightChecker) Entry(com.zimbra.cs.account.Entry) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DistributionList(com.zimbra.cs.account.DistributionList)

Example 3 with DistributionListSelector

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

the class GetDistributionListMembership method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetDistributionListMembershipRequest req = JaxbUtil.elementToJaxb(request);
    int limit = (req.getLimit() == null) ? 0 : req.getLimit();
    if (limit < 0) {
        throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
    }
    int offset = (req.getOffset() == null) ? 0 : req.getOffset();
    if (offset < 0) {
        throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
    }
    DistributionListSelector dlSel = req.getDl();
    DistributionListBy dlBy = dlSel.getBy().toKeyDistributionListBy();
    String dlKey = dlSel.getKey();
    DistributionList distributionList = prov.get(dlBy, dlKey);
    defendAgainstGroupHarvesting(distributionList, dlBy, dlKey, zsc, Admin.R_getDistributionListMembership, /* shouldn't be used */
    Admin.R_getDistributionListMembership);
    HashMap<String, String> via = new HashMap<String, String>();
    List<DistributionList> lists = prov.getDistributionLists(distributionList, false, via);
    Element response = zsc.createElement(AdminConstants.GET_DISTRIBUTION_LIST_MEMBERSHIP_RESPONSE);
    for (DistributionList dl : lists) {
        Element dlEl = response.addNonUniqueElement(AdminConstants.E_DL);
        dlEl.addAttribute(AdminConstants.A_NAME, dl.getName());
        dlEl.addAttribute(AdminConstants.A_ID, dl.getId());
        String viaDl = via.get(dl.getName());
        if (viaDl != null)
            dlEl.addAttribute(AdminConstants.A_VIA, viaDl);
    }
    return response;
}
Also used : GetDistributionListMembershipRequest(com.zimbra.soap.admin.message.GetDistributionListMembershipRequest) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DistributionListBy(com.zimbra.common.account.Key.DistributionListBy) Element(com.zimbra.common.soap.Element) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) Provisioning(com.zimbra.cs.account.Provisioning) DistributionList(com.zimbra.cs.account.DistributionList)

Aggregations

Element (com.zimbra.common.soap.Element)3 DistributionList (com.zimbra.cs.account.DistributionList)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 DistributionListSelector (com.zimbra.soap.admin.type.DistributionListSelector)3 DistributionListBy (com.zimbra.common.account.Key.DistributionListBy)2 Provisioning (com.zimbra.cs.account.Provisioning)2 AccountBy (com.zimbra.common.account.Key.AccountBy)1 AttrRightChecker (com.zimbra.cs.account.AccessManager.AttrRightChecker)1 Account (com.zimbra.cs.account.Account)1 DynamicGroup (com.zimbra.cs.account.DynamicGroup)1 Entry (com.zimbra.cs.account.Entry)1 Group (com.zimbra.cs.account.Group)1 GroupMembership (com.zimbra.cs.account.Provisioning.GroupMembership)1 GetAdminConsoleUICompRequest (com.zimbra.soap.admin.message.GetAdminConsoleUICompRequest)1 GetDistributionListMembershipRequest (com.zimbra.soap.admin.message.GetDistributionListMembershipRequest)1 GetDistributionListRequest (com.zimbra.soap.admin.message.GetDistributionListRequest)1 AccountSelector (com.zimbra.soap.type.AccountSelector)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1