use of com.zimbra.cs.account.SearchAccountsOptions in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAllAccounts.
@Override
public void getAllAccounts(Domain domain, NamedEntry.Visitor visitor) throws ServiceException {
SearchAccountsOptions opts = new SearchAccountsOptions(domain);
opts.setFilter(filterFactory.allAccountsOnly());
opts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
searchDirectory(opts, visitor);
}
use of com.zimbra.cs.account.SearchAccountsOptions in project zm-mailbox by Zimbra.
the class DataSourceCallback method lookupAccountsFromLDAP.
/*
* look up all accounts on this server with either the specified cos id, or without a cos id set on the account
* returns:
* - all accounts on this server
* - and with either the specified cos id, or without a cos id set on the account
* - and has at least one sub-entries
* (we can't tell whether those sub-entries are data sources, but this is as close as we can be searching for)
*/
private List<Account> lookupAccountsFromLDAP(Provisioning prov, String cosId) throws ServiceException {
SearchAccountsOptions searchOpts = new SearchAccountsOptions();
searchOpts.setFilter(ZLdapFilterFactory.getInstance().accountsOnServerAndCosHasSubordinates(prov.getLocalServer().getServiceHostname(), cosId));
List accts = prov.searchDirectory(searchOpts);
return accts;
}
use of com.zimbra.cs.account.SearchAccountsOptions in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method accountsByGrants.
@Test
public void accountsByGrants() throws Exception {
String GRANTEE_ID_1 = LdapUtil.generateUUID();
String GRANTEE_ID_2 = LdapUtil.generateUUID();
String GRANTEE_ID_3 = LdapUtil.generateUUID();
List<String> GRANTEE_IDS = Lists.newArrayList(GRANTEE_ID_1, GRANTEE_ID_2, GRANTEE_ID_3);
Map<String, Object> attrs1 = Maps.newHashMap();
attrs1.put(Provisioning.A_zimbraSharedItem, "granteeId:" + GRANTEE_ID_3 + "blah blah");
Account acct1 = createAccount(genAcctNameLocalPart("1"), attrs1);
Map<String, Object> attrs2 = Maps.newHashMap();
attrs2.put(Provisioning.A_zimbraSharedItem, "blah" + "granteeType:pub" + " blah");
Account acct2 = createAccount(genAcctNameLocalPart("2"), attrs2);
Map<String, Object> attrs3 = Maps.newHashMap();
attrs3.put(Provisioning.A_zimbraSharedItem, "blah" + "granteeType:all" + " blah");
Account acct3 = createAccount(genAcctNameLocalPart("3"), attrs3);
SearchAccountsOptions searchOpts = new SearchAccountsOptions(new String[] { Provisioning.A_zimbraId, Provisioning.A_displayName, Provisioning.A_zimbraSharedItem });
ZLdapFilter filter = ZLdapFilterFactory.getInstance().accountsByGrants(GRANTEE_IDS, true, false);
searchOpts.setFilter(filter);
// so our assertion below will always work
searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
Verify.verifyEquals(Lists.newArrayList(acct1, acct2), accounts, true);
deleteAccount(acct1);
deleteAccount(acct2);
deleteAccount(acct3);
}
use of com.zimbra.cs.account.SearchAccountsOptions in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method CMBSearchAccountsOnly.
@Test
public void CMBSearchAccountsOnly() 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);
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().CMBSearchAccountsOnly();
searchOpts.setFilter(filter);
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
Verify.verifyEquals(Lists.newArrayList(acct3, acct1), accounts, true);
deleteAccount(acct1);
deleteAccount(acct2);
deleteAccount(acct3);
/*
// legacy code and LDAP trace before refactoring
List<NamedEntry> accounts = prov.searchAccounts(
"(|(!(" + Provisioning.A_zimbraExcludeFromCMBSearch + "=*))(" +
Provisioning.A_zimbraExcludeFromCMBSearch + "=FALSE))",
attrs, null, false, Provisioning.searchDirectoryStringToMask("accounts"));
Oct 9 13:00:09 pshao-macbookpro-2 slapd[73952]: conn=1327 op=101 SRCH base="" scope=2 deref=0 filter="(&(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE))(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource))))"
Oct 9 13:00:09 pshao-macbookpro-2 slapd[73952]: conn=1327 op=101 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
*/
/*
* LDAP trace after reactoring
*
Oct 9 13:43:26 pshao-macbookpro-2 slapd[73952]: conn=1345 op=107 SRCH base="ou=people,dc=com,dc=zimbra,dc=qa,dc=unittest,dc=testldapprovaccount" scope=2 deref=0 filter="(&(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource)))(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))"
Oct 9 13:43:26 pshao-macbookpro-2 slapd[73952]: conn=1345 op=107 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
*/
}
use of com.zimbra.cs.account.SearchAccountsOptions in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method accountsOnServerAndCosHasSubordinates.
@Test
public void accountsOnServerAndCosHasSubordinates() throws Exception {
/*
* X.501: 14.4.4 Has Subordinates operational attribute
* is not supported in ubid InMemoryLdapServer
*/
SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.SUBORDINATES_OPERTIONAL_ATTRIBUTE);
String COS_ID = prov.get(CosBy.name, Provisioning.DEFAULT_COS_NAME).getId();
Account acct = createAccount(genAcctNameLocalPart());
Signature sig1 = prov.createSignature(acct, "sig1", new HashMap<String, Object>());
Signature sig2 = prov.createSignature(acct, "sig2", new HashMap<String, Object>());
SearchAccountsOptions searchOpts = new SearchAccountsOptions();
ZLdapFilter filter = ZLdapFilterFactory.getInstance().accountsOnServerAndCosHasSubordinates(prov.getLocalServer().getServiceHostname(), COS_ID);
searchOpts.setFilter(filter);
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
Verify.verifyEquals(Lists.newArrayList(acct), accounts, false);
deleteAccount(acct);
}
Aggregations