簡體   English   中英

更改密碼后如何以編程方式驗證用戶身份? 使用j_security_check進行基於表單的身份驗證來登錄

[英]How to programatically authenticate user after changing password? Form-based authentication using j_security_check was used to login

更改密碼后如何以編程方式對用戶進行身份驗證? 使用j_security_check的基於表單的身份驗證進行登錄。 更改密碼后,用戶將被重定向到主頁(這是必需的),但是在提交屏幕或單擊鏈接/按鈕時,用戶將被重定向回到登錄頁面。 我認為這是因為用於在后台進行身份驗證的密碼仍然是舊密碼。

如果可以獲得HttpServletRequest (這是JSF中的示例),則可以從那里調用login()

FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
request.login(username, password);

獎勵信息:要注銷當前用戶,可以在HttpSession上調用invalidate()

FacesContext context = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)context.getExternalContext().getSession(true);
session.invalidate();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM