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()));
}
}
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;
}
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);
}
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);
}
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"));
}
Aggregations