title: Custom login + Spring Security + Tiles + Request method 'POST' not supported
body: <p>I am trying access URLs <em>(e.g. /user/subscriptions)</em> secured with Spring(v.4.1.0) Security(v.3.2.5) and I am getting the following error , after submitting username/password and csrf token:</p>
  
  <blockquote>
    <p>HTTP ERROR 405  Problem accessing /j_spring_security_check. Reason:
          Request method 'POST' not supported</p>
  </blockquote>
  
  <p>I have the following configurations.
  web.xml</p>
  
  <pre><code>&lt;!--Hook into spring security--&gt;
  &lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
    &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
    &lt;url-pattern&gt;/rest_services/*&lt;/url-pattern&gt;
    &lt;url-pattern&gt;/users/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;   
  </code></pre>
  
  <p>Spring security context:</p>
  
  <pre><code>&lt;security:http  auto-config="false" authentication-manager-ref="jdbcAuthenticationManager"&gt;
      &lt;security:intercept-url pattern="/users/**/*" access="ROLE_USER"/&gt;
      &lt;security:intercept-url pattern="/login/custom_login" access="ROLE_ANONYMOUS"/&gt;
      &lt;security:form-login
          login-page="/login/custom_login"
          username-parameter="username"
          password-parameter="password" /&gt;
      &lt;security:logout logout-success-url="/custom_login?logout" /&gt;
      &lt;!-- enable csrf protection --&gt;
      &lt;csrf/&gt;
  &lt;/security:http&gt;
  </code></pre>
  
  <p>CustomLoginController:</p>
  
  <pre><code>@Controller
  @RequestMapping("/login")
  public class CustomLoginController {
  
      protected static Logger LOG = Logger.getLogger(CustomLoginController.class);
  
      //Spring Security see this :
      @RequestMapping(value = "custom_login", method = RequestMethod.GET)
      public String login(
              @RequestParam(value = "error", required = false) String error,
              @RequestParam(value = "logout", required = false) String logout) {
  
          ModelAndView model = new ModelAndView();
          if (error != null) {
              model.addObject("error", "Invalid username and password!");
          }
  
          if (logout != null) {
              model.addObject("msg", "You've been logged out successfully.");
          }
  
          return "login_def";
      }
  }
  </code></pre>
  
  <p>Tiles definition</p>
  
  <pre><code>&lt;definition name="login_def" extends="defaultTemplate_m"&gt;
      &lt;put-attribute name="title" value="Podcastpedia"/&gt;
      &lt;put-attribute name="page_description" value="Podcastpedia.org, knowledge to go"/&gt;
      &lt;put-attribute name="body-id" value="latest-episodes-podcast-subscriptions" /&gt;   
      &lt;put-attribute name="content" value="/WEB-INF/jsp/user/login.jsp"/&gt;                 
  &lt;/definition&gt;   
  </code></pre>
  
  <p>login.jsp</p>
  
  <pre><code>&lt;form name='loginForm'
      action="&lt;c:url value='/j_spring_security_check' /&gt;" method='POST'&gt;
  
      &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;User:&lt;/td&gt;
          &lt;td&gt;&lt;input type='text' name='username' value=''&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Password:&lt;/td&gt;
          &lt;td&gt;&lt;input type='password' name='password' /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
              &lt;td colspan='2'&gt;
                             &lt;input name="submit" type="submit" value="submit" /&gt;
                             &lt;/td&gt;
      &lt;/tr&gt;
     &lt;/table&gt;
  
     &lt;input type="hidden" 
                  name="${_csrf.parameterName}" value="${_csrf.token}" /&gt; 
  &lt;/form&gt;
  </code></pre>
  
  <p>Tiles-context configuration </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:p="http://www.springframework.org/schema/p" 
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd"&gt;
  
  
      &lt;!-- Views mapped in views.properties (PDF, XLS classes, and others) --&gt; 
      &lt;bean id="contentNegotiatingResolver"
                class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
          &lt;property name="order"
                    value="#{T(org.springframework.core.Ordered).HIGHEST_PRECEDENCE}" /&gt;
           &lt;property name="favorPathExtension" value="true"/&gt;
          &lt;property name="contentNegotiationManager"&gt;
              &lt;bean class="org.springframework.web.accept.ContentNegotiationManager"&gt;
                  &lt;constructor-arg&gt;
                      &lt;bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy"&gt;
                          &lt;constructor-arg&gt;
                              &lt;map&gt;
                                &lt;entry key="html" value="text/html"/&gt;
                                &lt;entry key="pdf" value="application/pdf"/&gt;
                                &lt;entry key="xsl" value="application/vnd.ms-excel"/&gt;
                                &lt;entry key="xml" value="application/xml"/&gt;
                                &lt;entry key="json" value="application/json"/&gt;
                                &lt;entry key="atom" value="application/xml"/&gt;
                              &lt;/map&gt;
                          &lt;/constructor-arg&gt;
                      &lt;/bean&gt;
                  &lt;/constructor-arg&gt;
              &lt;/bean&gt;
          &lt;/property&gt;         
       &lt;/bean&gt;
  
     &lt;bean id="tilesViewResolver"
       class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
          &lt;property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" /&gt;
          &lt;property name="order" value="#{contentNegotiatingResolver.order+1}" /&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver"&gt;
        &lt;property name="basename" value="views"/&gt;
        &lt;property name="order" value="#{tilesViewResolver.order+1}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"&gt; 
          &lt;property name="definitions"&gt;       
              &lt;list&gt;
                  &lt;value&gt;/WEB-INF/tile-defs/templates.xml&lt;/value&gt;
                  &lt;value&gt;/WEB-INF/tile-defs/definitions.xml&lt;/value&gt;
              &lt;/list&gt;     
          &lt;/property&gt; 
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Same configuration in project without Tiles works without any problem. Can you advise me on what I could be doing wrong... The attempt is available at <a href="https://github.com/podcastpedia/podcastpedia-web/tree/spring-security-custom-login" rel="nofollow noreferrer">https://github.com/podcastpedia/podcastpedia-web/tree/spring-security-custom-login</a> </p>
  
  <p>Question is pretty much similar to the one here <a href="https://stackoverflow.com/questions/27532177/http-status-405-request-method-post-not-supported-occurs-when-try-to-submit">HTTP Status 405 - Request method &#39;POST&#39; not supported occurs when try to submit spring security&#39;s custom login form</a>, but there are no answers yet... </p>