use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class TestLdapProvDomain method verifyAllDomains.
private void verifyAllDomains(List<Domain> allDomains) throws Exception {
// domains created by r-t-w
// TODO: this verification is very fragile
Set<String> expectedDomains = new HashSet<String>();
String defaultDomainName = prov.getInstance().getConfig().getDefaultDomainName();
expectedDomains.add(defaultDomainName);
expectedDomains.add("example.com");
assertEquals(expectedDomains.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(expectedDomains.contains(domain.getName()));
}
//
// another verification
//
LdapHelper ldapHelper = ((LdapProv) prov).getHelper();
final List<String> /* zimbraId */
domainIds = new ArrayList<String>();
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
try {
domainIds.add(ldapAttrs.getAttrString(Provisioning.A_zimbraId));
} catch (ServiceException e) {
fail();
}
}
};
SearchLdapOptions searchOpts = new SearchLdapOptions(LdapConstants.DN_ROOT_DSE, ZLdapFilterFactory.getInstance().fromFilterString(FilterId.UNITTEST, "(objectclass=zimbraDomain)"), new String[] { Provisioning.A_zimbraId }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapUsage.UNITTEST);
ldapHelper.searchLdap(zlc, searchOpts);
} finally {
LdapClient.closeContext(zlc);
}
assertEquals(domainIds.size(), allDomains.size());
for (Domain domain : allDomains) {
assertTrue(domainIds.contains(domain.getId()));
}
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class TestLdapZLdapContext method searchPaged.
@Test
public void searchPaged() throws Exception {
int SIZE_LIMIT = 5;
String base = LdapConstants.DN_ROOT_DSE;
ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
String[] returnAttrs = new String[] { "objectClass" };
final List<String> result = new ArrayList<String>();
SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {
@Override
public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
result.add(dn);
}
};
SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, returnAttrs, SIZE_LIMIT, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
boolean caughtException = false;
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapUsage.UNITTEST);
zlc.searchPaged(searchOptions);
} catch (LdapSizeLimitExceededException e) {
caughtException = true;
} finally {
LdapClient.closeContext(zlc);
}
assertTrue(caughtException);
assertEquals(SIZE_LIMIT, result.size());
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class LdapProvisioning method searchContainingDynamicGroupIdsForExternalAddress.
/*
* returns zimbraId of dynamic groups containing addr as an external member.
*/
private Set<String> searchContainingDynamicGroupIdsForExternalAddress(String addr, ZLdapContext initZlc) {
final Set<String> groupIds = Sets.newHashSet();
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
String groupId = null;
try {
groupId = ldapAttrs.getAttrString(A_zimbraGroupId);
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to get attr", e);
}
if (groupId != null) {
groupIds.add(groupId);
}
}
};
ZLdapContext zlc = initZlc;
try {
if (zlc == null) {
zlc = LdapClient.getContext(LdapServerType.REPLICA, LdapUsage.SEARCH);
}
String base = mDIT.mailBranchBaseDN();
ZLdapFilter filter = filterFactory.dynamicGroupsStaticUnitByMemberAddr(addr);
SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, new String[] { A_zimbraGroupId }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOptions);
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to search dynamic groups for guest acct", e);
} finally {
if (initZlc == null) {
LdapClient.closeContext(zlc);
}
}
return groupIds;
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class BUG_57866 method upgradeWikiAccounts.
private void upgradeWikiAccounts(ZLdapContext zlc) throws ServiceException {
// global wiki account
String acctName = prov.getConfig().getNotebookAccount();
if (acctName != null) {
printer.format("Checking global wiki account %s\n", acctName);
Account acct = prov.get(AccountBy.name, acctName);
setIsSystemAccount(zlc, acct);
}
// domain wiki accounts
LdapDIT dit = prov.getDIT();
String[] returnAttrs = new String[] { Provisioning.A_zimbraNotebookAccount };
String base = dit.mailBranchBaseDN();
String query = "(&(objectclass=zimbraDomain)(zimbraNotebookAccount=*))";
final Set<String> wikiAcctNames = new HashSet<String>();
SearchLdapVisitor visitor = new SearchLdapVisitor(false) {
@Override
public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
try {
String acctName;
acctName = ldapAttrs.getAttrString(Provisioning.A_zimbraNotebookAccount);
if (acctName != null) {
wikiAcctNames.add(acctName);
}
} catch (ServiceException e) {
printer.printStackTrace("unsble to search domains for wiki accounts", e);
}
}
};
SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOpts);
for (String wikiAcctName : wikiAcctNames) {
printer.format("Checking domain wiki account %s\n", wikiAcctName);
Account acct = prov.get(AccountBy.name, wikiAcctName);
setIsSystemAccount(zlc, acct);
}
}
use of com.zimbra.cs.ldap.SearchLdapOptions in project zm-mailbox by Zimbra.
the class BUG_22033 method doUpgrade.
@Override
void doUpgrade() throws ServiceException {
LdapDIT dit = prov.getDIT();
String base;
String query;
String[] returnAttrs = new String[] { Provisioning.A_objectClass, Provisioning.A_zimbraCreateTimestamp, "createTimestamp" };
if (mType == null) {
printer.println("Checking all objects\n");
base = dit.zimbraBaseDN();
query = "(|" + "(objectclass=zimbraAccount)" + "(objectclass=zimbraAlias)" + "(objectclass=zimbraCalendarResource)" + "(objectclass=zimbraGlobalConfig)" + "(objectclass=zimbraCOS)" + "(objectclass=zimbraDataSource)" + "(objectclass=zimbraDistributionList)" + "(objectclass=zimbraDomain)" + "(objectclass=zimbraIdentity)" + "(objectclass=zimbraServer)" + "(objectclass=zimbraSignature)" + "(objectclass=zimbraXMPPComponent)" + "(objectclass=zimbraZimletEntry)" + ")";
} else {
printer.println("Checking " + mType.name() + " objects...\n");
switch(mType) {
case account:
base = dit.mailBranchBaseDN();
query = "(&(objectclass=zimbraAccount)(!(objectclass=zimbraCalendarResource)))";
break;
case alias:
base = dit.mailBranchBaseDN();
query = "(objectclass=zimbraAlias)";
break;
case calendarresource:
base = dit.mailBranchBaseDN();
query = "(objectclass=zimbraCalendarResource)";
break;
case config:
base = dit.configDN();
query = "(objectclass=zimbraGlobalConfig)";
break;
case cos:
base = dit.cosBaseDN();
query = "(objectclass=zimbraCOS)";
break;
case datasource:
base = dit.mailBranchBaseDN();
query = "(objectclass=zimbraDataSource)";
break;
case distributionlist:
base = dit.mailBranchBaseDN();
query = "(objectclass=zimbraDistributionList)";
break;
case domain:
base = dit.domainBaseDN();
query = "(objectclass=zimbraDomain)";
break;
case identity:
base = dit.mailBranchBaseDN();
query = "(objectclass=zimbraIdentity)";
break;
case server:
base = dit.serverBaseDN();
query = "(objectclass=zimbraServer)";
break;
case signature:
base = dit.mailBranchBaseDN();
query = "(objectclass=zimbraSignature)";
break;
case xmppcomponent:
base = dit.xmppcomponentBaseDN();
query = "(objectclass=zimbraXMPPComponent)";
break;
case zimlet:
base = dit.zimletBaseDN();
query = "(objectclass=zimbraZimletEntry)";
break;
default:
throw ServiceException.FAILURE("", null);
}
}
query = "(&" + "(!(zimbraCreateTimestamp=*))" + query + ")";
ZLdapContext zlc = null;
ZLdapContext modZlc = null;
Bug22033Visitor visitor = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
modZlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
visitor = new Bug22033Visitor(this, modZlc);
SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOpts);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all objects", e);
} finally {
LdapClient.closeContext(zlc);
LdapClient.closeContext(modZlc);
if (visitor != null) {
printer.println("\nModified " + visitor.getNumModified() + " objects");
}
}
}
Aggregations