![](/img/trans.png)
[英]How can I manually add a Spring CacheInterceptor using Java Config?
[英]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.