spring-boot - 钥匙斗篷+弹簧。无论授权标头如何,都忽略某些 API
问题描述
我想api/v1/public/**
为所有经过身份验证的用户和匿名用户允许某些模式 API。
我的项目中有 Keycloak 适配器设置,我的 WebConfiguration 如下所示:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true, jsr250Enabled = true)
public class KeycloakWebConfig extends KeycloakWebSecurityConfigurerAdapter {
// ........ other methods .........//
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors().and().csrf().disable()
.authorizeRequests()
.anyRequest().permitAll();
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/api/v1/public/**");
}
}
使用此设置,当我调用/api/v1/public/ping
没有任何标头的 API 时,它可以正常工作。我得到了预期的回应。
但是,如果我在向同一个 api 发出请求时添加一个随机或空的 Authorization 标头,它根本不会响应。
使用 Postman 发出请求,它显示“连接到http://localhost:8080/api/v1/public/ping时出错”。
使用 cURL 终端命令发出请求,它不打印任何内容并终止进程。
如果我在没有任何标题字段的情况下再次拨打相同的电话(使用邮递员或 curl),它会再次正常工作。知道是什么原因造成的吗?
解决方案
推荐阅读
- python - 从 mongo db 游标的嵌套数据中构建 pandas 数据框
- javascript - Webpack - worker importScripts 的单独捆绑包
- java - 如何使用java程序执行oraenv脚本?
- azure - 流分析 - 将传入的 JSON 转换为 PowerBI 流数据集
- google-chrome - Chrome DevTools 控制台中的 Service Worker(不可见)错误
- .net - 使用axios发布上传图片结果为空文件集合
- python - 使用命令 sqlalchemy 更新
- ansible - 在ansible中循环嵌套列表
- javascript - 承诺不返回数据
- jquery - jQuery AJAX 不适用于 iPhone Safari