相关疑难解决方法(0)

了解 spring-security 上的 requestMatchers()

我正在研究一些弹簧安全代码。我想了解我在互联网1上找到的这个例子 :

http.requestMatchers()
        .antMatchers("/management/**") // (1)
        .and()
        .authorizeRequests() // (2)
        .antMatchers("/management/health")
        .permitAll()
        .antMatchers("/management/info")
        .permitAll()
        .antMatchers("/management/**")
        .hasRole("ACTUATOR")
        .anyRequest().permitAll()
        .and()
        .httpBasic(); (3)
Run Code Online (Sandbox Code Playgroud)

}

我无法理解这个配置,为什么这个代码:

http.requestMatchers()
        .antMatchers("/management/**")
        .and() 
Run Code Online (Sandbox Code Playgroud)

在 .authorizeRequests() 之前?(1)

这意味着什么?

你能解释一下这个例子吗?

2:在第二种情况下,有什么区别?

http.requestMatchers().antMatchers("/rest2/**")
.and()
.authorizeRequests()
.antMatchers("/rest/v1/test/hello").permitAll()
.antMatchers("/rest/v1/test/**").denyAll()
.and()
.requestMatchers().antMatchers("/rest/**")
.and()
.authorizeRequests()
.antMatchers("/rest/v1/test/hello").permitAll();
Run Code Online (Sandbox Code Playgroud)

使用 requestMatchers() 有什么影响?

如果我向 "/rest/v1/test/hello2" 发送请求,我会收到 401 为什么拒绝请求的规则与 antMatchers("/rest2/**") 不匹配?

spring-security spring-boot

8
推荐指数
2
解决办法
1万
查看次数

标签 统计

spring-boot ×1

spring-security ×1