2016-12-16 39 views
3

我將在Spring Boot(1.4.2v)中使用springfox(2.6.1v)和swagger-ui。訪問彈簧安全背後的springfox swagger-ui

它的配置如下:

@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); 
    } 
} 

的問題是,我昂首闊步的背後是春天的安全性,我只需要通過管理員允許訪問那裏。

問題是什麼應該是允許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"); 
    } 
} 

回答

1

確定第一我已經找到了解決辦法here所以下面幾行:

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

但還是某事沒有工作,因爲我已經問過這個問題。但經過深入調查發現,春狐不支持GSON。當您使用GSON作爲「to json」轉換器時,swagger-ui會收到稍微不同的JSON格式,從而導致問題...

當我們將轉換器更改爲Jackson並將以上路徑添加到spring-config時,它沒有任何問題。

我甚至要求spring-fox github here上的新功能。