Search in sources :

Example 51 with Group

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

the class MilterHandler method SMFIC_BodyEOB.

private void SMFIC_BodyEOB() throws IOException {
    ZimbraLog.milter.debug("SMFIC_BodyEOB");
    Set<String> listAddrs = Sets.newHashSetWithExpectedSize(lists.size());
    Set<String> replyToAddrs = Sets.newHashSetWithExpectedSize(lists.size());
    for (Group group : lists) {
        if (group == null) {
            ZimbraLog.milter.warn("null group in group list!?!");
            continue;
        }
        if (visibleAddresses.contains(group.getMail().toLowerCase())) {
            listAddrs.add(group.getMail());
            if (group.isPrefReplyToEnabled()) {
                String addr = group.getPrefReplyToAddress();
                if (Strings.isNullOrEmpty(addr)) {
                    // fallback to the default email address
                    addr = group.getMail();
                }
                String disp = group.getPrefReplyToDisplay();
                if (Strings.isNullOrEmpty(disp)) {
                    // fallback to the default display name
                    disp = group.getDisplayName();
                }
                replyToAddrs.add(new InternetAddress(disp, addr).toString());
            }
        }
    }
    if (!listAddrs.isEmpty()) {
        SMFIR_ChgHeader(1, "X-Zimbra-DL", Joiner.on(", ").join(listAddrs));
    }
    if (!replyToAddrs.isEmpty()) {
        SMFIR_ChgHeader(1, "Reply-To", Joiner.on(", ").join(replyToAddrs));
    }
    connection.send(new MilterPacket(SMFIR_ACCEPT));
}
Also used : Group(com.zimbra.cs.account.Group) InternetAddress(com.zimbra.common.mime.InternetAddress)

Example 52 with Group

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

the class MilterHandler method SMFIC_Rcpt.

private void SMFIC_Rcpt() throws ServiceException {
    ZimbraLog.milter.debug("SMFIC_Rcpt");
    String sender = context.get(Context.SENDER);
    if (sender == null) {
        ZimbraLog.milter.warn("Empty sender");
    }
    String rcpt = context.get(Context.RECIPIENT);
    if (rcpt == null) {
        ZimbraLog.milter.warn("Empty recipient");
    }
    if (sender == null || rcpt == null) {
        connection.send(new MilterPacket(SMFIR_TEMPFAIL));
        return;
    }
    if (prov.isDistributionList(rcpt)) {
        Group group = prov.getGroupBasic(Key.DistributionListBy.name, rcpt);
        if (group != null) {
            if (!accessMgr.canDo(sender, group, User.R_sendToDistList, false)) {
                ZimbraLog.milter.debug("Sender is not allowed to email this distribution list: %s", rcpt);
                SMFIR_ReplyCode("571", "571 Sender is not allowed to email this distribution list: " + rcpt);
                return;
            }
            lists.add(group);
            ZimbraLog.milter.debug("group %s has been added into the list.", group);
        } else {
            ZimbraLog.milter.debug("rcpt %s is a list but not a group?", rcpt);
        }
    } else {
        ZimbraLog.milter.debug("%s is not a distribution list.", rcpt);
    }
    connection.send(new MilterPacket(SMFIR_CONTINUE));
}
Also used : Group(com.zimbra.cs.account.Group)

Example 53 with Group

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

the class GetAllDistributionLists method doDomain.

private void doDomain(ZimbraSoapContext zsc, Element e, Domain d, AdminAccessControl aac) throws ServiceException {
    List dls = Provisioning.getInstance().getAllGroups(d);
    for (Iterator it = dls.iterator(); it.hasNext(); ) {
        Group dl = (Group) it.next();
        boolean hasRightToList = true;
        if (dl.isDynamic()) {
            // TODO: fix me
            hasRightToList = true;
        } else {
            hasRightToList = aac.hasRightsToList(dl, Admin.R_listDistributionList, null);
        }
        if (hasRightToList) {
            GetDistributionList.encodeDistributionList(e, dl, true, false, null, aac.getAttrRightChecker(dl));
        }
    }
}
Also used : Group(com.zimbra.cs.account.Group) Iterator(java.util.Iterator) DistributionList(com.zimbra.cs.account.DistributionList) List(java.util.List)

