title: Spring security - Call custom authentication provider from custom login page
body: <p>I have a custom login page (SecureLogin.jsp)</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
      &lt;title&gt;Login&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
      &lt;form action="&lt;c:url value='j_spring_security_check' /&gt;" method='POST'&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Username&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" id="userName" name="userName"/&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" id="password" name="password"/&gt;&lt;td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          &lt;input type="submit"  value="submit" action="submit"&gt;
      &lt;/form&gt;
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Spring security.xml is as follows :</p>
  
  <pre><code>&lt;http&gt;
      &lt;intercept-url pattern="/security/SecureLogin.jsp*" filters="none" /&gt;
      &lt;intercept-url pattern="/security/showCustomPage*" access="hasRole('ROLE_CUSTOM')" /&gt;
      &lt;form-login 
              login-page="/security/SecureLogin.jsp" 
              login-processing-url="/j_spring_security_check"
              authentication-success-handler-ref="customAuthenticationSuccessHandler"
              authentication-failure-url="/security/showError.jsp"  /&gt;
  &lt;/http&gt;
  
  &lt;authentication-manager&gt;
      &lt;authentication-provider  ref="customAuthenticationProvider"/&gt;
  
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p>I want to my Login call to be processed by the customAuthenticationProvider.
  But when submitting the login credentials, it is showing 
  <code>Error 404: SRVE0295E: Error reported: 404</code>
  The app Url for the above error is : </p>
  
  <pre><code>http://localhost:9081/app/security/j_spring_security_check
  </code></pre>
  
  <p>I am new to Spring and Spring security. Any help is much appreciated.
  Also if there is a better way to control login, please do suggest.</p>
  
  <p><strong>EDIT</strong> : Web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
      &lt;display-name&gt;app&lt;/display-name&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
          &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
          &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
          &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
  &lt;!-- Spring Entries Start  --&gt;
      &lt;listener&gt;
           &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath:/config/context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;classpath:/config/dispatcher-config.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
  
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/api/*&lt;/url-pattern&gt;
          &lt;url-pattern&gt;/security/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;!-- Spring Security Entries start --&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;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;1&lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;!-- Spring Security Entries end --&gt;
  
  &lt;!-- Spring Entries End --&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>context.xml </p>
  
  <pre><code>&lt;import resource="security.xml" /&gt;
  &lt;context:component-scan base-package="com.demo" /&gt;
  &lt;context:annotation-config /&gt;
  </code></pre>
  
  <p>dispatcher-config.xml</p>
  
  <pre><code>&lt;bean id="viewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
          value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
  
      &lt;context:component-scan base-package="com.demo.endpoint" /&gt;
      &lt;context:annotation-config /&gt;
  </code></pre>