title: Spring Security LDAP - login problem (ProviderNotFoundException)
body: <p>I have problem with LDAP Spring Security, I'm trying to authorise against the LDAP server. I have the spring configuration xml file (security-config.xml) like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sec="http://www.springframework.org/schema/security"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.4.xsd"&gt;
  
   &lt;bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"&gt;
    &lt;constructor-arg value="ldap://111.111.111.111"/&gt;
    &lt;property name="userDn" value="cn=auth-user,ou=System,dc=foo,dc=com"/&gt;
    &lt;property name="password" value="fooPwd"/&gt;
   &lt;/bean&gt;
  
   &lt;bean id="ldapAuthProvider" class="org.springframework.security.providers.ldap.LdapAuthenticationProvider"&gt;
    &lt;constructor-arg&gt;
     &lt;bean class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator"&gt;
      &lt;constructor-arg ref="contextSource"/&gt;
      &lt;property name="userSearch"&gt;
       &lt;bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"&gt;
         &lt;constructor-arg index="0" value="ou=people"/&gt;
         &lt;constructor-arg index="1" value="(uid={0})"/&gt;
         &lt;constructor-arg index="2" ref="contextSource" /&gt;
       &lt;/bean&gt;
      &lt;/property&gt;
     &lt;/bean&gt;
    &lt;/constructor-arg&gt;
    &lt;constructor-arg&gt;
     &lt;bean class="com.company.name.services.UserAuthoritiesPopulator" /&gt;
    &lt;/constructor-arg&gt;
   &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>In the login controller (LoginController.java) I'm authorising like this:</p>
  
  <pre><code>@RequestMapping(value = "/login", method = RequestMethod.POST)
  public String loginPPost(String username, String password, Model model, HttpServletRequest req, HttpServletResponse res) throws SQLException {
  
   UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
   Authentication authentication = authenticationManager.authenticate(authRequest);
   SecurityContextHolder.getContext().setAuthentication(authentication);
   ...
  }
  </code></pre>
  
  <p>The method "authenticationManager.authenticate(authRequest)" throws this exception:</p>
  
  <pre><code>org.springframework.security.providers.ProviderNotFoundException: No AuthenticationProvider found for org.springframework.security.providers.UsernamePasswordAuthenticationToken
      at org.springframework.security.providers.ProviderManager.doAuthentication(ProviderManager.java:214)
      at org.springframework.security.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:46)
  </code></pre>
  
  <p>Does anybody know how to solve this problem? Should I use different method for authorisation? Or is my configuration bad?</p>
  
  <p>Thanks for any help,</p>
  
  <p>Mateo</p>