我使用springdoc-openapi-ui来编写API文档
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.14</version>
</dependency>
并且,遵循Spring Boot安全配置
.
.
public static String[] SWAGGER_WHITELIST = {
"/api-docs",
"/swagger-ui.html",
"/swagger-resources/**",
"/webjars/**",
"/swagger.json"
};
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.cors().disable();
http.csrf().disable();
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
http
.authorizeHttpRequests()
.requestMatchers(SWAGGER_WHITELIST).permitAll()
.requestMatchers(AUTH_WHITELIST).permitAll()
.and()
.addFilterAt(new JWTAuthenticationFilter(userService, jwtService, authenticationProvider()), UsernamePasswordAuthenticationFilter.class)
// .addFilterAfter(new UserAuthorizationFilter(), JWTAuthenticationFilter.class)
.authorizeHttpRequests()
.anyRequest().authenticated();
return http.build();
}
.
.
Spring Boot父版本:3
当我尝试访问http://localhost:8080/swagger-ui.html时,我得到了403。
有人面临类似的问题吗?问题可能是什么?
我试过了
- 将招摇的URL列入白名单
- 从配置更改swagger文档路径
我越来越
- 调试失败,因为控制台未显示任何异常
- 它只是拒绝请求而不打印任何日志
1条答案
按热度按时间4c8rllxm1#
以下更改为我修复了该问题