Search in sources :

Example 6 with SearchLdapVisitor

use of com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor in project zm-mailbox by Zimbra.

the class BUG_57866 method upgradeGalSyncAccounts.

private void upgradeGalSyncAccounts(ZLdapContext zlc) throws ServiceException {
    LdapDIT dit = prov.getDIT();
    String[] returnAttrs = new String[] { Provisioning.A_zimbraGalAccountId };
    String base = dit.mailBranchBaseDN();
    String query = "(&(objectclass=zimbraDomain)(zimbraGalAccountId=*))";
    final Set<String> galAcctIds = new HashSet<String>();
    SearchLdapVisitor visitor = new SearchLdapVisitor(false) {

        @Override
        public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
            try {
                String acctId;
                acctId = ldapAttrs.getAttrString(Provisioning.A_zimbraGalAccountId);
                if (acctId != null) {
                    galAcctIds.add(acctId);
                }
            } catch (ServiceException e) {
                printer.printStackTrace("unsble to search domains for GAL sync accounts", e);
            }
        }
    };
    SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    zlc.searchPaged(searchOpts);
    for (String galAcctId : galAcctIds) {
        printer.format("Checking GAL sync account %s\n", galAcctId);
        Account acct = prov.get(AccountBy.id, galAcctId);
        setIsSystemAccount(zlc, acct);
    }
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) IAttributes(com.zimbra.cs.ldap.IAttributes) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) HashSet(java.util.HashSet)

Example 7 with SearchLdapVisitor

use of com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor 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;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) IAttributes(com.zimbra.cs.ldap.IAttributes) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions)

Example 8 with SearchLdapVisitor

use of com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor 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)8 SearchLdapVisitor (com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor)8 ServiceException (com.zimbra.common.service.ServiceException)6 AccountServiceException (com.zimbra.cs.account.AccountServiceException)4 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)4 Account (com.zimbra.cs.account.Account)3 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)3 HashMap (java.util.HashMap)3 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)2 ZAttributes (com.zimbra.cs.ldap.ZAttributes)2 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 GuestAccount (com.zimbra.cs.account.GuestAccount)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)1 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)1 CacheEntryType (com.zimbra.soap.admin.type.CacheEntryType)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1