2011-11-23 62 views
1

我使用彈簧3.0和IM試圖讓我的登錄頁面的工作,但我得到這個錯誤j_security_check不可

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

已解決! 在我的jsp我不得不加名 「.html」 和重定向開始工作 \t <形式名稱= 'F' 行動= 「」 \t \t method ='POST'> –

+0

我相信你不得不添加.html的原因是因爲你將你的spring安全過濾器鏈映射到* .html。這也意味着春季安全通常只適用於* .html請求而不是所有請求。如果這是你的意圖,很好,如果不是,你可能想看看你的springSecurityFilterChain的url-pattern – digitaljoel

回答

1

.html肯定需要做的過濾器設置的方式。正確的方法是將web.xml中的url-pattern聲明爲/ *。

如果要將url-pattern保留爲* .html,可能需要考慮將login-processing-url屬性添加到form-login元素,以便在某人確實返回並修改網頁時使用。 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"/>