Preparing for tests of DigestMd5
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<property name="location" value="/conf/ldap.properties" />
|
||||
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
|
||||
</bean>
|
||||
|
||||
<bean id="contextSource" class="org.springframework.ldap.DigestMd5ContextSourceEc2InstanceLaunchingFactoryBean">
|
||||
<property name="awsKey" value="${AWS_KEY}" />
|
||||
<property name="awsSecretKey" value="${AWS_SECRET_KEY}" />
|
||||
<property name="imageName" value="${aws.ami}" />
|
||||
<property name="groupName" value="${aws.security.group}" />
|
||||
<property name="keypairName" value="${aws.keypair}" />
|
||||
<property name="base" value="dc=jayway,dc=se" />
|
||||
<property name="userDn" value="${userDn}" />
|
||||
<property name="password" value="${password}" />
|
||||
</bean>
|
||||
|
||||
<bean id="ldapTemplate"
|
||||
class="org.springframework.ldap.core.LdapTemplate">
|
||||
<constructor-arg ref="contextSource" />
|
||||
</bean>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user