Search in sources :

Example 1 with SearchLdapVisitor

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

the class AutoProvision method searchAutoProvDirectory.

/*
     * entries are returned in DirectoryEntryVisitor interface.
     */
static void searchAutoProvDirectory(LdapProv prov, Domain domain, String filter, String name, String createTimestampLaterThan, String[] returnAttrs, int maxResults, final DirectoryEntryVisitor visitor) throws ServiceException {
    SearchLdapVisitor ldapVisitor = new SearchLdapVisitor() {

        @Override
        public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) throws StopIteratingException {
            visitor.visit(dn, attrs);
        }
    };
    searchAutoProvDirectory(prov, domain, filter, name, createTimestampLaterThan, returnAttrs, maxResults, ldapVisitor, false);
}
Also used : SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) IAttributes(com.zimbra.cs.ldap.IAttributes) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with SearchLdapVisitor

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

the class AutoProvisionEager method searchAccounts.

private boolean searchAccounts(final List<ExternalEntry> entries, int batchSize) throws ServiceException {
    String lastPolledAt = domain.getAutoProvLastPolledTimestampAsString();
    String[] returnAttrs = getAttrsToFetch();
    SearchLdapVisitor visitor = new SearchLdapVisitor(false) {

        @Override
        public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
            entries.add(new ExternalEntry(dn, (ZAttributes) ldapAttrs));
        }
    };
    boolean hitSizeLimitExceededException = AutoProvision.searchAutoProvDirectory(prov, domain, null, null, lastPolledAt, returnAttrs, batchSize, visitor, true);
    ZimbraLog.autoprov.debug("searched external LDAP source, hit size limit ? %s", hitSizeLimitExceededException);
    return hitSizeLimitExceededException;
}
Also used : SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) IAttributes(com.zimbra.cs.ldap.IAttributes) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Example 3 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 4 with SearchLdapVisitor

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

the class LdapProvisioning method deleteMemberOfOnAccounts.

// TODO: change to ldif and do in background
private void deleteMemberOfOnAccounts(ZLdapContext zlc, String dynGroupId) throws ServiceException {
    final List<Account> accts = new ArrayList<Account>();
    SearchLdapVisitor visitor = new SearchLdapVisitor(false) {

        @Override
        public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
            Account acct;
            try {
                acct = makeAccountNoDefaults(dn, (ZAttributes) ldapAttrs);
                accts.add(acct);
            } catch (ServiceException e) {
                ZimbraLog.account.warn("unable to make account " + dn, e);
            }
        }
    };
    searchDynamicGroupInternalMembers(zlc, dynGroupId, visitor);
    // do in background?
    for (Account acct : accts) {
        Map<String, Object> attrs = new HashMap<String, Object>();
        attrs.put("-" + Provisioning.A_zimbraMemberOf, dynGroupId);
        modifyLdapAttrs(acct, zlc, attrs);
        // remove the account from cache
        // note: cannnot just removeFromCache(acct) because acct only
        // contains the name, so id/alias/foreignPrincipal cached in NamedCache
        // won't be cleared.
        Account cached = getFromCache(AccountBy.name, acct.getName());
        if (cached != null) {
            removeFromCache(cached);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) GuestAccount(com.zimbra.cs.account.GuestAccount) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) 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) HashMap(java.util.HashMap) IAttributes(com.zimbra.cs.ldap.IAttributes) ZAttributes(com.zimbra.cs.ldap.ZAttributes) ArrayList(java.util.ArrayList)

Example 5 with SearchLdapVisitor

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

the class LdapProvisioning method searchDynamicGroupInternalMemberDeliveryAddresses.

private void searchDynamicGroupInternalMemberDeliveryAddresses(ZLdapContext initZlc, String dynGroupId, final Collection<String> result) {
    SearchLdapVisitor visitor = new SearchLdapVisitor(false) {

        @Override
        public void visit(String dn, IAttributes ldapAttrs) throws StopIteratingException {
            String addr = null;
            try {
                addr = ldapAttrs.getAttrString(Provisioning.A_zimbraMailDeliveryAddress);
            } catch (ServiceException e) {
                ZimbraLog.account.warn("unable to get attr", e);
            }
            if (addr != null) {
                result.add(addr);
            }
        }
    };
    ZLdapContext zlc = initZlc;
    try {
        if (zlc == null) {
            // always use master to search for dynamic group members
            zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.SEARCH);
        }
        searchDynamicGroupInternalMembers(zlc, dynGroupId, visitor);
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to search dynamic group members", e);
    } finally {
        if (initZlc == null) {
            LdapClient.closeContext(zlc);
        }
    }
}
Also used : 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)

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