WebMvCtest:从WebSecurityConfigurerAdapter迁移到SecurityFilterChain

发布于 2025-02-11 12:13:54 字数 2207 浏览 1 评论 0 原文

如上所述在这里我已经使用了一段时间的WebSecurityConfigurerAdapter 。我使用了基于组件的方法并引入 SecurityFilterChain inmemoryuserdetailsmanager beans(请参阅: commit ),但是我的一项测试,它正在使用 @withmockuser 失败。

@webmvctest 测试使用 @withmockuser 使用Spring Security Component的方法( Security> SecurityFilterChain )?

整体项目带有失败测试,​​位于: https://github.com/pszemus/spring-security-security-security-security-security-security-security-security-ink-security-in-security-in-security一下测试

As described here Spring Security deprecated WebSecurityConfigurerAdapter which I've been using for some time. I used the component based approach and introduced SecurityFilterChain and InMemoryUserDetailsManager beans (see: commit) but then one of my tests, which is using @WithMockUser failed.

Does @WebMvcTest tests work with @WithMockUser when using Spring Security component based approach (SecurityFilterChain)?

Whole project, with failing test, is located: https://github.com/pszemus/spring-security-test

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2025-02-18 12:13:54

您应该在测试类中添加 @import(yoursecurityConfiguration.class) @webmvctest 没有自动拾取配置,因此您必须明确地告诉它要使用哪种配置。

You should add @Import(YourSecurityConfiguration.class) in your test class. The @WebMvcTest is not picking up the configuration automatically, so you have to tell it explicitly which configuration to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文