作者:城哥_1986 | 来源:互联网 | 2023-02-05 14:02
我有一个Spring Boot + Spring Security应用程序,它有几个antMatchers
路径; 一些fullyAuthenticated()
,一些permitAll()
.
如何编写一个测试验证SecurityConfiguration
我的端点/api/**
(以及最终其他)是否正确安全?
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http
//...
.antMatchers("/api/**").fullyAuthenticated()
}
}
使用spring-boot-1.5.2.RELEASE
,spring-security-core-4.2.2-release
.
澄清1:我希望尽可能直接测试SecurityConfiguration
,而不是通过其中一个/api/**
端点进行传递测试,这些端点可能有自己的@PreAuthorize
安全性.
澄清2:我想要类似于这个WebSecurityConfigurerAdapterTests的东西.
澄清3:@Autowire
理想情况下HttpSecurity
,我想在Spring Security层进行测试.