Search in sources :

Example 21 with Group

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

the class TestDistListACL method testMilterExternalDomainSendToDL.

/**
     * "edom" GranteeType testing.  Check that a sender whose address has a domain which matches the
     * external domain will be able to send to the DL
     */
@Test
public void testMilterExternalDomainSendToDL() throws Exception {
    DistributionList dl = prov.createDistributionList(listAddress, new HashMap<String, Object>());
    String user1email = TestUtil.getAddress(USER_NAME);
    prov.grantRight("dl", TargetBy.name, listAddress, GranteeType.GT_EXT_DOMAIN.getCode(), GranteeBy.name, "example.test", 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("pete@example.test should be able to send to DL (in domain example.test)", accessMgr.canDo("pete@example.test", group, User.R_sendToDistList, false));
    Assert.assertFalse(String.format("%s should NOT be able to send to DL (in domain example.test)", user1email), accessMgr.canDo(user1email, group, User.R_sendToDistList, false));
}
Also used : Group(com.zimbra.cs.account.Group) DistributionList(com.zimbra.cs.account.DistributionList) Test(org.junit.Test)

Example 22 with Group

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

the class TestDistListACL method doCheckSentToDistListUserRight.

private void doCheckSentToDistListUserRight(DistributionList targetDl, String email, String user, boolean expected) throws ServiceException {
    ZimbraLog.test.info("DL name %s ID %s", targetDl.getName(), targetDl.getId());
    Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
    Assert.assertNotNull("Unable to find Group object for DL by name", group);
    AccessManager.ViaGrant via = new AccessManager.ViaGrant();
    //  More permissive that GT_USER - want to test called functions
    NamedEntry ne = GranteeType.lookupGrantee(prov, GranteeType.GT_EMAIL, GranteeBy.name, email);
    MailTarget grantee = null;
    if (ne instanceof MailTarget) {
        grantee = (MailTarget) ne;
    }
    boolean result = RightCommand.checkRight(prov, "dl", /* targetType */
    TargetBy.name, listAddress, grantee, RightConsts.RT_sendToDistList, null, /* attrs */
    via);
    if (expected) {
        Assert.assertTrue(String.format("%s should be able to send to DL (as user %s)", email, user), accessMgr.canDo(email, group, User.R_sendToDistList, false));
        Assert.assertTrue(String.format("%s should have right to send to DL (as user %s)", email, user), result);
        ZimbraLog.test.info("Test for %s against dom %s Via=%s", email, user, via);
    } else {
        Assert.assertFalse(String.format("%s should NOT be able to send to DL (because not user %s)", email, user), accessMgr.canDo(email, group, User.R_sendToDistList, false));
        Assert.assertFalse(String.format("%s should NOT have right to send to DL (because not user %s)", email, user), result);
    }
}
Also used : AccessManager(com.zimbra.cs.account.AccessManager) Group(com.zimbra.cs.account.Group) NamedEntry(com.zimbra.cs.account.NamedEntry) MailTarget(com.zimbra.cs.account.MailTarget)

Example 23 with Group

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

the class TestGetInfo method discoverRights.

@Test
public void discoverRights() throws Exception {
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, false);
    prov.grantRight(TargetType.domain.getCode(), TargetBy.name, domain.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, User.R_createDistList.getName(), null);
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, User.R_sendToDistList.getName(), null);
    SoapTransport transport = authUser(acct.getName());
    GetInfoRequest req = new GetInfoRequest();
    req.addRight(User.R_createDistList.getName());
    req.addRight(User.R_sendToDistList.getName());
    GetInfoResponse resp = invokeJaxb(transport, req);
    List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
    Set<String> result = Sets.newHashSet();
    for (DiscoverRightsInfo rightInfo : rightsInfo) {
        String right = rightInfo.getRight();
        List<DiscoverRightsTarget> targets = rightInfo.getTargets();
        for (DiscoverRightsTarget target : targets) {
            String id = target.getId();
            String name = target.getName();
            String type = target.getType().toString();
            result.add(Verify.makeResultStr(right, id, name, type));
        }
    }
    Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(User.R_createDistList.getName(), domain.getId(), domain.getName(), TargetType.domain.getCode()), Verify.makeResultStr(User.R_sendToDistList.getName(), group.getId(), group.getName(), TargetType.dl.getCode())), result);
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) GetInfoResponse(com.zimbra.soap.account.message.GetInfoResponse) DiscoverRightsInfo(com.zimbra.soap.account.type.DiscoverRightsInfo) DiscoverRightsTarget(com.zimbra.soap.account.type.DiscoverRightsTarget) GetInfoRequest(com.zimbra.soap.account.message.GetInfoRequest) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test)

