title: How to debug a Spring Thymelieaf page Spring security
body: <p>I'm new to Thymeleaf, but worked with JSPs before, so that should be the same principle I would have thought.</p>
  <p>Anyhow... I'm trying to put together the following Spring security tutorial <a href="https://spring.io/guides/gs/securing-web/" rel="nofollow noreferrer">https://spring.io/guides/gs/securing-web/</a>.</p>
  <p>It uses Thymeleaf for the frontend page rendering, and the following Login page does not play ball:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:th=&quot;https://www.thymeleaf.org&quot;
        xmlns:sec=&quot;https://www.thymeleaf.org/thymeleaf-extras-springsecurity4&quot;&gt;
  &lt;head&gt;
      &lt;title&gt;Spring Security Example &lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div th:if=&quot;${param.error}&quot;&gt;
      Invalid username and password.
  &lt;/div&gt;
  &lt;form th:action=&quot;@{/login.html}&quot; method=&quot;post&quot;&gt;
      &lt;div&gt;&lt;label&gt; User Name : &lt;input type=&quot;text&quot; name=&quot;username&quot;/&gt; &lt;/label&gt;&lt;/div&gt;
      &lt;div&gt;&lt;label&gt; Password: &lt;input type=&quot;password&quot; name=&quot;password&quot;/&gt; &lt;/label&gt;&lt;/div&gt;
      &lt;div&gt;&lt;input type=&quot;submit&quot; value=&quot;Sign In&quot;/&gt;&lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Then, I have the following Spring security configuration class:</p>
  <pre><code>@Configuration
  @EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .authorizeRequests()
              .antMatchers(&quot;/&quot;, &quot;/home&quot;, &quot;/greeting&quot;).permitAll()
              .anyRequest().authenticated()
              .and()
              .formLogin()
              .loginPage(&quot;/login&quot;)
              .defaultSuccessUrl(&quot;/homepage.html&quot;, true)
              .failureUrl(&quot;/login.html?error=true&quot;)
              .permitAll()
              .and()
              .logout()
              .permitAll();
  }
  
      @Bean
      @Override
      public UserDetailsService userDetailsService() {
          UserDetails user =
                  User.withDefaultPasswordEncoder()
                          .username(&quot;user&quot;)
                          .password(&quot;password&quot;)
                          .roles(&quot;USER&quot;)
                          .build();
          return new InMemoryUserDetailsManager(user);
      }
  }
  </code></pre>
  <p>The page with the form displays just fine, but when I provide the above credentials (user/password), it does not log the user in. It basically gets stuck in a loop demanding to login; there is a homepage.html, but it's never redirected to.</p>
  <p>There is nothing in the logs, no errors or any messages.</p>
  <p>Trying to debug it, I've added the following controller:</p>
  <pre><code>@Controller
  @Slf4j
  public class GreetingController {
  
      @PostMapping(&quot;/login&quot;)
      public String greeting(@RequestParam(name = &quot;username&quot;, value = &quot;xxx&quot;) String username, @RequestParam(name = &quot;password&quot;, value = &quot;yyy&quot;) String password, Model model) {
          log.info(&quot;U &quot; + username + &quot; P &quot; + password);
          model.addAttribute(&quot;username&quot;, username);
          model.addAttribute(&quot;password&quot;, password);
  
          return &quot;login&quot;;
      }
  }
  </code></pre>
  <p>but when trying to invoke <code>http://localhost:8080/login</code>, I get the following error:</p>
  <pre><code>There was an unexpected error (type=Method Not Allowed, status=405).
  Request method 'GET' not supported
  org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
  </code></pre>
  <p>So, having tried all above, I'm kinda stuck now and not sure what to try next.</p>
  <p>How do I debug such a login page to find out what's going on? Also, could anyone spot any problems with the code I've provided above so far?</p>