Search in sources :

Example 16 with SearchAccountsOptions

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

the class TestLdapProvSearchDirectory method CMBSearchNonSystemResourceAccountsOnly.

@Test
public void CMBSearchNonSystemResourceAccountsOnly() throws Exception {
    Account acct1 = createAccount(genAcctNameLocalPart("1"));
    Map<String, Object> acct2Attrs = Maps.newHashMap();
    acct2Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "TRUE");
    Account acct2 = createAccount(genAcctNameLocalPart("2"), acct2Attrs);
    Map<String, Object> acct3Attrs = Maps.newHashMap();
    acct3Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
    Account acct3 = createAccount(genAcctNameLocalPart("3"), acct3Attrs);
    Map<String, Object> acct4Attrs = Maps.newHashMap();
    acct4Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
    acct4Attrs.put(Provisioning.A_zimbraIsSystemResource, "TRUE");
    Account acct4 = createAccount(genAcctNameLocalPart("4"), acct4Attrs);
    Map<String, Object> acct5Attrs = Maps.newHashMap();
    acct5Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
    acct5Attrs.put(Provisioning.A_zimbraIsSystemResource, "FALSE");
    Account acct5 = createAccount(genAcctNameLocalPart("5"), acct5Attrs);
    String[] returnAttrs = { Provisioning.A_displayName, Provisioning.A_zimbraId, Provisioning.A_uid, Provisioning.A_zimbraArchiveAccount, Provisioning.A_zimbraMailHost };
    // use domain so our assertion will work, production code does not a domain
    SearchAccountsOptions searchOpts = new SearchAccountsOptions(domain, returnAttrs);
    searchOpts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
    searchOpts.setSortOpt(SortOpt.SORT_DESCENDING);
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().CMBSearchNonSystemResourceAccountsOnly();
    searchOpts.setFilter(filter);
    List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
    Verify.verifyEquals(Lists.newArrayList(acct5, acct3, acct1), accounts, true);
    deleteAccount(acct1);
    deleteAccount(acct2);
    deleteAccount(acct3);
    deleteAccount(acct4);
    deleteAccount(acct5);
/*
        // legacy code and LDAP trace before refactoring
        List<NamedEntry> accounts = prov.searchAccounts(
                "(&(!(" + Provisioning.A_zimbraIsSystemResource + "=*))(|(!(" +
                Provisioning.A_zimbraExcludeFromCMBSearch + "=*))(" +
                Provisioning.A_zimbraExcludeFromCMBSearch + "=FALSE)))",
                returnAttrs, null, false, Provisioning.searchDirectoryStringToMask("accounts"));

        Oct  9 14:55:09 pshao-macbookpro-2 slapd[73952]: conn=1352 op=172 SRCH base="" scope=2 deref=0 filter="(&(&(!(zimbraIsSystemResource=*))(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource))))"
        Oct  9 14:55:09 pshao-macbookpro-2 slapd[73952]: conn=1352 op=172 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
        */
/*
         * LDAP trace after reactoring
         *
        Oct  9 16:18:04 pshao-macbookpro-2 slapd[73952]: conn=1381 op=127 SRCH base="ou=people,dc=com,dc=zimbra,dc=qa,dc=unittest,dc=testldapprovaccount" scope=2 deref=0 filter="(&(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource)))(!(zimbraIsSystemResource=TRUE))(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))"
        Oct  9 16:18:04 pshao-macbookpro-2 slapd[73952]: conn=1381 op=127 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
        */
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 17 with SearchAccountsOptions

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

the class TestLdapProvSearchDirectory method CMBSearchAccountsOnlyWithArchive.

