我在使用带有primefaces 3的Spring security 3时遇到了问题。当我部署我的项目时,我得到登录页面,但当我尝试登录时,我收到此错误
HTTP 404 .... The requested resource (/j_security_check) is not available
你可以帮帮我们吗?
这是我的application-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<global-method-security secured-annotations="enabled">
</global-method-security>
<http auto-config="true" access-denied-page="/accessDenied.jsp">
<intercept-url pattern="/login*" access="IS_AUTHENTICATED_ANONYMOUSLY" />
<intercept-url pattern="/**" access="ROLE_USER,ROLE_ADMIN" />
<form-login login-page="/login.jsf" default-target-url="/"
authentication-failure-url="/loginFail" />
<logout logout-url="/logout" logout-success-url="/" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="jack" password="jack" authorities="ROLE_USER" />
<user name="admin" password="admin" authorities="ROLE_ADMIN" />
<user name="user" password="user" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
那是login.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="EmulateIE8" />
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>Acceuil</title>
</f:facet>
</h:head>
<h:form id="loginForm" prependId="false">
<p:panelGrid columns="2">
<h:outputLabel for="j_username" value="Username:" />
<p:inputText id="j_username" required="true"
value="#{loginBean.username}">
</p:inputText>
<h:outputLabel for="j_password" value="Password:" />
<p:password id="j_password" required="true"
value="#{loginBean.password}">
</p:password>
<f:facet name="footer">
<p:commandButton type="submit" id="login" ajax="false"
actionListener="#{loginBean.doLogin()}" value="Login" />
</f:facet>
</p:panelGrid>
</h:form>
</f:view>
</html>
和我的LoginBean:
import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.*;
@ManagedBean(name="loginBean")
@RequestScoped
public class LoginBean {
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String doLogin() throws IOException, ServletException {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
.getRequestDispatcher("/j_spring_security_check");
dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
return null;
}
}
答案 0 :(得分:0)
查看此帖子:http://mprabhat.wordpress.com/2012/07/11/spring-security-3-1-and-jsf-2-0-custom-form/ 我按照说明操作并能够集成JSF2.0和spring security 3