Search in sources :

Example 11 with SearchDirectoryOptions

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

the class TestLdapProvSearchDirectory method dnSubtreeMatchFilter.

@Test
public void dnSubtreeMatchFilter() throws Exception {
    String SUB_DOMAIN_BASE = genDomainSegmentName() + "." + baseDomainName();
    String SUB_DOMAIN_NAME = "sub." + SUB_DOMAIN_BASE;
    Domain subDomain = provUtil.createDomain(SUB_DOMAIN_NAME);
    String SUB_SUB_DOMAIN_NAME = "sub." + SUB_DOMAIN_NAME;
    Domain subSubDomain = provUtil.createDomain(SUB_SUB_DOMAIN_NAME);
    // create objects in subDomain
    Account acct = provUtil.createAccount(genAcctNameLocalPart("acct"), subDomain);
    DistributionList dl = provUtil.createDistributionList(genGroupNameLocalPart("dl"), subDomain);
    DynamicGroup dg = provUtil.createDynamicGroup(genGroupNameLocalPart("dg"), subDomain);
    // create objects in subSubDomain
    Account acctSub = provUtil.createAccount(genAcctNameLocalPart("acct"), subSubDomain);
    DistributionList dlSub = provUtil.createDistributionList(genGroupNameLocalPart("dl"), subSubDomain);
    DynamicGroup dgSub = provUtil.createDynamicGroup(genGroupNameLocalPart("dg"), subSubDomain);
    SearchDirectoryOptions options;
    List<NamedEntry> entries;
    try {
        SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.DN_SUBTREE_MATCH_FILTER);
        // do not specify a domain, so DnSubtreeMatchFilter won't be appened again in Ldapprovisioning
        options = new SearchDirectoryOptions();
        options.setTypes(ObjectType.accounts, ObjectType.distributionlists, ObjectType.dynamicgroups);
        options.setSortOpt(SortOpt.SORT_ASCENDING);
        options.setFilterString(FilterId.UNITTEST, ((LdapDomain) subDomain).getDnSubtreeMatchFilter().toFilterString());
        entries = prov.searchDirectory(options);
        Verify.verifyEquals(Lists.newArrayList(acct, dg, dl), entries, true);
    } catch (ProvTest.SkippedForInMemLdapServerException e) {
    }
    // specify a domain, search for accounts, distribution lists, and dynamic groups
    options = new SearchDirectoryOptions(subDomain);
    options.setTypes(ObjectType.accounts, ObjectType.distributionlists, ObjectType.dynamicgroups);
    options.setSortOpt(SortOpt.SORT_ASCENDING);
    options.setFilterString(FilterId.UNITTEST, null);
    entries = prov.searchDirectory(options);
    Verify.verifyEquals(Lists.newArrayList(acct, dg, dl), entries, true);
    // specify a domain, search for accounts, distribution lists
    options = new SearchDirectoryOptions(subDomain);
    options.setTypes(ObjectType.accounts, ObjectType.distributionlists);
    options.setSortOpt(SortOpt.SORT_ASCENDING);
    options.setFilterString(FilterId.UNITTEST, null);
    entries = prov.searchDirectory(options);
    Verify.verifyEquals(Lists.newArrayList(acct, dl), entries, true);
    // specify a domain, search for dynamic groups
    options = new SearchDirectoryOptions(subDomain);
    options.setTypes(ObjectType.dynamicgroups);
    options.setSortOpt(SortOpt.SORT_ASCENDING);
    options.setFilterString(FilterId.UNITTEST, null);
    entries = prov.searchDirectory(options);
    Verify.verifyEquals(Lists.newArrayList(dg), entries, true);
    // specify a domain, search for accounts and dynamic groups
    options = new SearchDirectoryOptions(subDomain);
    options.setTypes(ObjectType.accounts, ObjectType.dynamicgroups);
    options.setSortOpt(SortOpt.SORT_ASCENDING);
    options.setFilterString(FilterId.UNITTEST, null);
    entries = prov.searchDirectory(options);
    Verify.verifyEquals(Lists.newArrayList(acct, dg), entries, true);
    // cleanup
    deleteAccount(acct);
    deleteGroup(dl);
    deleteGroup(dg);
    deleteAccount(acctSub);
    deleteGroup(dlSub);
    deleteGroup(dgSub);
    deleteDomain(subSubDomain);
    deleteDomain(subDomain);
}
Also used : Account(com.zimbra.cs.account.Account) DynamicGroup(com.zimbra.cs.account.DynamicGroup) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) Domain(com.zimbra.cs.account.Domain) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) DistributionList(com.zimbra.cs.account.DistributionList) ProvTest(com.zimbra.qa.unittest.prov.ProvTest) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 12 with SearchDirectoryOptions

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

