【问题标题】:Configure Swagger-UI to pick up Spring's HttpSecurity Logout endpoint配置 Swagger-UI 以获取 Spring 的 HttpSecurity Logout 端点
【发布时间】:2016-08-25 03:11:45
【问题描述】:

我已经为我的应用程序中列出的所有控制器设置并工作了 Swagger。但是,我希望它能够获取 Spring Security Logout Endpoint,但我找不到让它工作的方法。正如您从下面的代码 sn-p 中看到的那样,我正在为用户指定一个 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);
}

我的 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";
                }
            });
}

【问题讨论】:

    标签: java spring spring-mvc spring-security swagger-ui


    【解决方案1】:

    Spring Fox 插件使用 Spring bean 构建 API 文档。看看这个答案:https://stackoverflow.com/a/42720435/439171

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-04
      • 2017-10-18
      • 2016-08-08
      • 2021-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多