我剛剛設置了Spring Security,它的工作效果很好。我可以使用自定義表單登錄和註銷。我已經連續登錄多次,沒有問題。奇怪的是,如果我嘗試使用錯誤的密碼登錄,我無法再重新登錄 - 每當我嘗試登錄後登錄到「loginFailed」頁面。有誰知道如何解決這一問題?Spring Security - 輸入無效密碼後無法登錄
這裏是我的安全-config.xml中:
<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.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.3.xsd">
<http use-expressions="true">
<intercept-url pattern="/secureA.htm" access="isAuthenticated()" />
<intercept-url pattern="/secureB.htm" access="isAuthenticated()" />
<form-login login-page="/login.htm" default-target-url="/secureA.htm"
authentication-failure-url="/loginFailed.htm"/>
<logout logout-success-url="/login" />
</http>
<authentication-manager>
<authentication-provider>
<password-encoder hash="sha">
</password-encoder>
<user-service>
<user name="user" password="pass"
authorities="ROLE_USER, ROLE_ADMIN" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
我的登錄表單:
<form action="<c:url value='j_spring_security_check' />" method="post">
Username: <input type="text" name="j_username" /><br/>
Password: <input type="password" name="j_password" /><br/>
<input type="submit" value="Login" /><br/>
</form>
我的登錄控制器:
@Controller
public class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String welcome(ModelMap m) {
return "login";
}
@RequestMapping(value = "/loginFailed", method = RequestMethod.GET)
public String failed(ModelMap m) {
m.addAttribute("error", "Invalid username or password");
return "login";
}
@RequestMapping("logout.htm")
public String logout(ModelMap m) {
return "redirect:login.htm";
}
}