O login do Spring Security retorna 404
Atualmente, estou trabalhando no meu blog no framework Spring. Estou implementando o Spring Security para fins de login. Tudo funciona como esperado até eu enviar as credenciais de login, que sempre retornam o código 404.
Aqui está o meu código web.xmle
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>avispring</display-name>
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-database.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/admin/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
Aqui está o meu código de segurança da primavera:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/avispring"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>
<security:debug/>
<security:http auto-config="true">
<security:intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')"/>
<security:intercept-url pattern="/j_spring_security_check" access="permitAll"/>
<security:form-login
login-page="/login.html"
authentication-failure-url="/login?login_error=1"
default-target-url="/admin/home.html"/>
</security:http>
<security:authentication-manager>
<security:authentication-provider>
<security:jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="select USERNAME,PASSWORD,ENABLED from USER_AUTHENTICATION where USERNAME=?"
authorities-by-username-query="select u1.USERNAME,u2.ROLE from USER_AUTHENTICATION u1,USER_AUTHORIZATION u2 where u1.USER_ID=u2.USER_ID and u1.USERNAME=?"/>
</security:authentication-provider>
</security:authentication-manager>
parte do meu código login.jsp é
<form action="<c:url value="/login"/>" method="post">
<div class="form-group has-feedback">
<input type="email" class="form-control" placeholder="Email" name="username">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" name="password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
</div><!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat" name="submit">Sign In</button>
</div><!-- /.col -->
</div>
</form>
e a saída do console é
16 de outubro de 2015 01:06:03 org.springframework.web.servlet.DispatcherServlet noHandlerFound AVISO: Nenhum mapeamento encontrado para solicitação HTTP com URI [/ avispring / login] no DispatcherServlet com o nome 'spring'
Nota:
Estou usando o Spring 4.2.1 e o Spring Security 4.0.2A maioria dos fóruns está apontando para o caminho de contexto, ou seja[nome do aplicativo / login] ou[appname / j_spring_security_check] e acho que o meu está bem em relação a issoPor favor ajude...
ATUALIZAR:
quando usei log4j, a saída de depuração no momento do envio do formulário é a seguinte:
DEBUG: org.springframework.web.servlet.DispatcherServlet - Contexto da solicitação vinculada ao segmento: org.apache.catalina.connector.RequestFacade@c8b445 DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet com o nome 'spring' processando POST para [/ avispring / login] DEBUG: org.springframework.web.servlet.DispatcherServlet - Mapa do manipulador de teste [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@16fffcf] no DispatcherServlet com o nome 'spring' DE ' org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Pesquisando o método manipulador para o caminho / login DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Não encontrou o método manipulador para [/ login] DEBUG: org.springframework.web.servlet.DispatcherServlet - Mapa do manipulador de teste [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@138f01b] no DispatcherServlet com o nome 'spring' DEBUG: org.springframework.web.servlet andler.BeanNameUrlHandlerMapping - Nenhum mapeamento de manipulador encontrado para [/ login] DEBUG: org.springframework.web.servlet.DispatcherServlet - Testando o mapa do manipulador [org.springframework.web.servlet.handler.SimpleUrlHandlerMapping@1ff154c] em name ' DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Nenhum mapeamento de manipulador encontrado para [/ login] AVISO: org.springframework.web.servlet.PageNotFound - nenhum mapeamento encontrado para solicitação HTTP com URI [/ avispring / login] em DispatcherServlet com o nome 'spring' DEBUG: org.springframework.web.servlet.DispatcherServlet - Contexto de solicitação limpo de encadeamento vinculado: org.apache.catalina.connector.RequestFacade@c8b445 DEBUG: org.springframework.web.servlet.DispatcherServlet - concluído com êxito request DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Publicando um evento no WebApplicationContext para o namespace 'spring-servlet': ServletRequestHandledEvent: url = [/ avispring / login]; cliente = [0: 0: 0: 0: 0: 0: 0: 1]; método = [POST]; servlet = [mola]; sessão = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; usuário = [nulo]; tempo = [3 ms]; status = [OK] DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Publicando evento no Root WebApplicationContext: ServletRequestHandledEvent: url = [/ avispring / login]; cliente = [0: 0: 0: 0: 0: 0: 0: 1]; método = [POST]; servlet = [mola]; sessão = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; usuário = [nulo]; tempo = [3 ms]; status = [OK] DEBUG: org.springframework.web.servlet.DispatcherServlet - Contexto de solicitação vinculado ao segmento: org.apache.catalina.core.ApplicationHttpRequest@bb82df DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet com nome ' spring 'processando solicitação POST para [/avispring/404.html] DEBUG: org.springframework.web.servlet.DispatcherServlet - Mapa do manipulador de teste [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping@16fffcf] no Dispatcher com o nome 'spring' DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Procurando método de manipulador para o caminho /404.html DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMapHandlerMap - Foram encontrados 1 mapeamento (s) correspondente (s) para [/404.html]: [{[/404.html]}] DEBUG: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Método de manipulador de retorno [public org .springframework.web.servlet.ModelAndView com.avispring.controll ers.HelloController.errorPage ()] DEBUG: org.springframework.web.servlet.DispatcherServlet - Adaptador de manipulador de teste [org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter@511db5] DEBUG: org.springervletSlet Adaptador do manipulador de teste [org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter@1a86ee] DEBUG: org.springframework.web.servlet.DispatcherServlet - Adaptador do manipulador de teste [org.springframework.web.servlet.mvc.method.ternotap.Helpler.com c26a5f] DEBUG: org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod - Invocando o método [HelloController.errorPage] com argumentos [] DEBUG: org.springframework.web.servlet.mvc.method.annotation.ServletInvocable [errorPage] retornou [ModelAndView: referência para visualizar com o nome '/ 404'; o modelo é nulo] DEBUG: org.springframework.web.servlet.DispatcherServlet - exibição Rendering [org.springframework.web.servlet.view.JstlView: name '/ 404'; URL [/WEB-INF/jsp//404.jsp]] em DispatcherServlet com o nome 'spring' DEBUG: org.springframework.web.servlet.view.JstlView - exibição de renderização com o nome '/ 404' com o modelo {} e estático atributos {} DEBUG: org.springframework.web.servlet.view.JstlView - Encaminhando para o recurso [/WEB-INF/jsp//404.jsp] no InternalResourceView '/ 404' DEBUG: org.springframework.web.servlet.DispatcherServlet - Contexto de solicitação limpo e encadeado: org.apache.catalina.core.ApplicationHttpRequest@bb82df DEBUG: org.springframework.web.servlet.DispatcherServlet - Solicitação concluída com êxito DEBUG: org.springframework.web.context.support.XmlWebApplicationContext em WebApplicationContext para o namespace 'spring-servlet': ServletRequestHandledEvent: url = [/ avispring / 404.html]; cliente = [0: 0: 0: 0: 0: 0: 0: 1]; método = [POST]; servlet = [mola]; sessão = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; usuário = [nulo]; tempo = [1 ms]; status = [OK] DEBUG: org.springframework.web.context.support.XmlWebApplicationContext - Publicando evento no Root WebApplicationContext: ServletRequestHandledEvent: url = [/ avispring / 404.html]; cliente = [0: 0: 0: 0: 0: 0: 0: 1]; método = [POST]; servlet = [mola]; sessão = [BC0FB7E62DC0AFABD8EF72B8BF1CED54]; usuário = [nulo]; tempo = [1 ms]; status = [OK]