使用 Spring Security 允许匿名访问 springdoc-openapi-ui [英] Allow anonymous access to springdoc-openapi-ui with Spring Security
本文介绍了使用 Spring Security 允许匿名访问 springdoc-openapi-ui的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何允许匿名访问 springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html
) 在 Spring Security 保护的 Spring Boot 应用程序中?
How to allow anonymous access to springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html
) in a Spring Boot application secured by Spring Security?
推荐答案
要使用 springdoc-openapi-ui /swagger-ui.html
,允许匿名访问 WebSecurityConfigurerAdapter
使用 permitAll
方法:
To use springdoc-openapi-ui /swagger-ui.html
, allow anonymous access to the following endpoints in the WebSecurityConfigurerAdapter
using permitAll
method:
/v3/api-docs/**
/swagger-ui/**
/swagger-ui.html
示例:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.
.authorizeRequests()
.antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic(); //or anything else, e.g. .oauth2ResourceServer().jwt()
}
}
确保项目具有以下依赖项:
Make sure a project has the following dependencies:
这篇关于使用 Spring Security 允许匿名访问 springdoc-openapi-ui的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文