Search in sources :

Example 6 with DistributionList

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

the class CollectAllEffectiveRights method setupShapeTest2.

private static void setupShapeTest2() throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    // create test
    String domainName = "test.com";
    Domain domain = prov.createDomain(domainName, new HashMap<String, Object>());
    DistributionList groupA = prov.createDistributionList("groupA@" + domainName, new HashMap<String, Object>());
    DistributionList groupB = prov.createDistributionList("groupB@" + domainName, new HashMap<String, Object>());
    DistributionList groupC = prov.createDistributionList("groupC@" + domainName, new HashMap<String, Object>());
    DistributionList groupD = prov.createDistributionList("groupD@" + domainName, new HashMap<String, Object>());
    String pw = "test123";
    Account A = prov.createAccount("A@" + domainName, pw, null);
    Account B = prov.createAccount("B@" + domainName, pw, null);
    Account C = prov.createAccount("C@" + domainName, pw, null);
    Account D = prov.createAccount("D@" + domainName, pw, null);
    groupA.addMembers(new String[] { A.getName(), groupB.getName() });
    groupB.addMembers(new String[] { B.getName(), groupC.getName() });
    groupC.addMembers(new String[] { C.getName(), groupD.getName() });
    groupD.addMembers(new String[] { D.getName() });
}
Also used : Account(com.zimbra.cs.account.Account) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) DistributionList(com.zimbra.cs.account.DistributionList)

Example 7 with DistributionList

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

the class CollectAllEffectiveRights method shapeTest2.

private static void shapeTest2() throws ServiceException {
    setupShapeTest2();
    Provisioning prov = Provisioning.getInstance();
    // create test
    Set<DistributionList> groupsWithGrants = new HashSet<DistributionList>();
    String domainName = "test.com";
    groupsWithGrants.add(prov.get(DistributionListBy.name, "groupA@" + domainName));
    groupsWithGrants.add(prov.get(DistributionListBy.name, "groupB@" + domainName));
    groupsWithGrants.add(prov.get(DistributionListBy.name, "groupC@" + domainName));
    groupsWithGrants.add(prov.get(DistributionListBy.name, "groupD@" + domainName));
    Set<GroupShape> accountShapes = new HashSet<GroupShape>();
    Set<GroupShape> calendarResourceShapes = new HashSet<GroupShape>();
    Set<GroupShape> distributionListShapes = new HashSet<GroupShape>();
    for (DistributionList group : groupsWithGrants) {
        // group is an AclGroup, which contains only upward membership, not downward membership.
        // re-get the DistributionList object, which has the downward membership.
        DistributionList dl = prov.get(DistributionListBy.id, group.getId());
        AllGroupMembers allMembers = allGroupMembers(dl);
        GroupShape.shapeMembers(TargetType.account, accountShapes, allMembers);
        GroupShape.shapeMembers(TargetType.calresource, calendarResourceShapes, allMembers);
        GroupShape.shapeMembers(TargetType.dl, distributionListShapes, allMembers);
    }
    int count = 1;
    for (GroupShape shape : accountShapes) {
        System.out.println("\n" + count++);
        for (String group : shape.getGroups()) System.out.println("group " + group);
        for (String member : shape.getMembers()) System.out.println("    " + member);
    }
}
Also used : Provisioning(com.zimbra.cs.account.Provisioning) HashSet(java.util.HashSet) DistributionList(com.zimbra.cs.account.DistributionList)

Example 8 with DistributionList

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

the class AccountStatus method handleAccountStatusClosed.

private void handleAccountStatusClosed(Account account) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    String status = account.getAccountStatus(prov);
    if (status.equals(Provisioning.ACCOUNT_STATUS_CLOSED)) {
        ZimbraLog.misc.info("removing account address and all its aliases from all distribution lists");
        String[] addrToRemove = new String[] { account.getName() };
        Set<String> dlIds = prov.getDistributionLists(account);
        for (String dlId : dlIds) {
            DistributionList dl = prov.get(Key.DistributionListBy.id, dlId);
            if (dl != null) {
                try {
                    // will remove all members that are aliases of the account too
                    prov.removeMembers(dl, addrToRemove);
                } catch (ServiceException se) {
                    if (AccountServiceException.NO_SUCH_MEMBER.equals(se.getCode())) {
                        ZimbraLog.misc.debug("Member not found in dlist; skipping", se);
                    } else {
                        throw se;
                    }
                }
            }
        }
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning) DistributionList(com.zimbra.cs.account.DistributionList)

Example 9 with DistributionList

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

the class AdminGroup method postModify.

@Override
public void postModify(CallbackContext context, String attrName, Entry entry) {
    if (!(entry instanceof DistributionList))
        return;
    Provisioning prov = Provisioning.getInstance();
    if (!(prov instanceof LdapProv))
        return;
    DistributionList group = (DistributionList) entry;
    ((LdapProv) prov).removeFromCache(group);
}
Also used : Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv) DistributionList(com.zimbra.cs.account.DistributionList)

Example 10 with DistributionList

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

the class DisplayName method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
    if (!((entry instanceof Account) || (entry instanceof DistributionList)))
        return;
    String displayName;
    // update cn only if we are not unsetting display name(cn is required for ZIMBRA_DEFAULT_PERSON_OC)
    SingleValueMod mod = singleValueMod(attrName, value);
    if (mod.unsetting())
        return;
    else
        displayName = mod.value();
    String namingRdnAttr = null;
    Provisioning prov = Provisioning.getInstance();
    if (prov instanceof LdapProv) {
        namingRdnAttr = ((LdapProv) prov).getDIT().getNamingRdnAttr(entry);
    }
    // update cn only if it is not the naming attr
    if (// non LdapProvisioning, pass thru
    namingRdnAttr == null || !namingRdnAttr.equals(Provisioning.A_cn)) {
        if (!attrsToModify.containsKey(Provisioning.A_cn)) {
            attrsToModify.put(Provisioning.A_cn, displayName);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv) DistributionList(com.zimbra.cs.account.DistributionList)

Aggregations

DistributionList (com.zimbra.cs.account.DistributionList)120 Account (com.zimbra.cs.account.Account)58 Domain (com.zimbra.cs.account.Domain)43 HashMap (java.util.HashMap)24 Test (org.junit.Test)24 Provisioning (com.zimbra.cs.account.Provisioning)22 NamedEntry (com.zimbra.cs.account.NamedEntry)18 HashSet (java.util.HashSet)18 ArrayList (java.util.ArrayList)14 ServiceException (com.zimbra.common.service.ServiceException)13 AccountServiceException (com.zimbra.cs.account.AccountServiceException)13 Right (com.zimbra.cs.account.accesscontrol.Right)12 DynamicGroup (com.zimbra.cs.account.DynamicGroup)10 LdapDistributionList (com.zimbra.cs.account.ldap.entry.LdapDistributionList)10 Group (com.zimbra.cs.account.Group)9 GuestAccount (com.zimbra.cs.account.GuestAccount)9 LdapProv (com.zimbra.cs.account.ldap.LdapProv)8 List (java.util.List)7 Entry (com.zimbra.cs.account.Entry)6 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)6