the class TestLdapProvRenameDomain method verifyDomainAliases.

/*
     * verify all aliases in the domain 
     */
private void verifyDomainAliases(int domainIdx, Domain domain) throws Exception {
    // get all the aliases reside in the domain
    SearchDirectoryOptions options = new SearchDirectoryOptions();
    options.setTypes(SearchDirectoryOptions.ObjectType.aliases);
    options.setDomain(domain);
    options.setFilterString(FilterId.UNITTEST, null);
    List<NamedEntry> list = prov.searchDirectory(options);
    // come up with all expected aliases
    Set<String> expectedAliases = new HashSet<String>();
    for (int d = 0; d < NUM_DOMAINS; d++) {
        for (int a = 0; a < NUM_ACCOUNTS; a++) expectedAliases.add(new Names.IDNName(ACCOUNT_ALIAS_NAME(a, d, domainIdx)).uName());
        for (int nd = 0; nd < NUM_DLS_NESTED; nd++) expectedAliases.add(new Names.IDNName(NESTED_DL_ALIAS_NAME(nd, d, domainIdx)).uName());
        for (int td = 0; td < NUM_DLS_TOP; td++) expectedAliases.add(new Names.IDNName(TOP_DL_ALIAS_NAME(td, d, domainIdx)).uName());
        for (int dg = 0; dg < NUM_DYNAMIC_GROUPS; dg++) expectedAliases.add(new Names.IDNName(DYNAMIC_GROUP_ALIAS_NAME(dg, d, domainIdx)).uName());
    }
    // verify all our aliases are there
    Set<String> actualAliases = namedEntryListToNameSet(list, UnicodeOrACE.UNICODE);
    // dumpStrings(expectedAliases);
    // dumpStrings(actualAliases);
    Verify.verifyEquals(expectedAliases, actualAliases);
    // verify the target of each alias can be found
    for (NamedEntry entry : list) {
        assertTrue(entry instanceof Alias);
        NamedEntry target = prov.searchAliasTarget((Alias) entry, true);
        assertNotNull(target);
    }
}
Also used : Names(com.zimbra.qa.unittest.prov.Names) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) Alias(com.zimbra.cs.account.Alias) HashSet(java.util.HashSet)

Example 13 with SearchDirectoryOptions

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

the class TestLdapProvSearchDirectory method searchAliasTarget.

@Test
public void searchAliasTarget() throws Exception {
    Account acct = createAccount(genAcctNameLocalPart("acct"));
    CalendarResource cr = createCalendarResource(genAcctNameLocalPart("cr"));
    DistributionList dl = createDistributionList(genGroupNameLocalPart("dl"));
    DynamicGroup dg = createDynamicGroup(genGroupNameLocalPart("dg"));
    // prepend a digit so the order returned from SearchDirectory is predictable
    prov.addAlias(acct, TestUtil.getAddress("1-acct-alias", domain.getName()));
    prov.addAlias(cr, TestUtil.getAddress("2-cr-alias", domain.getName()));
    prov.addGroupAlias(dl, TestUtil.getAddress("3-dl-alias", domain.getName()));
    prov.addGroupAlias(dg, TestUtil.getAddress("4-dg-alias", domain.getName()));
    SearchDirectoryOptions options = new SearchDirectoryOptions(domain);
    options.setTypes(ObjectType.aliases);
    options.setSortOpt(SortOpt.SORT_ASCENDING);
    options.setFilterString(FilterId.UNITTEST, null);
    List<NamedEntry> aliases = prov.searchDirectory(options);
    assertEquals(4, aliases.size());
    Alias acctAlias = (Alias) aliases.get(0);
    Alias crAlias = (Alias) aliases.get(1);
    Alias dlAlias = (Alias) aliases.get(2);
    Alias dgAlias = (Alias) aliases.get(3);
    NamedEntry acctAliasTarget = prov.searchAliasTarget(acctAlias, true);
    assertEquals(acct.getId(), acctAliasTarget.getId());
    NamedEntry crAliasTarget = prov.searchAliasTarget(crAlias, true);
    assertEquals(cr.getId(), crAliasTarget.getId());
    NamedEntry dlAliasTarget = prov.searchAliasTarget(dlAlias, true);
    assertEquals(dl.getId(), dlAliasTarget.getId());
    NamedEntry dgAliasTarget = prov.searchAliasTarget(dgAlias, true);
    assertEquals(dg.getId(), dgAliasTarget.getId());
    deleteAccount(acct);
    deleteAccount(cr);
    deleteGroup(dl);
    deleteGroup(dg);
}
Also used : Account(com.zimbra.cs.account.Account) DynamicGroup(com.zimbra.cs.account.DynamicGroup) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) Alias(com.zimbra.cs.account.Alias) CalendarResource(com.zimbra.cs.account.CalendarResource) DistributionList(com.zimbra.cs.account.DistributionList) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 14 with SearchDirectoryOptions

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

