WebMvCtest:从WebSecurityConfigurerAdapter迁移到SecurityFilterChain
如上所述在这里我已经使用了一段时间的WebSecurityConfigurerAdapter 。我使用了基于组件的方法并引入 SecurityFilterChain
和 inmemoryuserdetailsmanager
beans(请参阅: commit ),但是我的一项测试,它正在使用 @withmockuser
失败。
@webmvctest
测试使用 @withmockuser
使用Spring Security Component的方法( Security> SecurityFilterChain
)?
- 测试:
- 使用
web code> code> code> code> > (for which all tests pass): https://github.com/pszemus/spring-security-test/blob/c323ce3af77bb067c7eef58fd933689ef97c082c/src/main/java/com/example/springsecuritytest/SecurityConfiguration.java
- New security configuration that use基于组件的方法(
给予Mockedcredentials_shouldAccessSecuredPoint
测试失败的消息:状态预期:< 200>但是: securityConfiguration.java“ rel =“ noreferrer”> https://github.com/pszemus/spring-security-test/blob/blob/fb9b4019474747a3b456781818181818181c581c582cbb004a32cb004a3/sringsrime smer trime ation.java
整体项目带有失败测试,位于: https://github.com/pszemus/spring-security-security-security-security-security-security-security-security-ink-security-in-security-in-security一下测试
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在测试类中添加
@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.