【发布时间】:2022-12-15 15:30:32
【问题描述】:
我目前正在为我正在从事的项目之一设置 Swagger UI 界面,但我遇到了各种问题。
我的项目使用 Spring 安全性来保护使用不记名令牌身份验证的 API 调用,因此我需要提供一种启用输入对话框的方法,以便用户可以输入他们的不记名令牌。我已经尝试了 OpenAPI 文档中关于此的所有内容,但似乎无法正确呈现对话框。
其次,该项目会进行 CSRF 检查,即使我的应用程序属性包括 springdoc.swagger-ui.csrf.enabled=true,检查也会不断失败。我有一个死胡同,我不知道如何解决这两个问题。作为参考,我的安全配置如下:
@Bean
public SecurityWebFilterChain securityFilterChain(ServerHttpSecurity security) {
if (securityProperties.isEnabled()) {
return security
.securityMatcher(new NegatedServerWebExchangeMatcher(ServerWebExchangeMatchers.pathMatchers(securityProperties.getIgnoredPaths())))
.exceptionHandling()
.accessDeniedHandler(accessDeniedHandler)
.authenticationEntryPoint(entryPoint)
.and()
.cors()
.and()
.authorizeExchange(spec -> spec.anyExchange().authenticated())
.oauth2ResourceServer(ServerHttpSecurity.OAuth2ResourceServerSpec::jwt)
.build();
}
return security
.securityMatcher(new PathPatternParserServerWebExchangeMatcher("/**"))
.authorizeExchange(spec -> spec.anyExchange().permitAll())
.csrf()
.disable()
.build();
}
【问题讨论】:
标签: spring spring-boot spring-webflux swagger-ui springdoc-openapi-ui