配置 Swagger-UI 以获取 Spring 的 HttpSecurity Logout 端点 [英] Configure Swagger-UI to pick up Spring's HttpSecurity Logout endpoint

查看:77
本文介绍了配置 Swagger-UI 以获取 Spring 的 HttpSecurity Logout 端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have Swagger set up and working for all of the controllers listed in my application. However, I want it to pick up the Spring Security Logout Endpoint and I cannot find a way to get it to work. As you can see from code snippet below I am specifying a logoutUrl for a user to invalidate their session. I've tried class level annotation markings and method level, but no luck. Any ideas?

@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 配置如下:

My Swagger Docket configuration is below:

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

推荐答案

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

The Spring Fox plugin uses Spring beans to build the API documentation. Take a look at this answer: https://stackoverflow.com/a/42720435/439171

这篇关于配置 Swagger-UI 以获取 Spring 的 HttpSecurity Logout 端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