j_security_check不可用

时间:2011-11-23 20:24:54

标签: java forms security spring login

我正在使用spring 3.0,我试图让我的登录页面正常工作,但是我收到了这个错误

The requested resource (/myapp/j_spring_security_check) is not available.

我发布了与安全性有关的所有文件的内容。希望它就够了。如果需要,我可以展示更多。

这是我的web.xml

    <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

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

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

<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>*.html</url-pattern>
</filter-mapping>

我的登录页面:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>Login Page</title>
<style>
.errorblock {
color: #ff0000;
background-color: #ffEEEE;
border: 3px solid #ff0000;
padding: 8px;
margin: 16px;
}
</style>
</head>
<body onload='document.f.j_username.focus();'>
<h3>Login with Username and Password (Custom Page)</h3>

<c:if test="${not empty error}">
    <div class="errorblock">
        Your login attempt was not successful, try again.<br /> Caused :
        ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
    </div>
</c:if>

<form name='f' action="<c:url value='j_spring_security_check' />"
    method='POST'>

    <table>
        <tr>
            <td>User:</td>
            <td><input type='text' name='j_username' value=''>
            </td>
        </tr>
        <tr>
            <td>Password:</td>
            <td><input type='password' name='j_password' />
            </td>
        </tr>
        <tr>
            <td colspan='2'><input name="submit" type="submit"
                value="submit" />
            </td>
        </tr>
        <tr>
            <td colspan='2'><input name="reset" type="reset" />
            </td>
        </tr>
    </table>

</form>

和我的安全上下文

<beans:bean id="passwordEncoder"
    class="org.springframework.security.authentication.encoding.ShaPasswordEncoder">
    <beans:constructor-arg value="256" />
</beans:bean>

<beans:bean id="saltSource"
    class="org.springframework.security.authentication.dao.ReflectionSaltSource">
    <beans:property name="userPropertyToUse" value="id" />
</beans:bean>

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="authProvider" />
</authentication-manager>

<beans:bean id="authProvider"
    class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
    <beans:property name="userDetailsService" ref="personService" />
    <beans:property name="passwordEncoder" ref="passwordEncoder" />
    <beans:property name="saltSource" ref="saltSource" />
    <beans:property name="includeDetailsObject" value="true" />
</beans:bean>

<beans:bean id="authenticationProcessingFilterEntryPoint"
    class="org.springframework.security.web.authentication.AuthenticationProcessingFilterEntryPoint">
    <beans:property name="forceHttps" value="false" />
    <beans:property name="loginFormUrl" value="/login.html" />
</beans:bean>
<http entry-point-ref="authenticationProcessingFilterEntryPoint" auto-config="true">
        <intercept-url pattern="/**" access="ROLE_USER" />
        <intercept-url pattern="/login.html" filters="none" />
        <form-login login-page="/login.html" default-target-url="/welcome.html"
            authentication-failure-url="/loginfailed.html" />
        <logout logout-success-url="/logout" />
    </http>

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

.html绝对需要设置过滤器的方式。正确的方法是将web.xml中的url-pattern声明为/*.

如果要将url-pattern保留为* .html,可能需要考虑将login-processing-url属性添加到form-login元素,以便有人确实返回并修改web.xml由于这个怪癖,一切都不会崩溃。

<form-login login-page="/login.html" default-target-url="/welcome.html"
        authentication-failure-url="/loginfailed.html" login-processing-url="j_spring_security_check.html"/>