Galera, boa noite!
Estou tentando fazer uma aplicação com Spring Security, JSF e Hibernate. Estou tendo diversas dificuldades e empaquei em uma delas: quando tento fazer meu login recebo a mensagem HTTP method POST is not supported by this URL. Procurei por aí e vi que é um problema comum, mas não consigo achar qual a causa exata no meu caso e muito menos entender como fazer funcionar. Vocês me ajudariam?
Este aqui é meu applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:b="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.1.xsd">
<http auto-config="false" >
<form-login login-page="/login.xhtml"
authentication-failure-url="/login.xhtml?error=true" />
<logout logout-success-url="/login.xhtml" />
<intercept-url pattern="/index.xhtml" access="ROLE_USER" />
</http>
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="SELECT username, password, enable FROM User WHERE username=?"
authorities-by-username-query="SELECT User_username AS username, Auth_authority AS authority FROM User_Auth WHERE User_username=?" />
</authentication-provider>
</authentication-manager>
<b:bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<b:property name="url"
value="jdbc:mysql://localhost:3306/caixaeestoque" />
<b:property name="driverClassName" value="com.mysql.jdbc.Driver" />
<b:property name="username" value="root" />
<b:property name="password" value="" />
</b:bean>
</b:beans>
Este é meu web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>caixaeestoque-web</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server'.</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</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>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
Tenho uma entidade para os usuários.
@Entity
@Table(name = "USER")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "username", length = 40)
private String username;
@Column(name = "password", length = 40)
private String password;
@Column(name = "enable", columnDefinition = "BOOLEAN")
private boolean enable;
@ManyToMany
@JoinTable(name = "USER_AUTH", joinColumns = @JoinColumn(name = "USER_Username"), inverseJoinColumns = @JoinColumn(name = "AUTH_authority"))
private List<Authority> authorities;
Esta outra entidade são para os roles:
@Entity
@Table(name = "AUTHORITY")
public class Authority implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String name;
E, por fim, esta é minha página de login.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<f:view locale="#{localeControllerMB.locale}" contentType="text/html; charset=UTF-8" encoding="UTF-8" />
<f:loadBundle basename="messages" var="msg" />
</h:head>
<h:body>
<center>
<h:outputText value="Usuário e/ ou senha inválidos!"
rendered="#{param.error}"
style="color:darkred; font-size: 14px; padding-bottom: 10px;" />
<form action="j_spring_security_check" method="post" >
<h:panelGrid columns="2" cellpadding="3" style="font-weight: bold;">
<h:outputLabel for="j_username" value="* Usuário:" />
<h:inputText id="j_username" size="15" />
<h:outputLabel for="j_password" value="* Senha:" />
<h:inputSecret id="j_password" size="15" />
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</h:panelGrid>
<h:commandButton value="Entrar" />
</form>
</center>
</h:body>
</html>
Alguma idéia?