j_spring_security_check 404 JSF登录时出错

时间:2015-05-30 16:42:14

标签: jsf authentication jsf-2 spring-security

我正在为Spring安全身份验证创建一个简单的jsf login form

<form action="#{request.contextPath}/j_spring_security_check" method="post">
    <h:outputLabel for="j_username" value="Username"/>
    <h:inputText id="j_username"/>
    <br/>
    <h:outputLabel for="j_password" value="Password"/>
    <h:inputSecret id="j_password"/>
    <br/>
    <h:commandButton value="Login"/>
</form>

这是applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       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.xsd">

    <security:http auto-config="true" use-expressions="true">
        <security:intercept-url pattern="/login.xhtml" access="hasRole('IS_AUTHENTICATED_ANONYMOUSLY')"/>
        <security:intercept-url pattern="/**" access="hasRole('ROLE_USER')"/>
        <security:form-login login-page="/login.xhtml" default-target-url="/" authentication-failure-url="/login?login_error=1"/>
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="sajjad" password="200200" authorities="ROLE_USER"/>
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager>
</beans>

web.xml

<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>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<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>
</servlet-mapping>

faces-context.xml

<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>

代码有什么问题?

2 个答案:

答案 0 :(得分:1)

login-processing-url="/j_spring_security_check"添加到<security:http>

答案 1 :(得分:0)

尝试将<dispatcher>REQUEST</dispatcher>添加到springSecurityFilterChain映射