@Test
public void CMBSearchAccountsOnlyWithArchive() throws Exception {
    Account acct1 = createAccount(genAcctNameLocalPart("1"));
    Map<String, Object> acct2Attrs = Maps.newHashMap();
    acct2Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "TRUE");
    Account acct2 = createAccount(genAcctNameLocalPart("2"), acct2Attrs);
    Map<String, Object> acct3Attrs = Maps.newHashMap();
    acct3Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
    Account acct3 = createAccount(genAcctNameLocalPart("3"), acct3Attrs);
    Map<String, Object> acct4Attrs = Maps.newHashMap();
    acct4Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
    acct4Attrs.put(Provisioning.A_zimbraArchiveAccount, "archive@test.com");
    Account acct4 = createAccount(genAcctNameLocalPart("4"), acct4Attrs);
    String[] returnAttrs = { Provisioning.A_displayName, Provisioning.A_zimbraId, Provisioning.A_uid, Provisioning.A_zimbraArchiveAccount, Provisioning.A_zimbraMailHost };
    // use domain so our assertion will work, production code does not a domain
    SearchAccountsOptions searchOpts = new SearchAccountsOptions(domain, returnAttrs);
    searchOpts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
    searchOpts.setSortOpt(SortOpt.SORT_DESCENDING);
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().CMBSearchAccountsOnlyWithArchive();
    searchOpts.setFilter(filter);
    List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
    Verify.verifyEquals(Lists.newArrayList(acct4), accounts, true);
    deleteAccount(acct1);
    deleteAccount(acct2);
    deleteAccount(acct3);
    deleteAccount(acct4);
/*
        // legacy code and LDAP trace before refactoring
        List<NamedEntry> accounts = prov.searchAccounts(
                "(&(" + Provisioning.A_zimbraArchiveAccount + "=*)(|(!(" +
                Provisioning.A_zimbraExcludeFromCMBSearch + "=*))(" +
                Provisioning.A_zimbraExcludeFromCMBSearch + "=FALSE)))",
                returnAttrs,null,false,Provisioning.searchDirectoryStringToMask("accounts"));

        Oct  9 16:40:05 pshao-macbookpro-2 slapd[73952]: conn=1388 op=172 SRCH base="" scope=2 deref=0 filter="(&(&(zimbraArchiveAccount=*)(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource))))"
        Oct  9 16:40:05 pshao-macbookpro-2 slapd[73952]: conn=1388 op=172 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
        */
/*
         * LDAP trace after reactoring
         *
        Oct  9 17:03:11 pshao-macbookpro-2 slapd[73952]: conn=1413 op=125 SRCH base="ou=people,dc=com,dc=zimbra,dc=qa,dc=unittest,dc=testldapprovaccount" scope=2 deref=0 filter="(&(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource)))(zimbraArchiveAccount=*)(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))"
        Oct  9 17:03:11 pshao-macbookpro-2 slapd[73952]: conn=1413 op=125 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
        */
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 18 with SearchAccountsOptions

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

the class TestLdapProvSearchDirectory method sslClientCertPrincipalMap.

@Test
public void sslClientCertPrincipalMap() throws Exception {
    // don't use genAcctNameLocalPart() for this test, sicne filterStr is also hardcoded
    // we don't want to assume genAcctNameLocalPart() will always return the method name
    Account acct1 = createAccount("sslClientCertPrincipalMap-1");
    String filterStr = "(uid=sslClientCertPrincipalMap*)";
    SearchAccountsOptions searchOpts = new SearchAccountsOptions();
    searchOpts.setMaxResults(1);
    searchOpts.setFilterString(FilterId.ACCOUNT_BY_SSL_CLENT_CERT_PRINCIPAL_MAP, filterStr);
    List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
    Verify.verifyEquals(Lists.newArrayList(acct1), accounts, false);
    // create another account with same uid prefix
    Account acct2 = createAccount("sslClientCertPrincipalMap-2");
    searchOpts = new SearchAccountsOptions();
    searchOpts.setMaxResults(1);
    searchOpts.setFilterString(FilterId.ACCOUNT_BY_SSL_CLENT_CERT_PRINCIPAL_MAP, filterStr);
    boolean caughtTooManySearchResultsException = false;
    try {
        accounts = prov.searchDirectory(searchOpts);
    } catch (ServiceException e) {
        if (AccountServiceException.TOO_MANY_SEARCH_RESULTS.equals(e.getCode())) {
            caughtTooManySearchResultsException = true;
        }
    }
    assertTrue(caughtTooManySearchResultsException);
    deleteAccount(acct1);
    deleteAccount(acct2);
/*
        // legacy code and LDAP trace before refactoring
         *

        String filterStr = "(uid=sslClientCertPrincipalMap)";
        filter = "(&" + ZLdapFilterFactory.getInstance().allAccounts().toFilterString() + filterStr + ")";

        SearchOptions options = new SearchOptions();
        options.setMaxResults(1);
        options.setFlags(Provisioning.SO_NO_FIXUP_OBJECTCLASS);
        options.setQuery(filter);

        // should return at most one entry.  If more than one entries were matched,
        // TOO_MANY_SEARCH_RESULTS will be thrown
        List<NamedEntry> entries = prov.searchDirectory(options);

        Oct  9 19:28:20 pshao-macbookpro-2 slapd[73952]: conn=1417 op=165 SRCH base="" scope=2 deref=0 filter="(&(objectClass=zimbraAccount)(uid=sslclientcertprincipalmap))"
        Oct  9 19:28:20 pshao-macbookpro-2 slapd[73952]: conn=1417 op=165 SEARCH RESULT tag=101 err=0 nentries=0 text=
        */
/*
         // LDAP trace after refactoring
         Oct  9 19:58:39 pshao-macbookpro-2 slapd[73952]: conn=1438 op=220 SRCH base="" scope=2 deref=0 filter="(&(|(objectClass=zimbraAccount)(objectClass=zimbraCalendarResource))(uid=sslclientcertprincipalmap))"

         */
}
Also used : Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 19 with SearchAccountsOptions

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