Example 54 with Group

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

the class SmtpRecipientValidator method validate.

@Override
public Iterable<String> validate(String recipient) {
    try {
        Provisioning prov = Provisioning.getInstance();
        Account account = prov.get(AccountBy.name, recipient);
        if (account != null) {
            return Arrays.asList(account.getName());
        } else {
            Group group = prov.getGroup(Key.DistributionListBy.name, recipient);
            if (group != null) {
                String[] members;
                if (group instanceof DynamicGroup) {
                    members = ((DynamicGroup) group).getAllMembers(true);
                } else {
                    members = group.getAllMembers();
                }
                return Arrays.asList(members);
            }
        }
    } catch (ServiceException e) {
        log.error("Unable to validate recipient %s", recipient, e);
    }
    return Collections.emptyList();
}
Also used : Account(com.zimbra.cs.account.Account) DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) DynamicGroup(com.zimbra.cs.account.DynamicGroup) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning)

Example 55 with Group

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

the class TestACLEffectiveRights method bug70206.

@Bug(bug = 70206)
@Test
public void bug70206() throws Exception {
    Account acct = provUtil.createDelegatedAdmin(genAcctNameLocalPart(), domain);
    Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, false);
    Account grantingAccount = globalAdmin;
    String presetRightUnderTest = Right.RT_deleteDistributionList;
    String attrUnderTest = Provisioning.A_zimbraHideInGal;
    String attrRightUnderTest = InlineAttrRight.composeSetRight(TargetType.dl, attrUnderTest);
    // grant a combo right on global level
    RightCommand.grantRight(prov, grantingAccount, TargetType.global.getCode(), null, null, GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, Right.RT_adminConsoleDLRights, null);
    // deny a preset right (in the combo right) on global level
    RightCommand.grantRight(prov, grantingAccount, TargetType.global.getCode(), null, null, GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, presetRightUnderTest, RightModifier.RM_DENY);
    // grant the preset right on the target
    RightCommand.grantRight(prov, grantingAccount, TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, attrRightUnderTest, null);
    // deny an attr right (in the combo right) on global level
    RightCommand.grantRight(prov, grantingAccount, TargetType.global.getCode(), null, null, GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, attrRightUnderTest, RightModifier.RM_DENY);
    // grant the attr right on the target
    RightCommand.grantRight(prov, grantingAccount, TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, presetRightUnderTest, null);
    EffectiveRights effRights = RightCommand.getEffectiveRights(prov, TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeBy.name, acct.getName(), false, false);
    List<String> presetRights = effRights.presetRights();
    SortedMap<String, EffectiveAttr> setAttrRights = effRights.canSetAttrs();
    /*
        for (String right : presetRights) {
            System.out.println(right);
        }
        */
    assertTrue(presetRights.contains(Right.RT_deleteDistributionList));
    assertTrue(setAttrRights.containsKey(attrUnderTest));
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) EffectiveAttr(com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveAttr) EffectiveRights(com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveRights) AllEffectiveRights(com.zimbra.cs.account.accesscontrol.RightCommand.AllEffectiveRights) Bug(com.zimbra.qa.QA.Bug) Test(org.junit.Test)

Aggregations

Group (com.zimbra.cs.account.Group)110 Account (com.zimbra.cs.account.Account)53 Test (org.junit.Test)42 DynamicGroup (com.zimbra.cs.account.DynamicGroup)27 ServiceException (com.zimbra.common.service.ServiceException)23 SoapTransport (com.zimbra.common.soap.SoapTransport)23 Provisioning (com.zimbra.cs.account.Provisioning)23 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)21 Domain (com.zimbra.cs.account.Domain)17 GuestAccount (com.zimbra.cs.account.GuestAccount)17 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 Element (com.zimbra.common.soap.Element)16 AccountServiceException (com.zimbra.cs.account.AccountServiceException)15 NamedEntry (com.zimbra.cs.account.NamedEntry)14 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)12 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 DistributionList (com.zimbra.cs.account.DistributionList)9 Entry (com.zimbra.cs.account.Entry)9