【问题标题】:Vaadin + SpringBoot integration and SecurityContextHolder.getContext() is nullVaadin + SpringBoot 集成和 SecurityContextHolder.getContext() 为空
【发布时间】:2015-11-05 09:37:45
【问题描述】:

我正在使用基于 https://vaadin.com/spring 的带有 SpringBoot 的 VAADIN。除身份验证外,一切正常。我正在使用基于 SpringBoot 的 SpringSecurity java 配置,它工作正常,SecurityContextHolder.getContext().getAuthentication() 在 VaadinUI 中为我返回当前用户。我的配置在这里非常简单:

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

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

【问题讨论】:

标签: spring-security spring-boot vaadin vaadin7


【解决方案1】:

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

看看discussion about a related topic here

【讨论】:

  • 嗯,我找不到任何完整的示例。我需要访问 SecurityContextHolder.getContext().getAuthentication() 还是应该复制 getAuthentication() 对象并将其存储到初始 ApplicationUI 对象中?
【解决方案2】:

确保扩展 WebSecurityConfigurerAdapter 的 @Configuration 类使用 @EnableWebSecurity 进行注释。

【讨论】:

    猜你喜欢
    • 2019-03-25
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 2016-11-04
    • 1970-01-01
    • 2020-06-02
    • 2019-09-19
    相关资源
    最近更新 更多