簡體   English   中英

Spring Security記住我

[英]Spring Security Remember Me

我正在開發Spring MVC Web應用程序,並且已經配置了Spring Security來攔截所有URL並對其進行身份驗證。 如果用戶勾選“ 記住我 ”,則自動登錄用戶而無需重定向到登錄頁面。

說,我的登錄URL是

example.com/signin

和首頁是

example.com/home

當用戶輸入需要身份驗證的有效網頁(例如example.com/home)的任何URL時,如果啟用了“ 記住我”功能 ,則將其定向到該特定網頁,而無需再次進行身份驗證。

但是,當用戶輸入example.com/signin時,即使已經通過身份驗證和記住,它也只會顯示登錄表單。

如果他是經過身份驗證且啟用了我身份驗證的用戶,而又不顯示登錄頁面,該如何將他重定向到主頁(example.com/home)?

我向控制器添加了重定向。 請讓我知道這是否正確。

Authentication auth = SecurityContextHolder.getContext().getAuthentication();
            //if the user is already authenticated redirect him to the dashboard
            if(!(auth instanceof  AnonymousAuthenticationToken)){
                return "redirect:dashboard";
            }
            return "signin";

暫無
暫無

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

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