Zie*_*zyk 6 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);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我的招摇落后于 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");
}
}
Run Code Online (Sandbox Code Playgroud)
好的,首先我在这里找到了解决方案,所以以下几行:
.antMatchers("/admin/system/state/*", "/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**")
Run Code Online (Sandbox Code Playgroud)
但仍然没有奏效,因此我问了这个问题。但经过更深入的调查,发现 spring-fox 不支持 GSON。当您使用 GSON 作为“to json”转换器时,swagger-ui 收到的 JSON 格式略有不同,这会导致问题......
当我们将转换器更改为 Jackson 并将上述路径添加到 spring-config 时,它可以正常工作。
我什至在 spring-fox github 上请求了新功能here。
| 归档时间: |
|
| 查看次数: |
6163 次 |
| 最近记录: |