Search in sources :

Example 26 with Group

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

the class TestGroups method createCustomDynamicGroupWhoseMembersShareCOS.

public static Group createCustomDynamicGroupWhoseMembersShareCOS(String name, String cosName) throws Exception {
    Provisioning prov = Provisioning.getInstance();
    String dName = name.substring(0, name.indexOf('@') - 1);
    Group group = prov.getGroup(Key.DistributionListBy.name, name, true);
    if (group != null) {
        ZimbraLog.test.warn("createCustomDynamicGroupWhoseMembersShareCOS(%s) - already existed!!!", name);
        return group;
    }
    Map<String, Object> attrs = Maps.newHashMap();
    Cos cos = prov.get(Key.CosBy.name, cosName);
    attrs.put(ZAttrProvisioning.A_memberURL, String.format("ldap:///??sub?(&(objectClass=zimbraAccount)(zimbraCOSId=%s)(zimbraAccountStatus=active))", cos.getId()));
    attrs.put(ZAttrProvisioning.A_zimbraIsACLGroup, "TRUE");
    attrs.put(ZAttrProvisioning.A_zimbraMailStatus, "enabled");
    attrs.put(ZAttrProvisioning.A_displayName, dName);
    group = prov.createGroup(name, attrs, true);
    if (group == null) {
        ZimbraLog.test.debug("ensureCustomDynamicGroupExists returning null for '%s'", name);
    }
    return group;
}
Also used : Group(com.zimbra.cs.account.Group) Cos(com.zimbra.cs.account.Cos) ZAttrProvisioning(com.zimbra.common.account.ZAttrProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) LdapProvisioning(com.zimbra.cs.account.ldap.LdapProvisioning)

Example 27 with Group

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

the class TestGroups method setUp.

@Override
public void setUp() throws Exception {
    ldapProv = (LdapProvisioning) Provisioning.getInstance();
    if (soapProv == null) {
        soapProv = TestUtil.newSoapProvisioning();
    }
    tearDown();
    domain = createDomain(domainName);
    domain1 = createDomain(domainName1);
    domain2 = createDomain(domainName2);
    for (int cnt = 1; cnt <= NUM_COS; cnt++) {
        createCos(String.format(cosPatt, cnt));
    }
    groups.clear();
    for (int cnt = 1; cnt <= NUM_CUSTOM_DL; cnt++) {
        TestUtil.deleteAccount(String.format(customDLPatt, cnt));
        Group grp = createCustomDynamicGroupWhoseMembersShareCOS(String.format(customDLPatt, cnt), String.format(cosPatt, cnt));
        groups.put(grp.getId(), grp);
    }
    List<String> staticMembers = Lists.newArrayList();
    List<String> dynamicMembers = Lists.newArrayList();
    for (int cnt = 1; cnt <= NUM_ACCOUNTS; cnt++) {
        int cosChoice = cnt % NUM_COS + 1;
        createAccountAsMemberOfCOS(String.format(acctPatt, cnt), String.format(cosPatt, cosChoice));
        if (cnt % 2 == 0) {
            staticMembers.add(String.format(acctPatt, cnt));
        }
        if (cnt % 3 == 0) {
            dynamicMembers.add(String.format(acctPatt, cnt));
        }
    }
    createAccountWithAlias(acctWithAlias, acctAlias);
    createAccountWithAlias(acctWithAlias2, acctAlias2);
    staticMembers.add(acctAlias);
    DistributionList dlalias = createDistributionList(dlWithAlias);
    dlalias.addAlias(dlAlias);
    DistributionList dlalias2 = createDistributionList(dlWithAlias2);
    dlalias2.addAlias(dlAlias2);
    String[] aliasmems = { dlAlias2 };
    dlalias.addMembers(aliasmems);
    String[] aliasmems2 = { acctAlias, acctAlias2 };
    dlalias2.addMembers(aliasmems2);
    for (int cnt = 1; cnt <= NUM_NORMAL_DL; cnt++) {
        DistributionList dl = createDistributionList(String.format(normalDLPatt, cnt));
        groups.put(dl.getId(), dl);
        dl.addMembers(staticMembers.toArray(new String[staticMembers.size()]));
        for (String mem : staticMembers) {
            ZimbraLog.test.info("SETUP Distribution List %s has member acct=%s", dl.getName(), mem);
        }
    }
    for (int cnt = 1; cnt <= NUM_DYNAMIC_DL; cnt++) {
        Group grp = createDynamicGroup(String.format(dynamicDLPatt, cnt));
        groups.put(grp.getId(), grp);
        ldapProv.addGroupMembers(grp, dynamicMembers.toArray(new String[dynamicMembers.size()]));
        for (String mem : dynamicMembers) {
            ZimbraLog.test.info("SETUP Dynamic Group %s has member acct=%s", grp.getName(), mem);
        }
    }
    String groupName = String.format(customDLPatt, 1);
    // account4 should match this
    // account2 should NOT match this
    // account3 should NOT match this
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_createDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_createDistList, groupName, domain.getName());
    // account4 should match this
    // account2 should match this
    // account3 should NOT match this
    groupName = String.format(normalDLPatt, 1);
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain1.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_createDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_createDistList, groupName, domain.getName());
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_sendToDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_sendToDistList, groupName, domain.getName());
    // account4 should NOT match this
    // account2 should NOT match this
    // account3 should match this
    groupName = String.format(dynamicDLPatt, 1);
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain2.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_createDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_createDistList, groupName, domain.getName());
    // account4 should NOT match this
    // account2 should NOT match this
    // account3 should match this
    groupName = String.format(dynamicDLPatt, 2);
    ldapProv.grantRight("domain", /* targetType */
    TargetBy.name, /* targetBy */
    domain2.getName(), /* target */
    "grp", /* granteeType */
    GranteeSelector.GranteeBy.name, /* granteeBy */
    groupName, /* grantee */
    null, /* secret */
    RightConsts.RT_sendToDistList, /* right */
    null);
    ZimbraLog.test.info("SETUP Granted %s to Group %s for dom=%s", RightConsts.RT_sendToDistList, groupName, domain.getName());
}
Also used : Group(com.zimbra.cs.account.Group) DistributionList(com.zimbra.cs.account.DistributionList)

