Configure Swagger-UI to pick up Spring's HttpSecurity Logout endpoint

岁酱吖の 提交于 2021-01-27 05:52:49

问题


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

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

回答1:


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



来源:https://stackoverflow.com/questions/36947117/configure-swagger-ui-to-pick-up-springs-httpsecurity-logout-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!