Spring Security从定制过滤器中排除端点

问题描述 投票:5回答:1

具有带有以下内容的spring安全配置:

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中排除公共端点(AB)?

更新

使用:

@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")
        }

似乎足够,但是我仍然不知道这是否是推荐的方式

spring spring-security spring-boot spring-java-config
1个回答
0
投票

我已经尝试了您在更新中提供的解决方案,但对我来说它不起作用,我仍然收到401未经授权。

© www.soinside.com 2019 - 2024. All rights reserved.