Search in sources :

Example 11 with IAttributes

use of com.zimbra.cs.ldap.IAttributes 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

IAttributes (com.zimbra.cs.ldap.IAttributes)11 SearchLdapVisitor (com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor)9 ServiceException (com.zimbra.common.service.ServiceException)8 AccountServiceException (com.zimbra.cs.account.AccountServiceException)6 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)6 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)4 Account (com.zimbra.cs.account.Account)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)2 LdapSizeLimitExceededException (com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException)2 ZAttributes (com.zimbra.cs.ldap.ZAttributes)2 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)2 TreeMap (java.util.TreeMap)2 Domain (com.zimbra.cs.account.Domain)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1