spring-security - 在 spring-security 后面访问 springfox swagger-ui

标签 spring-security swagger-ui springfox

我将在 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 安全性,我只需要允许管理员访问那里。

问题是允许 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");
  }
}

最佳答案

好的,首先我找到了解决方案 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 .

关于spring-security - 在 spring-security 后面访问 springfox swagger-ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41179725/

相关文章:

java - 由 : java. lang.ClassNotFoundException : springfox. documentation.common.ClassPresentInClassPathCondition 引起

java - 如何安排Docket的groupName在Swagger UI中显示的顺序

java - Spring security自定义登录页面带有基于java的配置

spring - 如何在 jetty 9 中禁用基于 JSESSIONID cookie(和任何其他)的 session 跟踪功能?

java - Swagger UI 仅显示获取端点。

java - 无法将 Swagger-ui 链接到我的 Swagger Spring mvc 项目

spring-boot - 由于 Content-Security-Policy,Swagger UI 为空白

spring - 集成spring和vaadin

java - Spring Security 可以接受同一用户的多个密码吗?

Java - 如何直接从 openapi 3.0 规范生成 Swagger UI