【问题标题】:Spring security 3 with primefaces does not work : HTTP 404 .... The requested resource (/j_security_check) is not available带有primefaces的Spring security 3不起作用:HTTP 404 ....请求的资源(/j_security_check)不可用
【发布时间】:2014-03-13 14:33:51
【问题描述】:

我在使用 Spring security 3 和 primefaces 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;

        }

}

【问题讨论】:

    标签: java spring jsf jsf-2 primefaces


    【解决方案1】:

    看到这个帖子:http://mprabhat.wordpress.com/2012/07/11/spring-security-3-1-and-jsf-2-0-custom-form/ 我按照说明,能够集成 JSF2.0 和 spring security 3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 2014-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多