Search in sources :

Example 16 with LdapProv

use of com.zimbra.cs.account.ldap.LdapProv 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 17 with LdapProv

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

the class TestLdapProvRenameDomain method init.

@BeforeClass
public static void init() throws Exception {
    // ZimbraLog.toolSetupLog4j("INFO", "/Users/pshao/p4/main/ZimbraServer/conf/log4j.properties.cli");
    ZimbraLog.toolSetupLog4j("INFO", "/opt/zimbra/conf/log4j.properties");
    TEST_ID = genTestId();
    System.out.println("\nTest " + TEST_ID + "\n");
    Provisioning prov = Provisioning.getInstance();
    assertTrue(prov instanceof LdapProv);
    ldapProv = (LdapProv) prov;
}
Also used : Provisioning(com.zimbra.cs.account.Provisioning) LdapProvisioning(com.zimbra.cs.account.ldap.LdapProvisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv)

Example 18 with LdapProv

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

the class TestLdapProvExternalLdapAuth method externalLdapAuthBySearch.

@Test
public void externalLdapAuthBySearch() throws Exception {
    LdapProv ldapProv = (LdapProv) prov;
    String DOMAIN_NAME = Names.makeDomainName(genDomainSegmentName() + "." + baseDomainName());
    String authMech = AuthMech.ldap.name();
    Map<String, Object> domainAttrs = new HashMap<String, Object>();
    domainAttrs.put(Provisioning.A_zimbraAuthMech, authMech);
    domainAttrs.put(Provisioning.A_zimbraAuthLdapURL, getLdapURL());
    domainAttrs.put(Provisioning.A_zimbraAuthLdapStartTlsEnabled, getWantStartTLS());
    domainAttrs.put(Provisioning.A_zimbraAuthLdapSearchBindPassword, LC.zimbra_ldap_password.value());
    domainAttrs.put(Provisioning.A_zimbraAuthLdapSearchBindDn, LC.zimbra_ldap_userdn.value());
    domainAttrs.put(Provisioning.A_zimbraAuthLdapSearchFilter, "(zimbraMailDeliveryAddress=%n)");
    Domain domain = provUtil.createDomain(DOMAIN_NAME, domainAttrs);
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    Account acct = provUtil.createAccount(ACCT_NAME_LOCALPART, domain);
    prov.authAccount(acct, "test123", AuthContext.Protocol.test);
    provUtil.deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Domain(com.zimbra.cs.account.Domain) LdapProv(com.zimbra.cs.account.ldap.LdapProv) ProvTest(com.zimbra.qa.unittest.prov.ProvTest)

Example 19 with LdapProv

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

the class TestLdap method deleteAllNonDefaultCoses.

private static void deleteAllNonDefaultCoses() throws Exception {
    LdapDIT dit = ((LdapProv) Provisioning.getInstance()).getDIT();
    String cosBaseDN = dit.cosBaseDN();
    Set<String> defaultCosDN = new HashSet<String>();
    defaultCosDN.add(dit.cosNametoDN(Provisioning.DEFAULT_COS_NAME));
    defaultCosDN.add(dit.cosNametoDN(Provisioning.DEFAULT_EXTERNAL_COS_NAME));
    deleteAllChildrenUnderDN(cosBaseDN, defaultCosDN);
}
Also used : LdapDIT(com.zimbra.cs.account.ldap.LdapDIT) LdapProv(com.zimbra.cs.account.ldap.LdapProv) HashSet(java.util.HashSet)

Example 20 with LdapProv

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

the class TestObjectClass method getMostSpecificOC.

@Test
public void getMostSpecificOC() throws Exception {
    LdapProv ldapProv = (LdapProv) prov;
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "zimbraAccount", "organizationalPerson", "person" }, "inetOrgPerson"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "inetOrgPerson" }, "organizationalPerson"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "organizationalPerson", "inetOrgPerson" }, "person"));
    assertEquals("bbb", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "inetOrgPerson" }, "bbb"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "aaa" }, "inetOrgPerson"));
    assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "person", "inetOrgPerson" }, "organizationalPerson"));
}
Also used : LdapProv(com.zimbra.cs.account.ldap.LdapProv) Test(org.junit.Test)

Aggregations

LdapProv (com.zimbra.cs.account.ldap.LdapProv)38 Domain (com.zimbra.cs.account.Domain)14 Account (com.zimbra.cs.account.Account)12 HashMap (java.util.HashMap)12 DistributionList (com.zimbra.cs.account.DistributionList)8 Provisioning (com.zimbra.cs.account.Provisioning)8 ServiceException (com.zimbra.common.service.ServiceException)7 NamedEntry (com.zimbra.cs.account.NamedEntry)6 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)6 HashSet (java.util.HashSet)6 Map (java.util.Map)5 AccountServiceException (com.zimbra.cs.account.AccountServiceException)4 LdapDIT (com.zimbra.cs.account.ldap.LdapDIT)4 List (java.util.List)4 Entry (com.zimbra.cs.account.Entry)3 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)3 RightCommand (com.zimbra.cs.account.accesscontrol.RightCommand)3 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)3 GranteeBy (com.zimbra.soap.admin.type.GranteeSelector.GranteeBy)3 PublishedShareInfoVisitor (com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)2