首页 文章

将spring-boot-starter-security与Vaadin 7集成在一起

提问于
浏览
1

我正在尝试将 Spring SecurityVaadin Springhttps://vaadin.com/wiki/-/wiki/Main/Vaadin+Spring)集成 .

我的应用程序类只是启动Spring应用程序

https://gist.github.com/anonymous/c047030c61b90c02d1ef

我创建了一个扩展 WebSecurityConfigurerAdapter 的类

https://gist.github.com/anonymous/0e905d0627adf5e2dc39

pom.xml 包含依赖 spring-boot-starter-security

当我输入localhost:8080时,它会将我重定向到Spring Security提供的登录URL(http://localhost:8080/login) . 我输入用户名/密码(用户/密码),我收到此错误 .

java.lang.NullPointerException:null at com.vaadin.server.LegacyCommunicationManager.getClientCache(LegacyCommunicationManager.java:194)

https://gist.github.com/anonymous/b4be702762b5bc744c66处的完整日志输出) .

我尝试根据我在网络上找到的示例添加到 ApplicationSecurity 覆盖的方法"configuration(HttpSecurity http)"但是这给了我更多的错误,因为它根本不会带我到/ login页面 .

1 回答

  • 2

    我想这可能与当前测试版不支持所有功能的事实有关stated by Henry Sara

    Vaadin Spring是一个官方附加组件(目前从alpha转向beta,有一些API更改),包括Vaadin4Spring的核心功能 . 当前版本的Vaadin Spring(事件总线,Spring安全支持,......)未涵盖的Vaadin4Spring部分将在测试版发布后的某个时间转换为使用Vaadin Spring . 更多功能可能会在未来版本中迁移到官方插件 .

    无论如何,出于对 spring 安全的好奇(到目前为止还没有使用它)我已经用Vadin 7.4.3进行了一些研究 . 我在调试时设置了根 Logger ,添加了几个断点(UIInitHandler:148)并注意到以下内容:

    • UIInitHandler 正确处理了初始请求,并创建了相应UI的实例

    • 紧接在/错误路径触发相同的断点@ UIInitHandler:148 之后,处理程序无法解析UI,因为很可能您没有定义 . 这也让我觉得可能会抛出异常但隐藏在那里的某个地方

    • 看日志我看了很多 Invalid CSRF token found for http://localhost:8080/login?v-1429092013868

    所以我将 ApplicationSecurity.configure(HttpSecurity http) 方法改为 http.csrf().disable().authorizeRequests().anyRequest().permitAll(); 并且我能够进入第二个屏幕 . 现在这可能不是我收集的那么安全,但它应该给你一个起点 .

    注意:您可能已经知道这一点,但如果您不这样做,它可以节省您一些时间,我也很高兴分享这一点,因为我花了一段时间才弄明白 . 根据您设置应用安全性的方式,您可能最终将该方法更改为如下所示 .

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().
                exceptionHandling().authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")).accessDeniedPage("/accessDenied")
                .and().authorizeRequests()
                .antMatchers("/VAADIN/**", "/PUSH/**", "/UIDL/**","/login", "/login/**", "/error/**", "/accessDenied/**").permitAll()
                .antMatchers("/authorized", "/**").fullyAuthenticated();
    }
    

相关问题