【问题标题】:Get access to springfox swagger-ui behind spring-security访问 spring-security 后面的 springfox swagger-ui
【发布时间】:2017-05-01 23:23:25
【问题描述】:

我将在我的 Spring Boot (1.4.2v) 中使用带有 swagger-ui 的 springfox (2.6.1v)。

它的配置看起来:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

  @Bean
  public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
               .select()
               .apis(RequestHandlerSelectors.any())
               .paths(PathSelectors.any())
               .build()
               .genericModelSubstitutes(ResponseEntity.class);
  }
}

问题是我的招摇落后于 Spring Security,我只需要允许管理员访问那里。

问题是允许 swagger-ui 在我的应用程序中工作的匹配器集应该是什么?

public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
        .antMatchers("??? <<<what_should_be_here>>> ???") // what should be here?
        .hasRole("TENANT_ADMIN");
  }
}

【问题讨论】:

    标签: spring-security swagger-ui springfox


    【解决方案1】:

    好的,首先我找到了解决方案here,所以以下几行:

    .antMatchers("/admin/system/state/*", "/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**")
    

    但还是没有工作,因此我问了这个问题。但经过更深入的调查,发现 spring-fox 不支持 GSON。当您将 GSON 用作“to json”转换器时,swagger-ui 会收到稍微不同的 JSON 格式,这会导致问题...

    当我们将转换器更改为 Jackson 并将上述路径添加到 spring-config 时,它可以正常工作。

    我什至在 spring-fox github here 上请求了新功能。

    【讨论】:

      猜你喜欢
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 2018-01-27
      • 2021-06-03
      • 2012-11-07
      相关资源
      最近更新 更多