Search in sources :

Example 6 with IAttributes

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

Example 7 with IAttributes

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

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

the class TestLdapZLdapContext method searchPaged.

@Test
public void searchPaged() throws Exception {
    int SIZE_LIMIT = 5;
    String base = LdapConstants.DN_ROOT_DSE;
    ZLdapFilter filter = ZLdapFilterFactory.getInstance().anyEntry();
    String[] returnAttrs = new String[] { "objectClass" };
    final List<String> result = new ArrayList<String>();
    SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {

        @Override
        public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
            result.add(dn);
        }
    };
    SearchLdapOptions searchOptions = new SearchLdapOptions(base, filter, returnAttrs, SIZE_LIMIT, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    boolean caughtException = false;
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapUsage.UNITTEST);
        zlc.searchPaged(searchOptions);
    } catch (LdapSizeLimitExceededException e) {
        caughtException = true;
    } finally {
        LdapClient.closeContext(zlc);
    }
    assertTrue(caughtException);
    assertEquals(SIZE_LIMIT, result.size());
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) ArrayList(java.util.ArrayList) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) IAttributes(com.zimbra.cs.ldap.IAttributes) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) Map(java.util.Map)

Example 9 with IAttributes

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

the class TestLdapProvDomain method verifyAllDomains.

private void verifyAllDomains(List<Domain> allDomains) throws Exception {
    // domains created by r-t-w
    // TODO: this verification is very fragile
    Set<String> expectedDomains = new HashSet<String>();
    String defaultDomainName = prov.getInstance().getConfig().getDefaultDomainName();
    expectedDomains.add(defaultDomainName);
    expectedDomains.add("example.com");
    assertEquals(expectedDomains.size(), allDomains.size());
    for (Domain domain : allDomains) {
        assertTrue(expectedDomains.contains(domain.getName()));
    }
    //
    // another verification
    //
    LdapHelper ldapHelper = ((LdapProv) prov).getHelper();
    final List<String> /* zimbraId */
    domainIds = new ArrayList<String>();
    SearchLdapOptions.SearchLdapVisitor visitor = new SearchLdapOptions.SearchLdapVisitor() {

        @Override
        public void visit(String dn, Map<String, Object> attrs, IAttributes ldapAttrs) {
            try {
                domainIds.add(ldapAttrs.getAttrString(Provisioning.A_zimbraId));
            } catch (ServiceException e) {
                fail();
            }
        }
    };
    SearchLdapOptions searchOpts = new SearchLdapOptions(LdapConstants.DN_ROOT_DSE, ZLdapFilterFactory.getInstance().fromFilterString(FilterId.UNITTEST, "(objectclass=zimbraDomain)"), new String[] { Provisioning.A_zimbraId }, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapUsage.UNITTEST);
        ldapHelper.searchLdap(zlc, searchOpts);
    } finally {
        LdapClient.closeContext(zlc);
    }
    assertEquals(domainIds.size(), allDomains.size());
    for (Domain domain : allDomains) {
        assertTrue(domainIds.contains(domain.getId()));
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) LdapHelper(com.zimbra.cs.account.ldap.LdapHelper) ArrayList(java.util.ArrayList) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) LdapProv(com.zimbra.cs.account.ldap.LdapProv) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) IAttributes(com.zimbra.cs.ldap.IAttributes) Domain(com.zimbra.cs.account.Domain) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 10 with IAttributes

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

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