在JSF登录时出现404错误



我正在为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>

代码有什么问题?

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

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

相关内容

  • 没有找到相关文章

最新更新