the class TestLdapProvSearchDirectory method filterWithTrailingDot.

@Test
@Bug(bug = 68964)
public void filterWithTrailingDot() throws Exception {
    Domain subDomain = provUtil.createDomain(genDomainName(baseDomainName()));
    Account acct = provUtil.createAccount(genAcctNameLocalPart(), subDomain);
    SearchDirectoryOptions options = new SearchDirectoryOptions();
    options.setDomain(subDomain);
    options.setTypes(SearchDirectoryOptions.ObjectType.accounts);
    options.setFilterString(FilterId.UNITTEST, "(zimbraMailDeliveryAddress=*.*)");
    options.setReturnAttrs(new String[] { Provisioning.A_zimbraMailDeliveryAddress });
    options.setConvertIDNToAscii(true);
    List<NamedEntry> entries = prov.searchDirectory(options);
    Verify.verifyEquals(Lists.newArrayList(acct), entries, true);
    deleteAccount(acct);
    deleteDomain(subDomain);
}
Also used : Account(com.zimbra.cs.account.Account) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) Domain(com.zimbra.cs.account.Domain) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) ProvTest(com.zimbra.qa.unittest.prov.ProvTest) Bug(com.zimbra.qa.QA.Bug)

Example 15 with SearchDirectoryOptions

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

the class TestLdapProvSearchDirectory method wildcardFilter.

@Test
@Bug(bug = 67379)
public void wildcardFilter() throws Exception {
    Account acct1 = createAccount(genAcctNameLocalPart("1"));
    Account acct2 = createAccount(genAcctNameLocalPart("2"));
    Account acct3 = createAccount(genAcctNameLocalPart("3"));
    SearchDirectoryOptions options = new SearchDirectoryOptions(domain);
    options.setTypes(ObjectType.accounts);
    options.setSortOpt(SortOpt.SORT_ASCENDING);
    options.setFilterString(FilterId.UNITTEST, "(cn=*)");
    options.setConvertIDNToAscii(true);
    List<NamedEntry> entries = prov.searchDirectory(options);
    Verify.verifyEquals(Lists.newArrayList(acct1, acct2, acct3), entries, true);
    deleteAccount(acct1);
    deleteAccount(acct2);
    deleteAccount(acct3);
}
Also used : Account(com.zimbra.cs.account.Account) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) NamedEntry(com.zimbra.cs.account.NamedEntry) ProvTest(com.zimbra.qa.unittest.prov.ProvTest) Bug(com.zimbra.qa.QA.Bug)

Aggregations

SearchDirectoryOptions (com.zimbra.cs.account.SearchDirectoryOptions)30 NamedEntry (com.zimbra.cs.account.NamedEntry)19 Account (com.zimbra.cs.account.Account)11 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)9 Domain (com.zimbra.cs.account.Domain)8 DistributionList (com.zimbra.cs.account.DistributionList)7 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)5 Provisioning (com.zimbra.cs.account.Provisioning)4 Element (com.zimbra.common.soap.Element)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 DynamicGroup (com.zimbra.cs.account.DynamicGroup)3 AdminSession (com.zimbra.cs.session.AdminSession)3 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 List (java.util.List)3 ServiceException (com.zimbra.common.service.ServiceException)2 Alias (com.zimbra.cs.account.Alias)2 CalendarResource (com.zimbra.cs.account.CalendarResource)2 LdapDistributionList (com.zimbra.cs.account.ldap.entry.LdapDistributionList)2