java - Spring security permit all 不适用于多个 url

标签 java spring-boot microservices spring-security-oauth2

我正在尝试向多个 url 授予全部许可,但得到 403。当我禁用 csrf 时,所有请求都在未经身份验证的情况下工作。请在我的安全配置下方找到。

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .authorizeRequests()//.anyRequest().permitAll()
                .antMatchers("/actuator/**","/v1/foo/link")
                .permitAll()
                .antMatchers("/**")
                .authenticated()
                .and()
                .oauth2ResourceServer()
                .jwt(withDefaults());
    }
}

请纠正我遗漏的地方。谢谢..

最佳答案

我在提到的 stackoverflow 链接中找到了这个答案,它正在工作。

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers("/v1/foo/link").antMatchers("/v1/refer/link");
}

Spring Security exclude url patterns in security annotation configurartion

关于java - Spring security permit all 不适用于多个 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62466671/

相关文章:

java - 返回泛型类型 <String,Double>

java - 用 Ant 脚本替换正则表达式

java - 读取输入消息时出现 I/O 错误;嵌套异常是 java.io.IOException : Stream closed

maven-3 - Jboss EAP 上的 spring Boot 应用程序,servlet 上下文未加载

mongodb - MongoRepository 在数组中查找列表

websocket - MicroFrontends 通过单 channel /websocket 到 MicroService 后端的通信模式

architecture - 微服务与用户之间的授权

java - 如何使这段代码更简单、更短,Java

java - 如何在不更改 Spring Boot 中的实际类的情况下远程创建 bean?

json - 在微服务中使用 json Web token 进行 session 管理