配置Swagger-UI以获取Spring的HttpSecurity Logout端点

Jos*_*her 5 java spring spring-mvc spring-security swagger-ui

我有Swagger设置并为我的应用程序中列出的所有控制器工作.但是,我希望它能够获得Spring Security Logout端点,但我找不到让它工作的方法.正如您从下面的代码片段中看到的,我为用户指定了一个logoutUrl来使其会话无效.我已经尝试过类级注释标记和方法级别,但没有运气.有任何想法吗?

@Override
public void configure(HttpSecurity http) throws Exception {
    http.addFilter(someFilter());
    http.headers().and().csrf().disable()
            .authorizeRequests()
            .antMatchers("endpoint",
                    "endpoint",
                    "endpoint",
                    "endpoint",
                    "endpoint",
                    "endpoint",
                    "endpoint").permitAll()     
            .anyRequest().authenticated()
            .and()
            .logout().logoutUrl("endpoint/logout").invalidateHttpSession(true).logoutSuccessHandler(logoutSuccessHandler);
}
Run Code Online (Sandbox Code Playgroud)

我的Swagger Docket配置如下:

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            .apiInfo(new ApiInfo("API",
                    "Provides API's",
                    "1.0",
                    null,
                    "someEmail@nowhere.com",
                    null,
                    null))
            .useDefaultResponseMessages(false)
            .pathProvider(new RelativePathProvider(servletContext) {
                @Override
                protected String applicationPath() {
                    return super.applicationPath() + "/path";
                }

                @Override
                protected String getDocumentationPath() {
                    return super.getDocumentationPath() + "/path";
                }
            });
}
Run Code Online (Sandbox Code Playgroud)

Ita*_*tto 0

Spring Fox 插件使用 Spring bean 来构建 API 文档。看看这个答案:/sf/answers/2990430481/