Search in sources :

Example 11 with LdapDIT

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");
        }
    }
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ServiceException(com.zimbra.common.service.ServiceException) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions)

Example 12 with LdapDIT

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());
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 13 with LdapDIT

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);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 14 with LdapDIT

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);
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) LdapProv(com.zimbra.cs.account.ldap.LdapProv) HashSet(java.util.HashSet)

Example 15 with LdapDIT

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);
    }
}
Also used : Account(com.zimbra.cs.account.Account) LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) ServiceException(com.zimbra.common.service.ServiceException) IAttributes(com.zimbra.cs.ldap.IAttributes) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) HashSet(java.util.HashSet)

Aggregations

LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)15 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)7 HashSet (java.util.HashSet)7 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)5 ServiceException (com.zimbra.common.service.ServiceException)4 LdapProv (com.zimbra.cs.account.ldap.LdapProv)4 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)4 SearchLdapVisitor (com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor)4 Account (com.zimbra.cs.account.Account)2 IAttributes (com.zimbra.cs.ldap.IAttributes)2 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 ZSearchControls (com.zimbra.cs.ldap.ZSearchControls)2 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)2 LdapMultipleEntriesMatchedException (com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException)1