Spring安全性从自定义筛选器中排除端点
具有具有以下功能的spring安全配置:Spring安全性从自定义筛选器中排除端点,spring,spring-security,spring-boot,spring-java-config,Spring,Spring Security,Spring Boot,Spring Java Config,具有具有以下功能的spring安全配置: http.antMatcher("/**/v1/public/company/employees/**") .authorizeRequests() .antMatchers(HttpMethod.OPTIONS, "/**/v1/public/company/employees/A").permitAll() .antMatchers(HttpMethod.
http.antMatcher("/**/v1/public/company/employees/**")
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/**/v1/public/company/employees/A").permitAll()
.antMatchers(HttpMethod.POST, "/**/v1/public/company/employees/B").permitAll()
.antMatchers("/**/v1/public/company/employees/**")
.authenticated()
.and()
.csrf()
.disable()
.addFilterBefore(customFilter, AbstractPreAuthenticatedProcessingFilter.class);
如何从customFilter
中排除公共端点(A和B)
更新
使用:
@Override
public void configure(WebSecurity web) throws Exception {
web
.ignoring()
.antMatchers(HttpMethod.OPTIONS, "/**/v1/public/company/employees/A")
.antMatchers(HttpMethod.POST, "/**/v1/public/company/employees/B")
}
似乎足够了,但我仍然不知道这是否是推荐的方法所以基本上有三个端点-对吗?其中两个是公开的,另一个是需要身份验证的?我使用
/**
作为需要身份验证的端点,因此有很多端点。端点的数量很重要吗?因为我正在寻找通用的方法。一个解决方案可能是为端点A和B创建单独的http安全配置。这意味着您将得到两个额外的安全配置。我认为您可以遵循此指南