title: Spring Boot + Spring MVC + Thymeleaf custom login fails without showing any error in console
body: <p>I am trying to make a simple registration/login mechanism using Spring Boot + Thymeleaf.</p>
  
  <p>I managed to register a user successfully (checked the new entry in the h2-console)  but I have a problem while trying to log in.</p>
  
  <p>Specifically, the application is redirected to /login?error page and there is no message at the console indicating what is wrong.</p>
  
  <p>After debugging I discovered that the application does not stop at my Post controller method.</p>
  
  <p>I provide you with my code:</p>
  
  <p>login.html</p>
  
  <pre><code>&lt;form th:action="@{/login}" method="post" th:object="${user}"&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="username"&gt;Username&lt;/label&gt;
                  &lt;input th:field="*{username}" type="text" id="username" name="username" class="form-control" autofocus="autofocus"
                         placeholder="Username"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label for="password"&gt;Password&lt;/label&gt;:
                  &lt;input th:field="*{password}" type="password" id="password" name="password" class="form-control" placeholder="Password"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-sm-6 col-sm-offset-3"&gt;
                          &lt;input type="submit"
                                 name="login-submit"
                                 id="login-submit"
                                 class="form-control btn btn-success"
                                 value="Log In"&gt;
                      &lt;/div&gt;
                      &lt;div class="col-sm-6 col-sm-offset-3"&gt;
                          &lt;a th:href="@{/register}"&gt;Register&lt;/a&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>UserController.java</p>
  
  <pre><code>    @Controller
  public class UserController {
  
      @Autowired
      private UserService userService;
  
      @Autowired
      private SecurityService securityService;
  
      @GetMapping("/login")
      public String login(Model model) {
          model.addAttribute("user", new User());
          return "login";
      }
  
      @PostMapping("/login")
      public String login(@ModelAttribute("user") User user) {
          securityService.login(user.getUsername(), user.getPassword());
          return "redirect:/index";
      }
  
      @GetMapping("/register")
      public String register(Model model) {
          model.addAttribute("user", new User());
          return "register";
      }
  
      @PostMapping("/register")
      public String register(@ModelAttribute("user") User user) {
          userService.save(user);
          return "redirect:/login";
      }
  }
  </code></pre>
  
  <p>Please help, thanks in advance!</p>
  
  <p>EDIT:</p>
  
  <p>SecurityConfig.java</p>
  
  <pre><code>    @Configuration
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private UserDetailsService userDetailsService;
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
                  .authorizeRequests()
                  .antMatchers("/h2-console/**", "/register**").permitAll()
                  .anyRequest().authenticated()
                  .and()
                  .formLogin()
                  .loginPage("/login")
                  .permitAll();
  
          http.csrf().disable();
          http.headers().frameOptions().disable();
      }
  
      @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
      }
  
      @Bean("authenticationManager")
      @Override
      public AuthenticationManager authenticationManagerBean() throws Exception {
          return super.authenticationManagerBean();
      }
  
      @Bean
      public BCryptPasswordEncoder bCryptPasswordEncoder() {
          return new BCryptPasswordEncoder();
      }
  }
  </code></pre>