use of com.zimbra.soap.account.message.DistributionListActionRequest 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.message.DistributionListActionRequest in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionSetOwners.
@Test
public void distributionListActionSetOwners() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
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
//
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.email, DistributionListGranteeBy.name, owner3.getName()));
DistributionListActionResponse resp = invokeJaxb(transport, req);
//
// verify owners are 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(4, owners.size());
Verify.verifyEquals(Sets.newHashSet(USER_OWNER, owner1.getName(), owner2.getName(), owner3.getName()), ownerNames);
/*
* test invalid grantee type for owner
*/
action = new DistributionListAction(Operation.setOwners);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.email, DistributionListGranteeBy.name, "user@external.com"));
String errCode = null;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
errCode = e.getCode();
}
assertEquals(ServiceException.INVALID_REQUEST, errCode);
// remove all owners
action = new DistributionListAction(Operation.setOwners);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
resp = invokeJaxb(transport, req);
getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
getDLResp = invokeJaxb(transport, getDLReq);
dlInfo = getDLResp.getDl();
owners = dlInfo.getOwners();
assertEquals(0, owners.size());
}
use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionAddRemoveMembers.
@Test
public void distributionListActionAddRemoveMembers() throws Exception {
SoapTransport transport = authUser(USER_OWNER);
// addMembers
DistributionListAction action = new DistributionListAction(Operation.addMembers);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
Account member1 = provUtil.createAccount(genAcctNameLocalPart("member1"), domain);
Account member2 = provUtil.createAccount(genAcctNameLocalPart("member2"), domain);
String MEMBER1 = member1.getName();
String MEMBER2 = member2.getName();
action.addMember(MEMBER1);
action.addMember(MEMBER2);
DistributionListActionResponse resp = invokeJaxb(transport, req);
Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
Set<String> members = group.getAllMembersSet();
Verify.verifyEquals(Sets.newHashSet(MEMBER1, MEMBER2), members);
// removeMembers
action = new DistributionListAction(Operation.removeMembers);
req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
action.addMember(MEMBER1);
action.addMember(MEMBER2);
resp = invokeJaxb(transport, req);
group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
members = group.getAllMembersSet();
assertEquals(0, members.size());
}
use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionRename.
@Test
public void distributionListActionRename() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
// create an owner account
Account ownerAcct = provUtil.createAccount(genAcctNameLocalPart("owner"), domain);
Group group = createGroupAndAddOwner(GROUP_NAME, ownerAcct.getName());
DistributionListAction action = new DistributionListAction(Operation.rename);
String GROUP_NEW_NAME = getAddress(genGroupNameLocalPart("new-name"));
action.setNewName(GROUP_NEW_NAME);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
DistributionListActionResponse resp;
SoapTransport transport = authUser(ownerAcct.getName());
String errorCode = null;
try {
// only people with create right and owner right can rename
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
errorCode = e.getCode();
}
assertEquals(ServiceException.PERM_DENIED, errorCode);
// auth as creator and try again, should still fail
transport = authUser(USER_CREATOR);
errorCode = null;
try {
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
errorCode = e.getCode();
}
assertEquals(ServiceException.PERM_DENIED, errorCode);
// make the creator an owner
transport = authUser(ownerAcct.getName());
addOwner(transport, GROUP_NAME, USER_CREATOR);
// now try reanme as the creator (also an owner now), should succeed
transport = authUser(USER_CREATOR);
resp = invokeJaxb(transport, req);
group = prov.getGroup(Key.DistributionListBy.name, GROUP_NEW_NAME);
assertEquals(GROUP_NEW_NAME, group.getName());
// rename into a different domain
Domain otherDomain = provUtil.createDomain(genDomainName(domain.getName()));
String GROUP_NEW_NAME_IN_ANOTHER_DOMAIN = TestUtil.getAddress(genGroupNameLocalPart(), otherDomain.getName());
action = new DistributionListAction(Operation.rename);
action.setNewName(GROUP_NEW_NAME_IN_ANOTHER_DOMAIN);
req = new DistributionListActionRequest(DistributionListSelector.fromName(group.getName()), action);
transport = authUser(USER_CREATOR);
errorCode = null;
try {
// need create right on the other domain
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
errorCode = e.getCode();
}
assertEquals(ServiceException.PERM_DENIED, errorCode);
transport = authUser(ownerAcct.getName());
errorCode = null;
try {
// need create right on the other domain
resp = invokeJaxb(transport, req);
} catch (ServiceException e) {
errorCode = e.getCode();
}
assertEquals(ServiceException.PERM_DENIED, errorCode);
// grant create right on the other domain
prov.grantRight(TargetType.domain.getCode(), TargetBy.name, otherDomain.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, USER_CREATOR, null, User.R_createDistList.getName(), null);
// do the rename again, should work now
transport = authUser(USER_CREATOR);
resp = invokeJaxb(transport, req);
group = prov.getGroup(Key.DistributionListBy.name, GROUP_NEW_NAME_IN_ANOTHER_DOMAIN);
assertEquals(GROUP_NEW_NAME_IN_ANOTHER_DOMAIN, group.getName());
provUtil.deleteAccount(ownerAcct);
provUtil.deleteGroup(group);
provUtil.deleteDomain(otherDomain);
}
use of com.zimbra.soap.account.message.DistributionListActionRequest in project zm-mailbox by Zimbra.
the class TestDelegatedDL method addOwner.
private static void addOwner(SoapTransport transport, String groupName, String ownerName) throws Exception {
DistributionListAction action = new DistributionListAction(Operation.addOwners);
DistributionListActionRequest actionReq = new DistributionListActionRequest(DistributionListSelector.fromName(groupName), action);
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, ownerName));
DistributionListActionResponse actionResp = invokeJaxb(transport, actionReq);
}
Aggregations