Spring security 瓦丁+;SpringBoot集成和SecurityContextHolder.getContext()为空

Spring security 瓦丁+;SpringBoot集成和SecurityContextHolder.getContext()为空,spring-security,spring-boot,vaadin,vaadin7,Spring Security,Spring Boot,Vaadin,Vaadin7,我正在使用基于的带SpringBoot的VAADIN。除了身份验证之外,一切正常。我使用的是基于SpringBoot的SpringSecurity java配置,它工作正常,SecurityContextHolder.getContext().getAuthentication()在VaadinUI中为我返回当前用户。我的配置非常严格: http.authorizeRequests() .antMatchers("/*").authenticated().and().httpBasic(

我正在使用基于的带SpringBoot的VAADIN。除了身份验证之外,一切正常。我使用的是基于SpringBoot的SpringSecurity java配置,它工作正常,
SecurityContextHolder.getContext().getAuthentication()
在VaadinUI中为我返回当前用户。我的配置非常严格:

  http.authorizeRequests()
  .antMatchers("/*").authenticated().and().httpBasic()

问题在于,
SecurityContextHolder.getContext().getAuthentication()
仅在显示VaadinUI时为第一个请求返回正确的值。然后,任何后续的Vaadin请求(例如,单击按钮)都会为SecurityContextHolder.getContext().getAuthentication()返回null。知道如何让它按预期工作吗?

这是因为Vaadin处理请求的方式。它不使用DispatcherServlet,您可能需要使用RequestContextListener(或RequestContextFilter)来启用请求和会话范围


查看。

确保扩展WebSecurity ConfigureAdapter的@Configuration类用
@EnableWebSecurity

注释,除非您已经安装,否则您需要通过调用
SecurityContextHolder.getContext().setAuthentication(…​)嗯,我找不到任何完整的示例如何操作。我需要访问SecurityContextHolder.getContext().getAuthentication(),还是应该复制getAuthentication()对象并将其存储到初始ApplicationUI对象中?