【问题标题】:Spring security call for all the services when loading swagger UI加载 swagger UI 时对所有服务的 Spring 安全调用
【发布时间】:2020-09-14 04:30:41
【问题描述】:

我正在使用 springdoc-openapi-ui。当我加载我的招摇页面时,会在加载招摇 UI 时为所有 API 调用 spring-security。我有弹簧安全。我的期望是当我尝试从 swagger 中访问特定 API 时应该调用安全性。

我的招摇用户界面链接如下所示

'http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config'

当我使用 springfox-swagger-ui 时,它按预期工作。 最近我已经迁移到 springdoc-openapi-ui。

【问题讨论】:

  • 你能添加你的 Spring Security 配置吗?
  • 我已经配置了基本安全
  • 这是否意味着您没有配置任何东西而只是使用默认值?如果是这样,这可能是问题所在。您需要告诉 Spring Security 应用程序中的哪些路径应该受到保护,哪些不应该受到保护。 Spring对此有一个基本指南:spring.io/guides/gs/securing-web

标签: java spring-boot spring-security swagger-ui springdoc-openapi-ui


【解决方案1】:

Swagger 端点更改为带有springdoc-openapi-ui 的新映射。在SecurityConfiguration 中进行了相同的更改。现在在加载 swagger ui 时不会调用安全性。

public abstract class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
    
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(HttpMethod.OPTIONS, "/**").antMatchers("/v3/api-docs/**",
                "/swagger-ui/**", "/swagger-ui/index.html/**");
    }
}

【讨论】:

    猜你喜欢
    • 2021-09-01
    • 2018-09-13
    • 2017-07-24
    • 2018-02-12
    • 2016-09-06
    • 2023-03-11
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    相关资源
    最近更新 更多