use of com.zimbra.cs.account.ldap.LdapDIT 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");
}
}
}
use of com.zimbra.cs.account.ldap.LdapDIT in project zm-mailbox by Zimbra.
the class TestLdapHelper method searchForEntry.
@Test
public void searchForEntry() throws Exception {
LdapDIT dit = prov.getDIT();
String base = dit.configBranchBaseDN();
ZLdapFilter filter = filterFactory.fromFilterString(FilterId.UNITTEST, "(cn=config)");
ZSearchResultEntry sr = ldapHelper.searchForEntry(base, filter, null, false);
assertNotNull(sr);
assertEquals("cn=config,cn=zimbra", sr.getDN());
}
use of com.zimbra.cs.account.ldap.LdapDIT in project zm-mailbox by Zimbra.
the class TestLdapHelper method searchDirNotFound.
@Test
public void searchDirNotFound() throws Exception {
LdapDIT dit = prov.getDIT();
String base = dit.configBranchBaseDN();
ZLdapFilter filter = filterFactory.allSignatures();
String[] returnAttrs = new String[] { "objectClass" };
ZSearchControls searchControls = ZSearchControls.createSearchControls(ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);
ZSearchResultEnumeration ne = ldapHelper.searchDir(base, filter, searchControls);
int numFound = 0;
while (ne.hasMore()) {
ZSearchResultEntry sr = ne.next();
numFound++;
}
ne.close();
assertEquals(0, numFound);
}
use of com.zimbra.cs.account.ldap.LdapDIT in project zm-mailbox by Zimbra.
the class TestLdap method deleteAllNonDefaultServers.
private static void deleteAllNonDefaultServers() throws Exception {
LdapProv ldapProv = LdapProv.getInst();
LdapDIT dit = ldapProv.getDIT();
String serverBaseDN = dit.serverBaseDN();
Set<String> defaultServerDN = new HashSet<String>();
defaultServerDN.add(dit.serverNameToDN(ldapProv.getLocalServer().getName()));
deleteAllChildrenUnderDN(serverBaseDN, defaultServerDN);
}
use of com.zimbra.cs.account.ldap.LdapDIT 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);
}
}
Aggregations