use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method getAllAccountsByDomainAndServer.
@Test
public void getAllAccountsByDomainAndServer() throws Exception {
Account acct3 = createAccount(genAcctNameLocalPart("3"));
Account acct2 = createAccount(genAcctNameLocalPart("2"));
Account acct1 = createAccount(genAcctNameLocalPart("1"));
CalendarResource cr = createCalendarResource(genAcctNameLocalPart("cr"));
final List<NamedEntry> acctsVisitor = Lists.newArrayList();
NamedEntry.Visitor visitor = new NamedEntry.Visitor() {
@Override
public void visit(NamedEntry entry) throws ServiceException {
acctsVisitor.add(entry);
}
};
Server server = prov.getLocalServer();
prov.getAllAccounts(domain, server, visitor);
Verify.verifyEquals(Lists.newArrayList(acct1, acct2, acct3), acctsVisitor, false);
acctsVisitor.clear();
Server otherServer = createServer(genServerName());
prov.getAllAccounts(domain, otherServer, visitor);
Verify.verifyEquals(null, acctsVisitor, false);
deleteAccount(acct1);
deleteAccount(acct2);
deleteAccount(acct3);
deleteAccount(cr);
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method chineseFilter.
@Test
public void chineseFilter() throws Exception {
Map<String, Object> acct1Attrs = Maps.newHashMap();
acct1Attrs.put(Provisioning.A_cn, "中文 1");
Account acct1 = createAccount(genAcctNameLocalPart("1"), acct1Attrs);
Map<String, Object> acct2Attrs = Maps.newHashMap();
acct2Attrs.put(Provisioning.A_cn, "中文 2");
Account acct2 = createAccount(genAcctNameLocalPart("2"), acct2Attrs);
Map<String, Object> acct3Attrs = Maps.newHashMap();
acct3Attrs.put(Provisioning.A_cn, "中文 3");
Account acct3 = createAccount(genAcctNameLocalPart("3"), acct3Attrs);
SearchDirectoryOptions options = new SearchDirectoryOptions(domain);
options.setTypes(ObjectType.accounts);
options.setSortOpt(SortOpt.SORT_ASCENDING);
options.setFilterString(FilterId.UNITTEST, "(cn=中文 2)");
options.setConvertIDNToAscii(true);
List<NamedEntry> entries = prov.searchDirectory(options);
Verify.verifyEquals(Lists.newArrayList(acct2), entries, true);
deleteAccount(acct1);
deleteAccount(acct2);
deleteAccount(acct3);
}
use of com.zimbra.cs.account.NamedEntry 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))"
*/
}
use of com.zimbra.cs.account.NamedEntry 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);
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method testFilterWithCharsNeedEscaping.
private void testFilterWithCharsNeedEscaping(Account expected, String filterAttr, String filterValue) throws Exception {
SearchDirectoryOptions options = new SearchDirectoryOptions();
options.setDomain(prov.getDomain(expected));
options.setTypes(SearchDirectoryOptions.ObjectType.accounts);
options.setFilterString(FilterId.UNITTEST, String.format("(%s=%s)", filterAttr, filterValue));
options.setReturnAttrs(new String[] { Provisioning.A_zimbraMailDeliveryAddress });
options.setConvertIDNToAscii(true);
List<NamedEntry> entries = prov.searchDirectory(options);
Verify.verifyEquals(Lists.newArrayList(expected), entries, true);
}
Aggregations