title: Spring Security Ldap authentication userDn and password from login form
body: <p>I'am trying to implement a Spring Security LDAP authentication using <strong><a href="https://github.com/spring-projects/spring-security/blob/master/config/src/main/java/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.java" rel="noreferrer">WebSecurityConfigurerAdapter</a></strong>.</p>
  
  <p>So far it works fine, but the problem in my case is that I don't want the username and password of context to be hard coded. It must be the login and password of the user, so my question is <em>how can I build the context and setting of the username and password from the login form?</em> </p>
  
  <p>This is the code I'm working with: </p>
  
  <pre><code>@Configuration
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
                  .anyRequest().fullyAuthenticated()
                  .and()
              .formLogin();
      }
  
      @Override
      public void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth
              .ldapAuthentication()
                  .userSearchFilter("(sAMAccountName={0})")
                  .contextSource(contextSource());
      }
  
      @Bean
      public BaseLdapPathContextSource contextSource() {
          LdapContextSource bean = new LdapContextSource();
          bean.setUrl("ldap://10.10.10.10:389");
          bean.setBase("DC=myDomaine,DC=com");
          //instead of this i want to put here the username and password provided by the user
          bean.setUserDn("myDomaine\\username");
          bean.setPassword("password");
          bean.setPooled(true);
          bean.setReferral("follow");
          bean.afterPropertiesSet();
          return bean;
      }
  }
  </code></pre>
  
  <p>Thank you!</p>