Search in sources :

Example 6 with GetAccountMembershipRequest

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;
}
Also used : Account(com.zimbra.cs.account.Account) DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetAccountMembershipRequest(com.zimbra.soap.admin.message.GetAccountMembershipRequest) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy)

Example 7 with GetAccountMembershipRequest

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());
    }
}
Also used : Account(com.zimbra.cs.account.Account) AddDistributionListMemberResponse(com.zimbra.soap.admin.message.AddDistributionListMemberResponse) GetAccountMembershipResponse(com.zimbra.soap.admin.message.GetAccountMembershipResponse) AddAccountAliasRequest(com.zimbra.soap.admin.message.AddAccountAliasRequest) AddDistributionListMemberRequest(com.zimbra.soap.admin.message.AddDistributionListMemberRequest) GetAccountMembershipRequest(com.zimbra.soap.admin.message.GetAccountMembershipRequest) AddAccountAliasResponse(com.zimbra.soap.admin.message.AddAccountAliasResponse) DLInfo(com.zimbra.soap.admin.type.DLInfo) SoapTransport(com.zimbra.common.soap.SoapTransport) Test(org.junit.Test) SoapTest(com.zimbra.qa.unittest.prov.soap.SoapTest)

Aggregations

GetAccountMembershipRequest (com.zimbra.soap.admin.message.GetAccountMembershipRequest)7 GetAccountMembershipResponse (com.zimbra.soap.admin.message.GetAccountMembershipResponse)6 DLInfo (com.zimbra.soap.admin.type.DLInfo)6 ArrayList (java.util.ArrayList)5 SoapTransport (com.zimbra.common.soap.SoapTransport)4 Account (com.zimbra.cs.account.Account)4 DistributionList (com.zimbra.cs.account.DistributionList)4 SoapTest (com.zimbra.qa.unittest.prov.soap.SoapTest)4 AddDistributionListMemberRequest (com.zimbra.soap.admin.message.AddDistributionListMemberRequest)4 AddDistributionListMemberResponse (com.zimbra.soap.admin.message.AddDistributionListMemberResponse)4 Test (org.junit.Test)4 AddAccountAliasRequest (com.zimbra.soap.admin.message.AddAccountAliasRequest)3 AddAccountAliasResponse (com.zimbra.soap.admin.message.AddAccountAliasResponse)3 Group (com.zimbra.cs.account.Group)2 RemoveDistributionListMemberRequest (com.zimbra.soap.admin.message.RemoveDistributionListMemberRequest)2 RemoveDistributionListMemberResponse (com.zimbra.soap.admin.message.RemoveDistributionListMemberResponse)2 AccountBy (com.zimbra.common.account.Key.AccountBy)1 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 DynamicGroup (com.zimbra.cs.account.DynamicGroup)1