大佬教程收集整理的这篇文章主要介绍了启用 MethodSecurityInterceptor 发布 AuthorizedEvent,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在 spring-boot 2.X 应用程序中审核成功的授权。
因此,我尝试开始侦听 AuthorizedEvent
,但直到 AbstractSecurityInterceptor.publishAuthorizationsuccess
设置为 true,该事件才会发布。
此应用程序主要使用 @Secured
和 @PreAuthorize
/@PostAuthorize
批注,因此我尝试侦听的拦截器是 @H_494_3@methodSecurityInterceptor(它还为我提供了被授权的安全角色反对 FilterSecurityInterceptor
没有)
除了通过感觉脆弱的 @H_494_3@methodSecurityInterceptor 之外,我看不到任何配置 BeanPostProcessor
和启用事件发布的方法。
有没有比通过 @H_494_3@methodSecurityInterceptor.publishAuthorizationsuccess 启用 BeanPostProcessor
更好的方法?
在 spring-security github 存储库中发布了 an issue。
根据 reply,目前没有更好的方法来配置 @H_494_3@methodSecurityInterceptor,他们正在代码的那部分制作 major changes,因此现在没有任何改进的意义。
因此配置 @H_494_3@methodSecurityInterceptor 的最佳方法是通过如下所示的 BeanPostProcessor
:
@Component
public class MethodSecurityInterceptorPostProcessor implements BeanPostProcessor {
public Object postProcessAfterInitialization(Object bean,String beanName) throws BeansException {
if (bean instanceof MethodSecurityInterceptor) {
((MethodSecurityInterceptor) bean).setPublishAuthorizationsuccess(true);
}
return bean;
}
}
以上是大佬教程为你收集整理的启用 MethodSecurityInterceptor 发布 AuthorizedEvent全部内容,希望文章能够帮你解决启用 MethodSecurityInterceptor 发布 AuthorizedEvent所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。