use of com.zimbra.soap.admin.message.GetAccountMembershipRequest in project zm-mailbox by Zimbra.
the class GetAccountMembership method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetAccountMembershipRequest req = zsc.elementToJaxb(request);
AccountBy acctBy = req.getAccount().getBy().toKeyAccountBy();
String accountSelectorKey = req.getAccount().getKey();
Account account = prov.get(acctBy, accountSelectorKey, zsc.getAuthToken());
defendAgainstAccountHarvesting(account, acctBy, accountSelectorKey, zsc, Admin.R_getAccountMembership);
HashMap<String, String> via = new HashMap<String, String>();
List<Group> groups = prov.getGroups(account, false, via);
Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_MEMBERSHIP_RESPONSE);
for (Group group : groups) {
Element eDL = response.addNonUniqueElement(AdminConstants.E_DL);
eDL.addAttribute(AdminConstants.A_NAME, group.getName());
eDL.addAttribute(AdminConstants.A_ID, group.getId());
eDL.addAttribute(AdminConstants.A_DYNAMIC, group.isDynamic());
String viaDl = via.get(group.getName());
if (viaDl != null) {
eDL.addAttribute(AdminConstants.A_VIA, viaDl);
}
try {
if (group.isDynamic()) {
checkDynamicGroupRight(zsc, (DynamicGroup) group, needGetAttrsRight());
} else {
checkDistributionListRight(zsc, (DistributionList) group, needGetAttrsRight());
}
String isAdminGroup = group.getAttr(Provisioning.A_zimbraIsAdminGroup);
if (isAdminGroup != null) {
eDL.addNonUniqueElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, Provisioning.A_zimbraIsAdminGroup).setText(isAdminGroup);
}
} catch (ServiceException e) {
if (ServiceException.PERM_DENIED.equals(e.getCode())) {
ZimbraLog.acl.warn("no permission to view %s of dl %s", Provisioning.A_zimbraIsAdminGroup, group.getName());
}
}
}
return response;
}
use of com.zimbra.soap.admin.message.GetAccountMembershipRequest in project zm-mailbox by Zimbra.
the class TestDLMembership method testAddMemberByAlias.
@Test
public void testAddMemberByAlias() {
SoapTransport transport;
try {
transport = TestUtil.getAdminSoapTransport();
// add an alias to the account
AddAccountAliasResponse addAliasResp = SoapTest.invokeJaxb(transport, new AddAccountAliasRequest(testUser.getId(), TestUtil.getAddress(TEST_ALIAS)));
assertNotNull("AddAccountAliasResponse cannot be null", addAliasResp);
Account acct = Provisioning.getInstance().getAccount(testUser.getId());
assertNotNull(acct);
assertNotNull("account's aliases are null", acct.getAliases());
assertEquals("account has no aliases", acct.getAliases().length, 1);
// add a member by alias
AddDistributionListMemberResponse addDLMemberResp = SoapTest.invokeJaxb(transport, new AddDistributionListMemberRequest(testDL.getId(), Collections.singleton(TestUtil.getAddress(TEST_ALIAS))));
assertNotNull("AddDistributionListMemberResponse cannot be null", addDLMemberResp);
// verify that account is a member of the DL
GetAccountMembershipResponse resp = SoapTest.invokeJaxb(transport, new GetAccountMembershipRequest(AccountSelector.fromName(TEST_USER)));
assertNotNull("GetAccountMembershipRequest cannot be null", resp);
List<DLInfo> dlInfoList = resp.getDlList();
assertTrue("Account is not a member of any DLs", dlInfoList.size() > 0);
assertEquals("Account should be a member of the test DL only", dlInfoList.get(0).getName(), testDL.getName());
} catch (Exception e) {
fail(e.getLocalizedMessage());
}
}
Aggregations