anchor.diff:  == LDAP ContextSource
   
   Once you have an LDAP Server to which to point your configuration, you need to configure Spring Security to point to an LDAP server that should be used to authenticate users.
  -To do so, create an LDAP `ContextSource` (which is the equivalent of a JDBC `DataSource`):
  +To do so, create an LDAP `ContextSource` (which is the equivalent of a JDBC `DataSource`).
  +If you have already configured an `EmbeddedLdapServerContextSourceFactoryBean`, Spring Security will create an LDAP `ContextSource` that points to the embedded LDAP server.
  +
  +.LDAP Context Source with Embedded LDAP Server
  +====
  +.Java
  +[source,java,role="primary"]
  +----
  +@Bean
  +public EmbeddedLdapServerContextSourceFactoryBean contextSourceFactoryBean() {
  +	EmbeddedLdapServerContextSourceFactoryBean contextSourceFactoryBean =
  +			EmbeddedLdapServerContextSourceFactoryBean.fromEmbeddedLdapServer();
  +	contextSourceFactoryBean.setPort(0);
  +	return contextSourceFactoryBean;
  +}
  +----
  +
  +.Kotlin
  +[source,kotlin,role="secondary"]
  +----
  +@Bean
  +fun contextSourceFactoryBean(): EmbeddedLdapServerContextSourceFactoryBean {
  +    val contextSourceFactoryBean = EmbeddedLdapServerContextSourceFactoryBean.fromEmbeddedLdapServer()
  +    contextSourceFactoryBean.setPort(0)
  +    return contextSourceFactoryBean
  +}
  +----
  +====
  +
  +Alternatively, you can explicitly configure the LDAP `ContextSource` to connect to the supplied LDAP server:
   
   .LDAP Context Source
   ====
  
positive.code: [source,java,role="primary"]
  ----
  @Bean
  PasswordComparisonAuthenticator authenticator(BaseLdapPathContextSource contextSource) {
  	return new PasswordComparisonAuthenticator(contextSource);
  }
  
  @Bean
  LdapAuthenticationProvider authenticationProvider(LdapAuthenticator authenticator) {
  	return new LdapAuthenticationProvider(authenticator);
  }
  ----
  
  
negative.code: [source,kotlin,role="secondary",attrs="-attributes"]
  ----
  @Bean
  fun authenticationManager(contextSource: BaseLdapPathContextSource): AuthenticationManager {
      val factory = LdapBindAuthenticationManagerFactory(contextSource)
      factory.setUserSearchFilter("(uid={0})")
      factory.setUserSearchBase("ou=people")
      return factory.createAuthenticationManager()
  }
  ----
  ====
  