Search in sources :

Example 86 with Group

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

the class SendShareNotification method getGrantee.

/**
     * returns the grantee entry and displayName if there is one
     *
     * @param zsc
     * @param granteeType
     * @param granteeId
     * @param granteeName
     * @return
     * @throws ServiceException
     */
private Pair<NamedEntry, String> getGrantee(ZimbraSoapContext zsc, byte granteeType, String granteeId, String granteeName) throws ServiceException {
    NamedEntry entryById = null;
    NamedEntry entryByName = null;
    if (granteeId != null) {
        entryById = FolderAction.lookupGranteeByZimbraId(granteeId, granteeType);
        if (entryById == null)
            throw MailServiceException.NO_SUCH_GRANTEE(granteeId, null);
    }
    if (granteeName != null) {
        try {
            entryByName = FolderAction.lookupGranteeByName(granteeName, granteeType, zsc);
        } catch (ServiceException se) {
            throw MailServiceException.NO_SUCH_GRANTEE(granteeName, null);
        }
    }
    if (entryById == null && entryByName == null) {
        throw MailServiceException.NO_SUCH_GRANTEE("", null);
    }
    if (entryById != null && entryByName != null && !entryById.getId().equals(entryByName.getId())) {
        throw ServiceException.INVALID_REQUEST("grantee name does not match grantee id", null);
    }
    NamedEntry grantee = (entryById != null) ? entryById : entryByName;
    String displayName;
    if (grantee instanceof Account) {
        displayName = ((Account) grantee).getDisplayName();
    } else if (grantee instanceof Group) {
        displayName = ((Group) grantee).getDisplayName();
    } else {
        throw ServiceException.INVALID_REQUEST("unsupported grantee type for sending share notification email", null);
    }
    return new Pair<NamedEntry, String>(grantee, displayName);
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Pair(com.zimbra.common.util.Pair)

Example 87 with Group

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

the class TestGroups method createDynamicGroup.

public static Group createDynamicGroup(String name) throws Exception {
    Provisioning prov = Provisioning.getInstance();
    Group group = prov.getGroup(Key.DistributionListBy.name, name, true);
    if (group != null) {
        ZimbraLog.test.warn("createDynamicGroup(%s) - already existed!!!", name);
        return group;
    }
    Map<String, Object> attrs = Maps.newHashMap();
    group = prov.createGroup(name, attrs, true);
    if (group == null) {
        ZimbraLog.test.warn("createDynamicGroup returning null for '%s'", name);
    }
    return group;
}
Also used : Group(com.zimbra.cs.account.Group) ZAttrProvisioning(com.zimbra.common.account.ZAttrProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) LdapProvisioning(com.zimbra.cs.account.ldap.LdapProvisioning)

Example 88 with Group

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

the class TestLdapHelper method hasSubordinates.

@Test
public void hasSubordinates() throws Exception {
    Domain domain = provUtil.createDomain(genDomainName(baseDomainName()));
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, true);
    String domainDn = ((LdapDomain) domain).getDN();
    String acctBaseDn = prov.getDIT().domainDNToAccountBaseDN(domainDn);
    String dynGroupsBaseDn = prov.getDIT().domainDNToDynamicGroupsBaseDN(domainDn);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UNITTEST);
        // verify dn has Subordinates
        assertTrue(hasSubordinates(zlc, acctBaseDn));
        assertTrue(hasSubordinates(zlc, dynGroupsBaseDn));
        provUtil.deleteAccount(acct);
        provUtil.deleteGroup(group);
        // verify dn don't have Subordinates
        assertFalse(hasSubordinates(zlc, acctBaseDn));
        assertFalse(hasSubordinates(zlc, dynGroupsBaseDn));
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain)

Example 89 with Group

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

the class TestLdapProvCountObjects method countDL.

@Test
public void countDL() throws Exception {
    Group staticGroup = provUtil.createGroup(genGroupNameLocalPart("static"), domain, false);
    Group dynamicGroup = provUtil.createGroup(genGroupNameLocalPart("dynamic"), domain, true);
    Domain subDomain = provUtil.createDomain(genDomainName(domain.getName()));
    Group staticGroup1Sub = provUtil.createGroup(genGroupNameLocalPart("static-1"), subDomain, false);
    Group dynamicGroup1Sub = provUtil.createGroup(genGroupNameLocalPart("dynamic-1"), subDomain, true);
    Group staticGroup2Sub = provUtil.createGroup(genGroupNameLocalPart("static-2"), subDomain, false);
    Group dynamicGroup2Sub = provUtil.createGroup(genGroupNameLocalPart("dynamic-2"), subDomain, true);
    long num;
    num = prov.countObjects(CountObjectsType.dl, domain, null);
    // groups in sub domains should not be counted
    assertEquals(2, num);
    provUtil.deleteGroup(staticGroup);
    provUtil.deleteGroup(dynamicGroup);
    provUtil.deleteGroup(staticGroup1Sub);
    provUtil.deleteGroup(dynamicGroup1Sub);
    provUtil.deleteGroup(staticGroup2Sub);
    provUtil.deleteGroup(dynamicGroup2Sub);
    provUtil.deleteDomain(subDomain);
}
Also used : Group(com.zimbra.cs.account.Group) Domain(com.zimbra.cs.account.Domain) Test(org.junit.Test)

Example 90 with Group

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

the class TestSearchGalGroups method searchGroup.

@Test
public void searchGroup() throws Exception {
    SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.DN_SUBTREE_MATCH_FILTER);
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraDistributionListSubscriptionPolicy, ZAttrProvisioning.DistributionListSubscriptionPolicy.ACCEPT.name());
    Group group = provUtil.createGroup(genGroupNameLocalPart(), domain, attrs, false);
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
    // make acct owner of the the group
    String right = Group.GroupOwner.GROUP_OWNER_RIGHT.getName();
    prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, right, null);
    // make acct member of the group
    prov.addGroupMembers(group, new String[] { acct.getName() });
    // test with GSA on
    GalTestUtil.enableGalSyncAccount(prov, domain.getName());
    testSearchGroup(acct, group, Boolean.TRUE, MemberOfSelector.all, true, true);
    testSearchGroup(acct, group, Boolean.TRUE, null, true, true);
    testSearchGroup(acct, group, null, MemberOfSelector.all, true, true);
    testSearchGroup(acct, group, null, null, true, true);
    // test with GSA off
    GalTestUtil.disableGalSyncAccount(prov, domain.getName());
    testSearchGroup(acct, group, Boolean.TRUE, MemberOfSelector.all, true, true);
    testSearchGroup(acct, group, Boolean.TRUE, null, true, true);
    testSearchGroup(acct, group, null, MemberOfSelector.all, true, true);
    testSearchGroup(acct, group, null, null, true, true);
    provUtil.deleteGroup(group);
    provUtil.deleteAccount(acct);
}
Also used : Group(com.zimbra.cs.account.Group) Account(com.zimbra.cs.account.Account) Test(org.junit.Test)

Aggregations

Group (com.zimbra.cs.account.Group)110 Account (com.zimbra.cs.account.Account)53 Test (org.junit.Test)42 DynamicGroup (com.zimbra.cs.account.DynamicGroup)27 ServiceException (com.zimbra.common.service.ServiceException)23 SoapTransport (com.zimbra.common.soap.SoapTransport)23 Provisioning (com.zimbra.cs.account.Provisioning)23 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)21 Domain (com.zimbra.cs.account.Domain)17 GuestAccount (com.zimbra.cs.account.GuestAccount)17 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 Element (com.zimbra.common.soap.Element)16 AccountServiceException (com.zimbra.cs.account.AccountServiceException)15 NamedEntry (com.zimbra.cs.account.NamedEntry)14 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)12 DistributionListActionRequest (com.zimbra.soap.account.message.DistributionListActionRequest)12 DistributionListAction (com.zimbra.soap.account.type.DistributionListAction)12 DistributionListActionResponse (com.zimbra.soap.account.message.DistributionListActionResponse)11 DistributionList (com.zimbra.cs.account.DistributionList)9 Entry (com.zimbra.cs.account.Entry)9