簡體   English   中英

使用Spring,如何手動觸發AuthenticationSuccessHandler

[英]Using Spring, how can I manually fire AuthenticationSuccessHandler

我想為用戶提供一種使用令牌登錄的替代方法。 我已經在PreAuthenticationFilter類中處理了對用戶的身份驗證,但是隨后我需要觸發我的

AuthenticationSuccessHandler.onAuthenticationSuccess()

哪個

super.onAuthenticationSuccess()

這會在其基類中觸發該方法

SavedRequestAwareAuthenticationSuccessHandler.

如何從預AuthenticationSuccessHandler過濾器中啟動AuthenticationSuccessHandler 我嘗試設置SecurityContextHolder的身份驗證,認為它會自動觸發AuthenticationSuccessHandler但事實並非如此。 這就是我試圖做到的:

Authentication authentication = new UsernamePasswordAuthenticationToken(Username, Password);
SecurityContextHolder.getContext().setAuthentication(authentication);

不幸的是,那行不通。 因此,我需要知道如何從預AuthenticationSuccessHandler過濾器中啟動AuthenticationSuccessHandler

您可能會因為RememberMeAuthenthicationFilter如何在春季安全性中工作而受到啟發。 它具有對AuthenticationSuccessHandler的引用,並手動調用onAuthenticationSuccess

您必須擴展PreAuthenticationFilter並覆蓋成功的方法。 在那里,您可以觸發注入的成功處理程序。

暫無
暫無

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

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