title: Error 405 Request method 'POST' not supported Spring Security
body: <p>I am trying to implement a simple login page with Spring security. Whatever I do, I always get an error <code>Error 405 Request method 'POST' not supported</code> when submitting form input. <br><br><strong>Related files:</strong><br><br>
  SecurityConfig.java:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter
  {
      @Autowired
      public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception
      {
          auth.inMemoryAuthentication().withUser("admin").password("abc123").roles("ADMIN");
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception
      {
  
          http.authorizeRequests()
                  .antMatchers("/", "/thank-you", "/faq", "/legal", "/policy").permitAll()
                  .antMatchers("/admin/**").access("hasRole('ADMIN')")
                  .and().formLogin().loginPage("/login")
                  .usernameParameter("ssoId").passwordParameter("password")
                  .and().csrf()
                  .and().exceptionHandling().accessDeniedPage("/");
      }
  }
  </code></pre>
  
  <p>SecurityWebApplicationInitializer.java:</p>
  
  <pre><code>import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
  
  public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer
  {
  
  }
  </code></pre>
  
  <p>part of my controller:</p>
  
  <pre><code>@RequestMapping(value = "/login", method = RequestMethod.GET)
  public ModelAndView loginPage(  )
  {
      return new ModelAndView("WEB-INF/views/login");
  }
  </code></pre>
  
  <p>pom.xml:</p>
  
  <pre><code>&lt;dependency&gt;
     &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
     &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
     &lt;version&gt;4.0.4.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
      &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
      &lt;version&gt;4.0.4.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
      &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
      &lt;version&gt;4.0.4.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
      &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
      &lt;version&gt;4.2.5.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>login.jsp:</p>
  
  <pre><code>&lt;form action="/login" method="post"&gt;
  &lt;div&gt;
    &lt;label for="j_username"&gt;Username&lt;/label&gt; &lt;br&gt;
    &lt;input type="text" class="form-control" id="j_username" name="ssoId" required /&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;label for="j_password"&gt;Password&lt;/label&gt; &lt;br&gt;
      &lt;input type="password" class="form-control" id="j_password" name="password" required /&gt;
  &lt;/div&gt;
  
  &lt;input type="hidden" name="${_csrf.parameterName}"   value="${_csrf.token}" /&gt;
  
  &lt;div class="form-actions"&gt;
    &lt;input type="submit" value="Log in" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>I think the problem is with the fact that my $(_csrf.parameterName} and ${_csrf.token} are both empty when Inspecting them. If you need any additional information, I would be happy to supply it.</p>