我正在開發一個基於spring的項目; 對於用戶登錄界面,我使用Spring Security 4.0.3; 併發控制上的一切都很好,但我想在用戶嘗試登錄另一個時間並且以前的日誌記錄會話未過期時獲取自定義錯誤消息。 對於記住我的問題,它是固定的,因爲它使用session-authentication-error-url="/login?auth_error
但是對於從窗體的多個日誌記錄,它重定向到在<form-login login-page="/login" default-target-url="/"
指定的網址這是用於錯誤的用戶名或密碼。 由於我使用url中指定的參數在重定向時發送錯誤,我怎麼能將用戶發送到像
authentication-failure-url="/login?error" />/login?different_error
這樣的頁面呢?在spring-security.xml
Spring Security 4併發控制,想要使用authentication-error-url都是錯誤登錄或已經登錄的用戶
<session-management invalid-session-url="/login?invalid"
session-authentication-error-url="/login?auth_error">
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
</session-management>
監聽 會話管理web.xml
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
登錄,在控制器的方法
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout,
@RequestParam(value = "invalid", required = false) String invalid,
@RequestParam(value = "auth_error", required = false) String auth_error) {
ModelAndView model = new ModelAndView();
if (error != null) {
model.addObject("error", "Username e/o password non validi!");
}
if (logout != null) {
model.addObject("msg", "Hai effettuato il logout!");
}
if (invalid != null) {
model.addObject("error", "invalid session ID");
}
if (auth_error != null) {
model.addObject("error", "Utente già loggato nel sistema");
}
model.setViewName("login");
return model;
}
感謝,任何幫助將非常感激。
編輯:用戶註銷也被檢測爲無效會話