【发布时间】:2021-07-17 05:20:19
【问题描述】:
我想在我的浏览器上打开 swagger ui。这是我的代码
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/swagger-ui.html").permitAll() .anyRequest().authenticated().and().httpBasic().and().csrf().disable();
}
但它不起作用。我还需要输入httpBasic()提供的基本认证
所以我添加以下别人找到的代码
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs",
"/configuration/ui",
"/swagger-resources/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**");
}
现在,我可以访问 localhost:8080/swagger-ui.html 但仍然会弹出 httpBasic 窗口。我可以点击取消关闭窗口并继续使用 swagger ui。但我不知道是什么导致了这个问题
【问题讨论】:
-
不是真的,请阅读我的问题的第二部分。
-
基本上我可以打开 swagger UI 但添加代码后 httpBasic() 仍然会弹出
-
该问题是由主要
swagger-ui.html文件直接或间接引用的辅助文件引起的。.js、.css、.png等文件。您可以在 Web 浏览器的“网络”面板上查看完整列表。例如。在 Firefox 中,按 F12 并选择“网络”选项卡,然后重新加载页面。 Chrome 也有类似的功能。返回状态为401 Unauthorized的请求是导致 httpBasic 弹出窗口发生的原因。 -
@Andreas 可能是对的
标签: java spring spring-boot swagger