the class TestLdapProvSearchDirectory method searchAccountsOnServer.

@Test
public void searchAccountsOnServer() throws Exception {
    // create a search domain
    String DOMAIN_NAME = genDomainSegmentName() + "." + baseDomainName();
    Domain searchDomain = provUtil.createDomain(DOMAIN_NAME, null);
    // create an account and a calendar resource on the domain
    String ACCT_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("acct"));
    String CR_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("cr"));
    Map<String, Object> crAttrs = Maps.newHashMap();
    crAttrs.put(Provisioning.A_displayName, "ACCT_LOCALPART");
    crAttrs.put(Provisioning.A_zimbraCalResType, Provisioning.CalResType.Equipment.name());
    Account acct = createAccount(prov, ACCT_LOCALPART, searchDomain, null);
    CalendarResource cr = createCalendarResource(CR_LOCALPART, searchDomain, crAttrs);
    Server server = prov.getLocalServer();
    List<NamedEntry> result;
    SearchAccountsOptions opts;
    // 1. test search accounts, including cr
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(acct, cr), result, false);
    // 2. test maxResults
    boolean caughtTooManySearchResultsException = false;
    try {
        opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
        opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
        opts.setMaxResults(1);
        result = prov.searchAccountsOnServer(server, opts);
    } catch (ServiceException e) {
        if (AccountServiceException.TOO_MANY_SEARCH_RESULTS.equals(e.getCode())) {
            caughtTooManySearchResultsException = true;
        }
    }
    assertTrue(caughtTooManySearchResultsException);
    // 3. search accounts only
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    opts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(acct), result, false);
    // 4. test sorting
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    opts.setSortOpt(SortOpt.SORT_DESCENDING);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(cr, acct), result, true);
    opts = new SearchAccountsOptions(searchDomain, new String[] { Provisioning.A_zimbraId });
    opts.setMakeObjectOpt(MakeObjectOpt.NO_DEFAULTS);
    opts.setSortOpt(SortOpt.SORT_ASCENDING);
    result = prov.searchAccountsOnServer(server, opts);
    Verify.verifyEquals(Lists.newArrayList(acct, cr), result, true);
}
Also used : Account(com.zimbra.cs.account.Account) NamedEntry(com.zimbra.cs.account.NamedEntry) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Domain(com.zimbra.cs.account.Domain) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) CalendarResource(com.zimbra.cs.account.CalendarResource) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Aggregations

SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)19 NamedEntry (com.zimbra.cs.account.NamedEntry)12 Account (com.zimbra.cs.account.Account)9 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)7 Provisioning (com.zimbra.cs.account.Provisioning)5 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)5 Server (com.zimbra.cs.account.Server)4 ServiceException (com.zimbra.common.service.ServiceException)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 Domain (com.zimbra.cs.account.Domain)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ZMailbox (com.zimbra.client.ZMailbox)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 Element (com.zimbra.common.soap.Element)1 AddressList (com.zimbra.cs.account.AddressList)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 CalendarResource (com.zimbra.cs.account.CalendarResource)1 DistributionList (com.zimbra.cs.account.DistributionList)1