我将在 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/