Example 24 with Group

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

the class TestDelegatedDL method ownerIsGroup.

/*
     * owner of a group is a group
     */
@Test
public void ownerIsGroup() throws Exception {
    Group ownedGroup = provUtil.createGroup(genGroupNameLocalPart("owned"), domain, DYNAMIC);
    Group owningGroup = provUtil.createGroup(genGroupNameLocalPart("owning"), domain, DYNAMIC);
    /*
         * add members to owning group
         */
    Account acctInOwningGroup = provUtil.createAccount("acctInOwningGroup", domain);
    prov.addGroupMembers(owningGroup, new String[] { acctInOwningGroup.getName() });
    /*
         * grant ownDistList right to owningGroup on ownedGroup
         */
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, ownedGroup.getName(), GranteeType.GT_GROUP.getCode(), GranteeBy.name, owningGroup.getName(), null, Group.GroupOwner.GROUP_OWNER_RIGHT.getName(), null);
    /*
         * auth as acctInOwningGroup
         */
    SoapTransport transport = authUser(acctInOwningGroup.getName());
    /*
         * try to add member in ownedGroup
         */
    // addMembers
    DistributionListAction action = new DistributionListAction(Operation.addMembers);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(ownedGroup.getName()), action);
    String MEMBER1 = "member1@test.com";
    String MEMBER2 = "member2@test.com";
    action.addMember(MEMBER1);
    action.addMember(MEMBER2);
    DistributionListActionResponse resp = invokeJaxb(transport, req);
    Group group = prov.getGroup(Key.DistributionListBy.name, ownedGroup.getName());
    Set<String> members = group.getAllMembersSet();
    assertEquals(2, members.size());
    assertTrue(members.contains(MEMBER1));
    assertTrue(members.contains(MEMBER2));
    provUtil.deleteAccount(acctInOwningGroup);
    provUtil.deleteGroup(owningGroup);
    provUtil.deleteGroup(ownedGroup);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) Test(org.junit.Test)

Example 25 with Group

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

the class TestDelegatedDL method distributionListActionSetBadOwners.

@Test
@Bug(bug = 72791)
public void distributionListActionSetBadOwners() throws Exception {
    String GROUP_NAME = getAddress(genGroupNameLocalPart());
    Group group = createGroupAndAddOwner(GROUP_NAME);
    Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
    Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
    Account owner3 = provUtil.createAccount(genAcctNameLocalPart("3"), domain);
    SoapTransport transport = authUser(USER_OWNER);
    //
    // setOwners: some good owners an a bogus owner (not a user)
    //
    DistributionListAction action = new DistributionListAction(Operation.setOwners);
    DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, USER_OWNER));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner3.getName()));
    action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, "bogus@bogus.com"));
    String errorCode = null;
    try {
        DistributionListActionResponse resp = invokeJaxb(transport, req);
    } catch (ServiceException e) {
        errorCode = e.getCode();
    }
    assertEquals(AccountServiceException.NO_SUCH_ACCOUNT, errorCode);
    //
    // verify owners are NOT replaced
    //
    GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
    GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
    DistributionListInfo dlInfo = getDLResp.getDl();
    List<? extends DistributionListGranteeInfoInterface> owners = dlInfo.getOwners();
    Set<String> ownerNames = Sets.newHashSet();
    for (DistributionListGranteeInfoInterface owner : owners) {
        if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
            ownerNames.add(owner.getName());
        }
    }
    assertEquals(1, owners.size());
    Verify.verifyEquals(Sets.newHashSet(USER_OWNER), ownerNames);
}
Also used : GetDistributionListResponse(com.zimbra.soap.account.message.GetDistributionListResponse) Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) DistributionListGranteeInfoInterface(com.zimbra.soap.base.DistributionListGranteeInfoInterface) DistributionListInfo(com.zimbra.soap.account.type.DistributionListInfo) DistributionListActionResponse(com.zimbra.soap.account.message.DistributionListActionResponse) GetDistributionListRequest(com.zimbra.soap.account.message.GetDistributionListRequest) DistributionListActionRequest(com.zimbra.soap.account.message.DistributionListActionRequest) DistributionListGranteeSelector(com.zimbra.soap.account.type.DistributionListGranteeSelector) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) DistributionListAction(com.zimbra.soap.account.type.DistributionListAction) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) Bug(com.zimbra.qa.QA.Bug)

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