繁体   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