title: Why doesn't my implementation of AuthenticationProvider with Java Config work?
body: <p>I tried to connect a custom AuthenticationProvider to the Spring Security configuration like below:</p>
  
  <pre><code>@Configuration
  @EnableWebMvcSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private CustomAuthenticationProvider customAuthenticationProvider;
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.authenticationProvider(customAuthenticationProvider);
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http.authorizeRequests().antMatchers("/", "/signup", "/resources/**", "/home").permitAll()
                  .antMatchers("/user").hasRole("USER").anyRequest().authenticated()
                  .and()
                  .formLogin().loginPage("/login").loginProcessingUrl("/login").permitAll()
                  .and().logout().permitAll();
      }
  
  }
  </code></pre>
  
  <p>Here is my CustomAuthenticationProvider class:</p>
  
  <pre><code>@Component
  public class CustomAuthenticationProvider implements AuthenticationProvider {
  
  @Autowired private UserService userService;
  
  @Override
  public Authentication authenticate(Authentication auth) throws AuthenticationException {
  
      String email = (String) auth.getPrincipal();
      String password = (String) auth.getCredentials();
  
      System.out.println("[CustomAuthenticationProvider] Authentication try [" + email +"]");
  
      User user = (User) userService.findByEmail(email);
      if (user == null) {
          throw new BadCredentialsException("[CustomAuthenticationProvider] Authentication Failed!!! Reason: User is not exist: [" + email + "]");
      }
  
      if (user.getPassword().equals(password)) {
          System.out.println("[CustomAuthenticationProvider] - Authentication Success!!!");
  
          List&lt;GrantedAuthority&gt; roles = new ArrayList&lt;GrantedAuthority&gt;();
          roles.add(new SimpleGrantedAuthority("ROLE_USER"));
  
          UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(email, password, roles);
              result.setDetails(user);
              return result;
          } else {
              throw new BadCredentialsException("[CustomAuthenticationProvider] Authentication Failed!!! Reason: Wrong password");
          }
      }
  
      @Override
      public boolean supports(Class&lt;?&gt; auth) {
          return auth.equals(UsernamePasswordAuthenticationToken.class);
      }
  }
  </code></pre>
  
  <p>I opened the browser and connected to the url: "localhost:8080/login"
  I can see the login page, and I input the id/pw.
  After I click the "login" button, I expected to find some log output for <code>CustomAuthenticationProvider</code>.  But there is no log output.  This means my <code>CustomAuthenticationProvider</code> is not working.</p>
  
  <p>I checked Google and stackoverflow, but I cannot find the resolution.</p>
  
  <p>Before this, I used XML configuration like:</p>
  
  <pre><code>&lt;security:authentication-manager&gt;
      &lt;security:authentication-provider ref="customAuthenticationProvider" /&gt;
  &lt;/security:authentication-manager&gt;
  </code></pre>
  
  <p>That code works fine, but I am trying moving the code from XML to Java Configuration.</p>
  
  <p>I am using Spring Boot ver 1.27.  Here is the relevant portion of my POM:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.hateoas&lt;/groupId&gt;
          &lt;artifactId&gt;spring-hateoas&lt;/artifactId&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>