gpt4 book ai didi

java - Spring Security 中 Web 忽略和 Http 允许之间的区别?

转载 作者:行者123 更新时间:2023-11-30 07:41:47 24 4
gpt4 key购买 nike

这两种方法有什么区别?

 @Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/api/**").permitAll();
}

@Override
public void configure(WebSecurity web) {
web.ignoring().antMatchers("/api/**");
}

在 spring 安全配置类中,当我使用 HttpSecurity 时,它仍然给我 403 forbidden,但是当我使用 WebSecurity 时,它通过了吗?这是为什么?我觉得我几乎无法控制什么是允许的,什么需要通过过滤器授权。

最佳答案

我建议您浏览一下这篇文章:Spring Security Java Config Preview: Web Security您的代码中这两种方法之间的区别是:

  • HttpSecurity允许为 HTTP 请求配置基于 Web 的安全性。在此级别,您声明身份验证规则。
  • WebSecurity允许配置对所有 Web 安全具有全局影响的事物,例如设置 Debug模式或使用 HttpFirewall 的实现启用进一步的防火墙配置或者像您的代码所示那样简单地忽略资源。

您可能对第 3 个 configure 感兴趣WebSecurityConfigurerAdapter的方法它使用:

关于java - Spring Security 中 Web 忽略和 Http 允许之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55652267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com