use of com.zimbra.cs.account.NamedEntry 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);
}
use of com.zimbra.cs.account.NamedEntry 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.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method getAllAccounts.
@Test
public void getAllAccounts() throws Exception {
Account acct3 = createAccount(genAcctNameLocalPart("3"));
Account acct2 = createAccount(genAcctNameLocalPart("2"));
Account acct1 = createAccount(genAcctNameLocalPart("1"));
CalendarResource cr = createCalendarResource(genAcctNameLocalPart("cr"));
List<NamedEntry> accounts = prov.getAllAccounts(domain);
Verify.verifyEquals(Lists.newArrayList(acct1, acct2, acct3), accounts, true);
// test the visitor interface, sorting is not supported with visitor interface
final List<NamedEntry> acctsByVisitor = Lists.newArrayList();
NamedEntry.Visitor visitor = new NamedEntry.Visitor() {
@Override
public void visit(NamedEntry entry) throws ServiceException {
acctsByVisitor.add(entry);
}
};
prov.getAllAccounts(domain, visitor);
Verify.verifyEquals(Lists.newArrayList(acct1, acct2, acct3), accounts, 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 searchGrantee.
@Test
public void searchGrantee() throws Exception {
String granteeId = LdapUtil.generateUUID();
byte gtype = ACL.GRANTEE_USER;
SearchDirectoryOptions opts = new SearchDirectoryOptions();
if (gtype == ACL.GRANTEE_USER) {
opts.addType(SearchDirectoryOptions.ObjectType.accounts);
opts.addType(SearchDirectoryOptions.ObjectType.resources);
} else if (gtype == ACL.GRANTEE_GROUP) {
opts.addType(SearchDirectoryOptions.ObjectType.distributionlists);
} else if (gtype == ACL.GRANTEE_COS) {
opts.addType(SearchDirectoryOptions.ObjectType.coses);
} else if (gtype == ACL.GRANTEE_DOMAIN) {
opts.addType(SearchDirectoryOptions.ObjectType.domains);
} else {
throw ServiceException.INVALID_REQUEST("invalid grantee type for revokeOrphanGrants", null);
}
String query = "(" + Provisioning.A_zimbraId + "=" + granteeId + ")";
opts.setFilterString(FilterId.SEARCH_GRANTEE, query);
// search the grantee on LDAP master
opts.setOnMaster(true);
Provisioning prov = Provisioning.getInstance();
List<NamedEntry> entries = prov.searchDirectory(opts);
/*
// logacy code and LDAP trace
int flags = 0;
if (gtype == ACL.GRANTEE_USER)
flags |= (Provisioning.SD_ACCOUNT_FLAG | Provisioning.SD_CALENDAR_RESOURCE_FLAG) ;
else if (gtype == ACL.GRANTEE_GROUP)
flags |= Provisioning.SD_DISTRIBUTION_LIST_FLAG;
else if (gtype == ACL.GRANTEE_COS)
flags |= Provisioning.SD_COS_FLAG;
else if (gtype == ACL.GRANTEE_DOMAIN)
flags |= Provisioning.SD_DOMAIN_FLAG;
else
throw ServiceException.INVALID_REQUEST("invalid grantee type for revokeOrphanGrants", null);
String query = "(" + Provisioning.A_zimbraId + "=" + granteeId + ")";
Provisioning.SearchOptions opts = new SearchOptions();
opts.setFlags(flags);
opts.setQuery(query);
opts.setOnMaster(true); // search the grantee on LDAP master
Provisioning prov = Provisioning.getInstance();
List<NamedEntry> entries = prov.searchDirectory(opts);
Oct 9 23:09:26 pshao-macbookpro-2 slapd[73952]: conn=1531 op=209 SRCH base="" scope=2 deref=0 filter="(&(zimbraId=8b435b63-40c3-4de7-b105-869cbafea29b)(|(objectClass=zimbraAccount)(objectClass=zimbraCalendarResource)))"
*/
/*
// LDAP trace after refactoring
Oct 9 23:26:59 pshao-macbookpro-2 slapd[73952]: conn=1535 op=209 SRCH base="" scope=2 deref=0 filter="(&(|(objectClass=zimbraAccount)(objectClass=zimbraCalendarResource))(zimbraId=561fcc6d-6a09-432e-8346-3f1752eea3f9))"
*/
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method maxResults.
@Test
public void maxResults() throws Exception {
// must be greator than 1
int NUM_ACCTS = 3;
List<Account> accts = Lists.newArrayList();
for (int i = 0; i < NUM_ACCTS; i++) {
Map<String, Object> attrs = Maps.newHashMap();
attrs.put(Provisioning.A_displayName, "acct-" + i);
String ACCT_LOCALPART = Names.makeAccountNameLocalPart("acct-" + i);
Account acct = createAccount(ACCT_LOCALPART, attrs);
accts.add(acct);
}
String filter = "(uid=*)";
String sortAttr = Provisioning.A_displayName;
String[] returnAttrs = new String[] { Provisioning.A_displayName, Provisioning.A_zimbraId, Provisioning.A_zimbraMailHost, Provisioning.A_uid, Provisioning.A_zimbraAccountStatus, Provisioning.A_zimbraIsAdminAccount, Provisioning.A_zimbraMailStatus };
SearchDirectoryOptions searchOpts = new SearchDirectoryOptions();
searchOpts.setDomain(domain);
searchOpts.setTypes(SearchDirectoryOptions.ObjectType.accounts);
// unlimited
searchOpts.setMaxResults(0);
searchOpts.setFilterString(FilterId.UNITTEST, filter);
searchOpts.setReturnAttrs(returnAttrs);
searchOpts.setSortOpt(SortOpt.SORT_ASCENDING);
searchOpts.setSortAttr(sortAttr);
List<NamedEntry> result = prov.searchDirectory(searchOpts);
Verify.verifyEquals(accts, result, true);
searchOpts.setMaxResults(NUM_ACCTS - 1);
boolean caughtException = false;
try {
prov.searchDirectory(searchOpts);
} catch (ServiceException e) {
if (AccountServiceException.TOO_MANY_SEARCH_RESULTS.equals(e.getCode())) {
caughtException = true;
}
}
assertTrue(caughtException);
for (Account acct : accts) {
deleteAccount(acct);
}
}
Aggregations