Search in sources :

Example 21 with DynamicGroup

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

the class TestLdapProvAttrCallback method zimbraIsACLGroupAndMemberURLModify.

@Test
public void zimbraIsACLGroupAndMemberURLModify() throws Exception {
    String SOME_URL = "blah";
    String SOME_URL_2 = "blah blah";
    Map<String, Object> attrs = Maps.newHashMap();
    boolean caughtException;
    DynamicGroup group;
    group = createDynamicGroup(genGroupNameLocalPart("3"));
    attrs.clear();
    attrs.put(Provisioning.A_memberURL, SOME_URL);
    caughtException = false;
    try {
        prov.modifyAttrs(group, attrs, true);
    } catch (ServiceException e) {
        if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
            caughtException = true;
        } else {
            throw e;
        }
    }
    assertTrue(caughtException);
    deleteDynamicGroup(group);
    group = createDynamicGroup(genGroupNameLocalPart("4"));
    attrs.clear();
    attrs.put(Provisioning.A_zimbraIsACLGroup, ProvisioningConstants.TRUE);
    attrs.put(Provisioning.A_memberURL, SOME_URL);
    caughtException = false;
    try {
        prov.modifyAttrs(group, attrs);
    } catch (ServiceException e) {
        if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
            caughtException = true;
        } else {
            throw e;
        }
    }
    assertTrue(caughtException);
    deleteDynamicGroup(group);
    attrs.clear();
    attrs.put(Provisioning.A_zimbraIsACLGroup, ProvisioningConstants.FALSE);
    attrs.put(Provisioning.A_memberURL, SOME_URL);
    group = createDynamicGroup(genGroupNameLocalPart("8"), attrs);
    attrs.clear();
    attrs.put(Provisioning.A_memberURL, SOME_URL_2);
    prov.modifyAttrs(group, attrs, true);
    verifyIsNotACLGroup(group, SOME_URL_2);
    deleteDynamicGroup(group);
    attrs.clear();
    attrs.put(Provisioning.A_zimbraIsACLGroup, ProvisioningConstants.FALSE);
    attrs.put(Provisioning.A_memberURL, SOME_URL);
    group = createDynamicGroup(genGroupNameLocalPart("9"), attrs);
    attrs.clear();
    attrs.put(Provisioning.A_zimbraIsACLGroup, ProvisioningConstants.TRUE);
    attrs.put(Provisioning.A_memberURL, SOME_URL);
    caughtException = false;
    try {
        prov.modifyAttrs(group, attrs, true);
    } catch (ServiceException e) {
        if (ServiceException.INVALID_REQUEST.equals(e.getCode())) {
            caughtException = true;
        } else {
            throw e;
        }
    }
    assertTrue(caughtException);
    deleteDynamicGroup(group);
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) ServiceException(com.zimbra.common.service.ServiceException)

Example 22 with DynamicGroup

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

the class TestLdapProvDynamicGroup method zimbraIsACLGroup_and_memeberURL_5.

/*
     * On modify: memeberURL can be modified if zimbraIsACLGroup is FALSE.
     */
@Test
public void zimbraIsACLGroup_and_memeberURL_5() throws Exception {
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_memberURL, "foo");
    attrs.put(Provisioning.A_zimbraIsACLGroup, ProvisioningConstants.FALSE);
    DynamicGroup group = createDynamicGroup(genGroupNameLocalPart(seq), attrs);
    assertEquals(false, group.isIsACLGroup());
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_memberURL, "bar");
    prov.modifyAttrs(group, attrs, true);
    assertEquals("bar", group.getMemberURL());
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 23 with DynamicGroup

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

the class TestLdapProvDynamicGroup method zimbraIsACLGroup_and_memeberURL_1.

/*
     * ================================================
     * Testing zimbraIsACLGroup and memeberURL settings
     * ================================================
     */
/*
     * On create: if memeberURL is specified, zimbraIsACLGroup must also be specified
     * an set to FALSE.
     */
@Test
public void zimbraIsACLGroup_and_memeberURL_1() throws Exception {
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_memberURL, "blah");
    attrs.put(Provisioning.A_zimbraIsACLGroup, ProvisioningConstants.FALSE);
    DynamicGroup group = createDynamicGroup(genGroupNameLocalPart(seq), attrs);
    assertEquals(false, group.isIsACLGroup());
    String errCode = null;
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_memberURL, "blah");
    try {
        createDynamicGroup(genGroupNameLocalPart(seq), attrs);
    } catch (ServiceException e) {
        errCode = e.getCode();
    }
    assertEquals(LdapException.OBJECT_CLASS_VIOLATION, errCode);
    errCode = null;
    attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_memberURL, "blah");
    attrs.put(Provisioning.A_zimbraIsACLGroup, ProvisioningConstants.TRUE);
    try {
        createDynamicGroup(genGroupNameLocalPart(seq), attrs);
    } catch (ServiceException e) {
        assertTrue("Unexpected Exception e thrown", false);
        errCode = e.getCode();
    }
}
Also used : DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 24 with DynamicGroup

use of com.zimbra.cs.account.DynamicGroup 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 = JaxbUtil.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)

Aggregations

DynamicGroup (com.zimbra.cs.account.DynamicGroup)24 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)10 ServiceException (com.zimbra.common.service.ServiceException)9 Account (com.zimbra.cs.account.Account)9 DistributionList (com.zimbra.cs.account.DistributionList)9 Group (com.zimbra.cs.account.Group)7 Test (org.junit.Test)7 Domain (com.zimbra.cs.account.Domain)6 NamedEntry (com.zimbra.cs.account.NamedEntry)6 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)5 HashMap (java.util.HashMap)5 Entry (com.zimbra.cs.account.Entry)4 GuestAccount (com.zimbra.cs.account.GuestAccount)3 SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)3 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)3 Element (com.zimbra.common.soap.Element)2 Provisioning (com.zimbra.cs.account.Provisioning)2 Names (com.zimbra.qa.unittest.prov.Names)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 HashSet (java.util.HashSet)2