Example 28 with Group

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

the class GalGroup method canExpandGroup.

private static boolean canExpandGroup(Provisioning prov, String groupName, Account authedAcct) {
    try {
        // get the dl object for ACL checking
        ZimbraLog.gal.trace("GalGroup - canExpandGroup() account [%s] group [%s]", authedAcct == null ? "null" : authedAcct.getName(), groupName);
        Group group = prov.getGroupBasic(Key.DistributionListBy.name, groupName);
        // or should we just let the request through?
        if (group == null) {
            ZimbraLog.gal.warn("GalGroup - unable to find group " + groupName + " for permission checking");
            return false;
        }
        if (!AccessManager.getInstance().canDo(authedAcct, group, User.R_viewDistList, false)) {
            ZimbraLog.gal.trace("GalGroup - canDo returned false");
            return false;
        }
    } catch (ServiceException e) {
        ZimbraLog.gal.warn("GalGroup - unable to check permission for gal group expansion: " + groupName);
        return false;
    }
    ZimbraLog.gal.trace("GalGroup - canExpandGroup() true");
    return true;
}
Also used : Group(com.zimbra.cs.account.Group) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException)

Example 29 with Group

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

the class SubscribeDistributionList method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Account acct = getRequestedAccount(zsc);
    if (!canAccessAccount(zsc, acct)) {
        throw ServiceException.PERM_DENIED("can not access account");
    }
    Element response = zsc.createElement(AccountConstants.SUBSCRIBE_DISTRIBUTION_LIST_RESPONSE);
    Group group = getGroupBasic(request, prov);
    SubscribeDistributionListHandler handler = new SubscribeDistributionListHandler(group, request, response, prov, acct);
    handler.handle();
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 30 with Group

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

the class TestDistListACL method testMilterEdomWithLocalDomain.

/**
     * "edom" GranteeType testing.
     * Addresses for local domains will also match right for "edom" GranteeType
     * (if we decide we don't want this, just testing for a guest account in ZimbraACE won't be sufficient,
     * we will need to make sure that the external domain isn't a local domain.
     */
@Test
public void testMilterEdomWithLocalDomain() throws Exception {
    DistributionList dl = prov.createDistributionList(listAddress, new HashMap<String, Object>());
    String user1email = TestUtil.getAddress(USER_NAME);
    Account user1account = TestUtil.getAccount(USER_NAME);
    prov.grantRight("dl", TargetBy.name, listAddress, GranteeType.GT_EXT_DOMAIN.getCode(), GranteeBy.name, user1account.getDomainName(), null, /* secret */
    RightConsts.RT_sendToDistList, (RightModifier) null);
    ZimbraLog.test.info("DL name %s ID %s", dl.getName(), dl.getId());
    Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
    Assert.assertNotNull("Unable to find Group object for DL by name", group);
    Assert.assertTrue(String.format("%s should be able to send to DL (in domain %s)", user1email, user1account.getDomainName()), accessMgr.canDo(user1email, group, User.R_sendToDistList, false));
    String badName = "unconfigured@" + user1account.getDomainName();
    Assert.assertTrue(String.format("%s should be able to send to DL (in domain %s)", badName, user1account.getDomainName()), accessMgr.canDo(badName, group, User.R_sendToDistList, false));
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) DistributionList(com.zimbra.cs.account.DistributionList) 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