|
| 1 | +package org.springframework.ldap.itest.ldap473; |
| 2 | + |
| 3 | +import javax.naming.directory.DirContext; |
| 4 | + |
| 5 | +import org.junit.Test; |
| 6 | +import org.junit.runner.RunWith; |
| 7 | + |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.context.annotation.Bean; |
| 10 | +import org.springframework.context.annotation.Configuration; |
| 11 | +import org.springframework.ldap.core.ContextSource; |
| 12 | +import org.springframework.ldap.core.support.LdapContextSource; |
| 13 | +import org.springframework.ldap.test.EmbeddedLdapServerFactoryBean; |
| 14 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 15 | + |
| 16 | +import static org.assertj.core.api.Assertions.assertThat; |
| 17 | + |
| 18 | +/** |
| 19 | + * @author Eddú Meléndez |
| 20 | + */ |
| 21 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 22 | +public class Ldap473Test { |
| 23 | + |
| 24 | + @Autowired |
| 25 | + private ContextSource contextSource; |
| 26 | + |
| 27 | + @Test |
| 28 | + public void anonymous() { |
| 29 | + DirContext readOnlyContext = contextSource.getReadOnlyContext(); |
| 30 | + assertThat(readOnlyContext).isNotNull(); |
| 31 | + } |
| 32 | + |
| 33 | + @Configuration |
| 34 | + static class ContextSourceConfig { |
| 35 | + |
| 36 | + @Bean |
| 37 | + public ContextSource contextSource() { |
| 38 | + LdapContextSource contextSource = new LdapContextSource(); |
| 39 | + contextSource.setUrl("ldap://localhost:9321"); |
| 40 | + contextSource.setUserDn(null); |
| 41 | + contextSource.setPassword(null); |
| 42 | + return contextSource; |
| 43 | + } |
| 44 | + |
| 45 | + } |
| 46 | + |
| 47 | + @Configuration |
| 48 | + static class EmbeddedLdapConfig { |
| 49 | + |
| 50 | + @Bean |
| 51 | + public EmbeddedLdapServerFactoryBean embeddedLdapServer() { |
| 52 | + EmbeddedLdapServerFactoryBean embeddedLdapServer = new EmbeddedLdapServerFactoryBean(); |
| 53 | + embeddedLdapServer.setPartitionName("example"); |
| 54 | + embeddedLdapServer.setPartitionSuffix("dc=261consulting,dc=com"); |
| 55 | + embeddedLdapServer.setPort(9321); |
| 56 | + return embeddedLdapServer; |
| 57 | + } |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments