diff --git a/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml b/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml index 563c1c85..ee3344e0 100644 --- a/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapContextSourceTestContext.xml @@ -4,7 +4,7 @@ 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"> - + diff --git a/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml b/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml index 0d49b793..c8e57f25 100644 --- a/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapTemplateAcegiTestContext.xml @@ -12,15 +12,15 @@ + class="org.springframework.ldap.core.support.LdapContextSource"> + class="org.springframework.ldap.authentication.AcegiAuthenticationSource" /> + value="org.springframework.ldap.core.DefaultDirObjectFactory" /> diff --git a/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml b/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml index 50ba6af0..20450325 100644 --- a/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapTemplateNoBaseSuffixTestContext.xml @@ -10,11 +10,11 @@ - + - + diff --git a/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml b/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml index b6c80c68..99728b26 100644 --- a/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml +++ b/spring-ldap/src/itest/java/conf/ldapTemplateTestContext.xml @@ -10,12 +10,12 @@ - + - + diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/AttributeCheckContextMapper.java b/spring-ldap/src/itest/java/org/springframework/ldap/AttributeCheckContextMapper.java index 6c1f0752..9318fe89 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/AttributeCheckContextMapper.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/AttributeCheckContextMapper.java @@ -18,7 +18,7 @@ package org.springframework.ldap; import junit.framework.Assert; import org.springframework.ldap.core.ContextMapper; -import org.springframework.ldap.support.DirContextAdapter; +import org.springframework.ldap.core.DirContextAdapter; /** * Dummy ContextMapper for testing purposes to check that the received diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java index 07b70d2c..3a04e9b2 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapServerManager.java @@ -34,8 +34,8 @@ import org.apache.directory.server.protocol.shared.store.LdifFileLoader; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.ldap.core.ContextSource; -import org.springframework.ldap.support.DefaultDirObjectFactory; -import org.springframework.ldap.support.DistinguishedName; +import org.springframework.ldap.core.DefaultDirObjectFactory; +import org.springframework.ldap.core.DistinguishedName; /** * Utility class to initialize the apache directory server for use in the diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java index dfc427df..4a9085cf 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateBindUnbindITest.java @@ -21,9 +21,9 @@ import javax.naming.directory.BasicAttribute; import javax.naming.directory.BasicAttributes; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DirContextAdapter; -import org.springframework.ldap.support.DistinguishedName; import org.springframework.ldap.support.EntryNotFoundException; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java index 161fb7f7..be0689d7 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextExecutorTest.java @@ -19,8 +19,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; import org.springframework.ldap.core.ContextExecutor; +import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DirContextAdapter; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; /** diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java index cd38df57..c6488ef8 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateContextMapperITest.java @@ -19,8 +19,8 @@ package org.springframework.ldap; import java.util.List; import org.springframework.ldap.core.ContextMapper; +import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DirContextAdapter; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; /** @@ -38,7 +38,7 @@ public class LdapTemplateContextMapperITest extends } /** - * This method depends on a DirObjectFactory ({@link org.springframework.ldap.support.DefaultDirObjectFactory}) + * This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.DefaultDirObjectFactory}) * being set in the ContextSource. */ public void testSearch_ContextMapper() { diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java index 3180e4d9..2a0bcbdf 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateListITest.java @@ -17,9 +17,9 @@ package org.springframework.ldap; import java.util.List; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.CountNameClassPairCallbackHandler; -import org.springframework.ldap.support.DistinguishedName; +import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; /** diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java index 589c72b9..eebb5e93 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateLookupITest.java @@ -21,9 +21,9 @@ import javax.naming.directory.Attributes; import org.springframework.ldap.core.AttributesMapper; import org.springframework.ldap.core.ContextMapper; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DirContextAdapter; -import org.springframework.ldap.support.DistinguishedName; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; /** @@ -42,7 +42,7 @@ public class LdapTemplateLookupITest extends } /** - * This method depends on a DirObjectFactory ({@link org.springframework.ldap.support.DefaultDirObjectFactory}) + * This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.DefaultDirObjectFactory}) * being set in the ContextSource. */ public void testLookup_Plain() { @@ -134,7 +134,7 @@ public class LdapTemplateLookupITest extends } /** - * This method depends on a DirObjectFactory ({@link org.springframework.ldap.support.DefaultDirObjectFactory}) + * This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.DefaultDirObjectFactory}) * being set in the ContextSource. */ public void testLookup_ContextMapper() { diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java index 04ca3e8d..1cf9baab 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateModifyITest.java @@ -25,9 +25,9 @@ import javax.naming.directory.ModificationItem; import org.springframework.dao.DataAccessException; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DirContextAdapter; -import org.springframework.ldap.support.DistinguishedName; import org.springframework.ldap.support.UncategorizedLdapException; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java index cbe90d21..a5ec46d0 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateNoBaseSuffixITest.java @@ -16,9 +16,9 @@ package org.springframework.ldap; +import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.CountNameClassPairCallbackHandler; -import org.springframework.ldap.support.DirContextAdapter; +import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler; import org.springframework.ldap.support.EntryNotFoundException; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; @@ -39,7 +39,7 @@ public class LdapTemplateNoBaseSuffixITest extends } /** - * This method depends on a DirObjectFactory ({@link org.springframework.ldap.support.DefaultDirObjectFactory}) + * This method depends on a DirObjectFactory ({@link org.springframework.ldap.core.DefaultDirObjectFactory}) * being set in the ContextSource. */ public void testLookup_Plain() { diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java index 970d14eb..79e1df3a 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRecursiveDeleteITest.java @@ -18,9 +18,9 @@ package org.springframework.ldap; import javax.naming.Name; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DirContextAdapter; -import org.springframework.ldap.support.DistinguishedName; import org.springframework.ldap.support.EntryNotFoundException; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java index 4655620d..7a9a9562 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateRenameITest.java @@ -19,9 +19,9 @@ package org.springframework.ldap; import javax.naming.Name; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DirContextAdapter; -import org.springframework.ldap.support.DistinguishedName; import org.springframework.ldap.support.EntryNotFoundException; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java index 2242646b..2fe55d31 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchCountITest.java @@ -17,9 +17,9 @@ package org.springframework.ldap; import org.ddsteps.spring.DDStepsSpringTestCase; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.CountNameClassPairCallbackHandler; -import org.springframework.ldap.support.DistinguishedName; +import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler; /** * Tests for LdapTemplate's search methods. This test class tests the generic diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java index 3e5898a8..7e045af1 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/LdapTemplateSearchResultITest.java @@ -20,8 +20,8 @@ import java.util.List; import javax.naming.Name; import javax.naming.directory.SearchControls; +import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.support.DistinguishedName; import org.springframework.test.AbstractDependencyInjectionSpringContextTests; /** diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java b/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java index 7ecefdc8..cecad889 100644 --- a/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java +++ b/spring-ldap/src/itest/java/org/springframework/ldap/PersonContextMapper.java @@ -17,7 +17,7 @@ package org.springframework.ldap; import org.springframework.ldap.core.ContextMapper; -import org.springframework.ldap.support.DirContextAdapter; +import org.springframework.ldap.core.DirContextAdapter; /** * Dummy implemention of ContextMapper for use in the integration tests and for diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/authentication/AcegiAuthenticationSourceITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/authentication/AcegiAuthenticationSourceITest.java new file mode 100644 index 00000000..3f543de4 --- /dev/null +++ b/spring-ldap/src/itest/java/org/springframework/ldap/authentication/AcegiAuthenticationSourceITest.java @@ -0,0 +1,81 @@ +/* + * Copyright 2002-2005 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.authentication; + +import java.util.List; + +import javax.naming.NamingException; +import javax.naming.directory.Attributes; + + +import org.acegisecurity.Authentication; +import org.acegisecurity.context.SecurityContextHolder; +import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; +import org.acegisecurity.providers.ldap.LdapAuthenticationProvider; +import org.springframework.ldap.authentication.AcegiAuthenticationSource; +import org.springframework.ldap.core.AttributesMapper; +import org.springframework.ldap.core.LdapTemplate; +import org.springframework.test.AbstractDependencyInjectionSpringContextTests; + +public class AcegiAuthenticationSourceITest extends + AbstractDependencyInjectionSpringContextTests { + + private LdapAuthenticationProvider ldapAuthProvider; + + private LdapTemplate ldapTemplate; + + protected String[] getConfigLocations() { + return new String[] { "/conf/ldapTemplateAcegiTestContext.xml" }; + } + + public void setLdapAuthProvider(LdapAuthenticationProvider ldapAuthProvider) { + this.ldapAuthProvider = ldapAuthProvider; + } + + public void setLdapTemplate(LdapTemplate ldapTemplate) { + this.ldapTemplate = ldapTemplate; + } + + public void testGetPrincipalAndCredentials() { + Authentication authentication = ldapAuthProvider + .authenticate(new UsernamePasswordAuthenticationToken( + "Some Person3", "password")); + SecurityContextHolder.getContext().setAuthentication(authentication); + + AcegiAuthenticationSource tested = new AcegiAuthenticationSource(); + assertEquals("cn=Some Person3,ou=company1,c=Sweden,dc=jayway,dc=se", + tested.getPrincipal()); + assertEquals("password", tested.getCredentials()); + } + + public void testSearchIndiviualAuthentication() { + Authentication authentication = ldapAuthProvider + .authenticate(new UsernamePasswordAuthenticationToken( + "Some Person3", "password")); + SecurityContextHolder.getContext().setAuthentication(authentication); + + List result = ldapTemplate.search("dc=jayway,dc=se", + "(objectclass=person)", new AttributesMapper() { + public Object mapFromAttributes(Attributes attributes) + throws NamingException { + return attributes.get("cn"); + } + }); + assertEquals(5, result.size()); + } + +} diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/core/DnParsePerformanceITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/core/DnParsePerformanceITest.java new file mode 100644 index 00000000..c66468e2 --- /dev/null +++ b/spring-ldap/src/itest/java/org/springframework/ldap/core/DnParsePerformanceITest.java @@ -0,0 +1,75 @@ +/* + * Copyright 2002-2005 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.core; + +import org.springframework.ldap.core.DistinguishedName; + +import junit.framework.Test; +import junit.framework.TestCase; + +import com.clarkware.junitperf.LoadTest; + +/** + * Performance test for the {@link DistinguishedName} class. + * + * @author Ulrik Sandberg + */ +public class DnParsePerformanceITest extends TestCase { + + public DnParsePerformanceITest(String name) { + super(name); + } + + /** + * Tests parsing and toString. + */ + public void testContains() { + + DistinguishedName migpath = new DistinguishedName("OU=G,OU=I,OU=M"); + DistinguishedName path1 = new DistinguishedName( + "cn=john.doe, OU=Users,OU=SE,OU=G,OU=I,OU=M"); + DistinguishedName path2 = new DistinguishedName( + "cn=john.doe, OU=Users,OU=SE,ou=G,OU=i,OU=M, ou=foo"); + DistinguishedName path3 = new DistinguishedName( + "ou=G,OU=i,OU=M, ou=foo"); + DistinguishedName path4 = new DistinguishedName("ou=G,OU=i,ou=m"); + + DistinguishedName pathE1 = new DistinguishedName( + "cn=john.doe, OU=Users,OU=SE,ou=G,OU=L,OU=M, ou=foo"); + DistinguishedName pathE2 = new DistinguishedName( + "cn=john.doe, OU=Users,OU=SE"); + + assertTrue("Contains MIG", path1.contains(migpath)); + assertTrue("Contains MIG", path2.contains(migpath)); + assertTrue("Contains MIG", path3.contains(migpath)); + assertTrue("Contains MIG", path4.contains(migpath)); + + assertFalse("Does not contain MIG", pathE1.contains(migpath)); + assertFalse("Does not contain MIG", pathE2.contains(migpath)); + } + + public static Test suite() { + int users = 2000; + Test testCase = new DnParsePerformanceITest("testContains"); + Test loadTest = new LoadTest(testCase, users); + return loadTest; + } + + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } +} \ No newline at end of file diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/core/support/LdapContextSourcelITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/core/support/LdapContextSourcelITest.java new file mode 100644 index 00000000..d0248b83 --- /dev/null +++ b/spring-ldap/src/itest/java/org/springframework/ldap/core/support/LdapContextSourcelITest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2002-2005 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.core.support; + +import java.util.Hashtable; + +import javax.naming.Context; +import javax.naming.NamingException; +import javax.naming.directory.DirContext; + +import org.springframework.ldap.core.support.LdapContextSource; +import org.springframework.test.AbstractDependencyInjectionSpringContextTests; + +/** + * Integration tests for ContextSourceImpl. + * + * @author Mattias Arthursson + */ +public class LdapContextSourcelITest extends + AbstractDependencyInjectionSpringContextTests { + + private LdapContextSource tested; + + protected String[] getConfigLocations() { + return new String[] { "/conf/ldapTemplateTestContext.xml" }; + } + + public void testGetReadOnlyContext() throws NamingException { + DirContext ctx = null; + + try { + ctx = tested.getReadOnlyContext(); + assertNotNull(ctx); + Hashtable environment = ctx.getEnvironment(); + assertTrue(environment + .containsKey(LdapContextSource.SUN_LDAP_POOLING_FLAG)); + assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL)); + assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS)); + } finally { + // Always clean up. + if (ctx != null) { + try { + ctx.close(); + } catch (Exception e) { + // Never mind this + } + } + } + } + + public void testGetReadWriteContext() throws NamingException { + DirContext ctx = null; + + try { + ctx = tested.getReadWriteContext(); + assertNotNull(ctx); + // Double check to see that we are authenticated. + Hashtable environment = ctx.getEnvironment(); + assertTrue(environment.containsKey(Context.SECURITY_PRINCIPAL)); + assertTrue(environment.containsKey(Context.SECURITY_CREDENTIALS)); + } finally { + // Always clean up. + if (ctx != null) { + try { + ctx.close(); + } catch (Exception e) { + // Never mind this + } + } + } + } + + public void setTested(LdapContextSource tested) { + this.tested = tested; + } +} diff --git a/spring-ldap/src/itest/java/org/springframework/ldap/core/support/LdapContextSourcelMultiServerITest.java b/spring-ldap/src/itest/java/org/springframework/ldap/core/support/LdapContextSourcelMultiServerITest.java new file mode 100644 index 00000000..a97c7932 --- /dev/null +++ b/spring-ldap/src/itest/java/org/springframework/ldap/core/support/LdapContextSourcelMultiServerITest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2002-2005 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.core.support; + +import javax.naming.NamingException; + +import org.springframework.test.AbstractDependencyInjectionSpringContextTests; + +/** + * Integration tests for ContextSourceImpl. + * + * @author Mattias Arthursson + */ +public class LdapContextSourcelMultiServerITest extends + AbstractDependencyInjectionSpringContextTests { + + private LdapContextSource tested; + + protected String[] getConfigLocations() { + return new String[] { "/conf/ldapContextSourceTestContext.xml" }; + } + + public void testUrls() throws NamingException { + String[] urls = tested.getUrls(); + String string = tested.assembleProviderUrlString(urls); + + assertEquals("ldap://127.0.0.1:389 ldap://127.0.0.2:389", string); + } + + public void setTested(LdapContextSource tested) { + this.tested = tested; + } +}