Search in sources :

Example 1 with LdapHelper

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

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Domain (com.zimbra.cs.account.Domain)1 LdapHelper (com.zimbra.cs.account.ldap.LdapHelper)1 LdapProv (com.zimbra.cs.account.ldap.LdapProv)1 IAttributes (com.zimbra.cs.ldap.IAttributes)1 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)1 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1