use of com.zimbra.soap.account.type.DistributionListRightSpec in project zm-mailbox by Zimbra.
the class TestDelegatedDL method getDistributionListRights.
/*
* verify rights are returned
*/
@Test
public void getDistributionListRights() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
Group group = createGroupAndAddOwner(GROUP_NAME);
String right1 = Right.RT_sendToDistList;
String right2 = Right.RT_viewDistList;
Account grantee1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
Account grantee2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
SoapTransport transport = authUser(USER_OWNER);
//
// grantRights
//
DistributionListAction action = new DistributionListAction(Operation.grantRights);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
DistributionListRightSpec dlRight1 = new DistributionListRightSpec(right1);
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee1.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee2.getName()));
DistributionListRightSpec dlRight2 = new DistributionListRightSpec(right2);
dlRight2.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.all, null, null));
action.addRight(dlRight1);
action.addRight(dlRight2);
DistributionListActionResponse resp = invokeJaxb(transport, req);
/*
* verify rights are returned
*/
GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.FALSE, right1 + "," + right2);
GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
DistributionListInfo dlInfo = getDLResp.getDl();
List<? extends DistributionListRightInfo> rights = dlInfo.getRights();
Set<String> right1GranteeNames = Sets.newHashSet();
Set<String> right2GranteeNames = Sets.newHashSet();
for (DistributionListRightInfo rightInfo : rights) {
String right = rightInfo.getRight();
List<DistributionListGranteeInfo> grantees = rightInfo.getGrantees();
if (right1.equals(right)) {
for (DistributionListGranteeInfo grantee : grantees) {
right1GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
}
} else if (right2.equals(right)) {
for (DistributionListGranteeInfo grantee : grantees) {
right2GranteeNames.add(Verify.makeResultStr(grantee.getType().name(), grantee.getName()));
}
}
}
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee1.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee2.getName())), right1GranteeNames);
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_AUTHUSER.getCode(), "null")), right2GranteeNames);
}
use of com.zimbra.soap.account.type.DistributionListRightSpec in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionManipulateOwnerRight.
/*
* verify owner right can never be altered directly, all modification on
* owners must go through addOwners/remvoeOwners/setOwners operations
*/
@Test
public void distributionListActionManipulateOwnerRight() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
Group group = createGroupAndAddOwner(GROUP_NAME);
String right = Group.GroupOwner.GROUP_OWNER_RIGHT.getName();
Account grantee = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
SoapTransport transport = authUser(USER_OWNER);
//
// grantRights
//
DistributionListAction action = new DistributionListAction(Operation.grantRights);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
DistributionListRightSpec dlRight = new DistributionListRightSpec(right);
dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
action.addRight(dlRight);
DistributionListActionResponse resp;
boolean caughtException = false;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
//
// revokeRights
//
action = new DistributionListAction(Operation.revokeRights);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
dlRight = new DistributionListRightSpec(right);
dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
action.addRight(dlRight);
caughtException = false;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
//
// setRights
//
action = new DistributionListAction(Operation.setRights);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
dlRight = new DistributionListRightSpec(right);
dlRight.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee.getName()));
action.addRight(dlRight);
caughtException = false;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
}
use of com.zimbra.soap.account.type.DistributionListRightSpec in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionGrantRevokeSetRights.
@Test
public void distributionListActionGrantRevokeSetRights() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
Group group = createGroupAndAddOwner(GROUP_NAME);
String right1 = Right.RT_sendToDistList;
String right2 = Right.RT_viewDistList;
Account grantee1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
Account grantee2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
Group groupGrantee1 = provUtil.createGroup(genGroupNameLocalPart("3"), domain, DYNAMIC);
// test grantees specified as "email" grantee type
Account grantee3 = provUtil.createAccount(genAcctNameLocalPart("4"), domain);
Account grantee4 = provUtil.createAccount(genAcctNameLocalPart("5"), domain);
Group groupGrantee2 = provUtil.createGroup(genGroupNameLocalPart("6"), domain, DYNAMIC);
String GUEST = "user@external.com";
SoapTransport transport = authUser(USER_OWNER);
//
// grantRights
//
DistributionListAction action = new DistributionListAction(Operation.grantRights);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
DistributionListRightSpec dlRight1 = new DistributionListRightSpec(right1);
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee1.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee2.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.grp, DistributionListGranteeBy.name, groupGrantee1.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.all, null, null));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.pub, null, null));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, grantee3.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, grantee4.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, groupGrantee2.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, GUEST));
DistributionListRightSpec dlRight2 = new DistributionListRightSpec(right2);
dlRight2.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee1.getName()));
dlRight2.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, grantee2.getName()));
action.addRight(dlRight1);
action.addRight(dlRight2);
DistributionListActionResponse resp = invokeJaxb(transport, req);
//
// verify rights are granted
//
RightCommand.Grants grants = prov.getGrants(TargetType.dl.name(), TargetBy.id, group.getId(), null, null, null, true);
Set<String> right1GranteeNames = Sets.newHashSet();
Set<String> right2GranteeNames = Sets.newHashSet();
for (RightCommand.ACE ace : grants.getACEs()) {
String right = ace.right();
if (right1.equals(right)) {
right1GranteeNames.add(Verify.makeResultStr(ace.granteeType(), ace.granteeName()));
} else if (right2.equals(right)) {
right2GranteeNames.add(Verify.makeResultStr(ace.granteeType(), ace.granteeName()));
}
}
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee1.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee2.getName()), Verify.makeResultStr(GranteeType.GT_GROUP.getCode(), groupGrantee1.getName()), Verify.makeResultStr(GranteeType.GT_AUTHUSER.getCode(), ""), Verify.makeResultStr(GranteeType.GT_PUBLIC.getCode(), ""), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee3.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee4.getName()), Verify.makeResultStr(GranteeType.GT_GROUP.getCode(), groupGrantee2.getName()), Verify.makeResultStr(GranteeType.GT_GUEST.getCode(), GUEST)), right1GranteeNames);
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee1.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee2.getName())), right2GranteeNames);
//
// setRights
//
action = new DistributionListAction(Operation.setRights);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
dlRight1 = new DistributionListRightSpec(right1);
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.all, null, null));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, grantee3.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, grantee4.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, groupGrantee2.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, GUEST));
dlRight2 = new DistributionListRightSpec(right2);
// don't add any grantee, this should revoke all grants for right2
action.addRight(dlRight1);
action.addRight(dlRight2);
resp = invokeJaxb(transport, req);
//
// verify rights are set
//
grants = prov.getGrants(TargetType.dl.name(), TargetBy.id, group.getId(), null, null, null, true);
right1GranteeNames = Sets.newHashSet();
right2GranteeNames = Sets.newHashSet();
for (RightCommand.ACE ace : grants.getACEs()) {
String right = ace.right();
if (right1.equals(right)) {
right1GranteeNames.add(Verify.makeResultStr(ace.granteeType(), ace.granteeName()));
} else if (right2.equals(right)) {
right2GranteeNames.add(Verify.makeResultStr(ace.granteeType(), ace.granteeName()));
}
}
Verify.verifyEquals(Sets.newHashSet(Verify.makeResultStr(GranteeType.GT_AUTHUSER.getCode(), ""), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee3.getName()), Verify.makeResultStr(GranteeType.GT_USER.getCode(), grantee4.getName()), Verify.makeResultStr(GranteeType.GT_GROUP.getCode(), groupGrantee2.getName()), Verify.makeResultStr(GranteeType.GT_GUEST.getCode(), GUEST)), right1GranteeNames);
assertEquals(0, right2GranteeNames.size());
//
// revokeRights
//
action = new DistributionListAction(Operation.revokeRights);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
dlRight1 = new DistributionListRightSpec(right1);
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.all, null, null));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, grantee3.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, grantee4.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, groupGrantee2.getName()));
dlRight1.addGrantee(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, GUEST));
action.addRight(dlRight1);
resp = invokeJaxb(transport, req);
//
// verify all rights are revoked
//
grants = prov.getGrants(TargetType.dl.name(), TargetBy.id, group.getId(), null, null, null, true);
right1GranteeNames = Sets.newHashSet();
right2GranteeNames = Sets.newHashSet();
for (RightCommand.ACE ace : grants.getACEs()) {
String right = ace.right();
if (right1.equals(right)) {
right1GranteeNames.add(ace.granteeName());
} else if (right2.equals(right)) {
right2GranteeNames.add(ace.granteeName());
}
}
assertEquals(0, right1GranteeNames.size());
assertEquals(0, right2GranteeNames.size());
}
Aggregations