diff --git a/test/integration-tests-openldap/src/main/java/org/springframework/ldap/DigestMd5ContextSourceEc2InstanceLaunchingFactoryBean.java b/test/integration-tests-openldap/src/main/java/org/springframework/ldap/DigestMd5ContextSourceEc2InstanceLaunchingFactoryBean.java new file mode 100644 index 00000000..eb50c2b7 --- /dev/null +++ b/test/integration-tests-openldap/src/main/java/org/springframework/ldap/DigestMd5ContextSourceEc2InstanceLaunchingFactoryBean.java @@ -0,0 +1,43 @@ +/* + * Copyright 2005-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.ldap; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLSession; + +import org.springframework.ldap.core.support.DefaultTlsDirContextAuthenticationStrategy; +import org.springframework.ldap.core.support.DigestMd5DirContextAuthenticationStrategy; +import org.springframework.ldap.core.support.LdapContextSource; +import org.springframework.ldap.test.ContextSourceEc2InstanceLaunchingFactoryBean; + +/** + * FactoryBean for testing LDAP TLS connections on an Amazon EC2 image launched by superclass. + */ +public class DigestMd5ContextSourceEc2InstanceLaunchingFactoryBean extends ContextSourceEc2InstanceLaunchingFactoryBean { + + protected void setAdditionalContextSourceProperties(LdapContextSource ctx, final String dnsName) { + DigestMd5DirContextAuthenticationStrategy authenticationStrategy = new DigestMd5DirContextAuthenticationStrategy(); + +// authenticationStrategy.setHostnameVerifier(new HostnameVerifier() { +// public boolean verify(String hostname, SSLSession session) { +// return hostname.equals(dnsName); +// } +// }); + + ctx.setAuthenticationStrategy(authenticationStrategy); + ctx.setPooled(false); + } +} diff --git a/test/integration-tests-openldap/src/test/java/org/springframework/ldap/core/support/DigestMd5AuthenticationITest.java b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/core/support/DigestMd5AuthenticationITest.java new file mode 100644 index 00000000..b79ebf25 --- /dev/null +++ b/test/integration-tests-openldap/src/test/java/org/springframework/ldap/core/support/DigestMd5AuthenticationITest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2010 The JA-SIG Collaborative. All rights reserved. See license + * distributed with this file and available online at + * http://www.ja-sig.org/products/cas/overview/license/index.html + */ +package org.springframework.ldap.core.support; + +import javax.naming.directory.DirContext; + +import org.junit.Assert; +import org.junit.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.NamingException; +import org.springframework.ldap.core.LdapTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; + +/** + * Integration test to verify DIGEST-MD5 authentication support. + * + * @author Marvin S. Addison + * @version $Revision$ + * + */ +@ContextConfiguration(locations = { "/conf/ldapTemplateDigestMd5TestContext.xml" }) +public class DigestMd5AuthenticationITest extends AbstractJUnit4SpringContextTests { + @Autowired + private LdapTemplate ldapTemplate; + + + @Test + public void testAuthenticate() { + try { + DirContext ctxt = ldapTemplate.getContextSource().getContext("admin", "secret"); + Assert.assertNotNull(ctxt); + } catch (NamingException e) { + Assert.fail("DIGEST-MD5 authentication failed: " + e); + } + + } +} diff --git a/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateDigestMd5TestContext.xml b/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateDigestMd5TestContext.xml new file mode 100644 index 00000000..596864fd --- /dev/null +++ b/test/integration-tests-openldap/src/test/resources/conf/ldapTemplateDigestMd5TestContext.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + +