In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how Spring security opens up access to Swagger. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Spring security opens Swagger access to these four directories
Done.
.antMatch ("/ swagger-ui.html"). PermitAll (). AntMatchers ("/ webjars/**"). PermitAll (). AntMatchers ("/ v2 swagger-resources/** *"). PermitAll (). AntMatchers ("/ swagger-resources/**"). PermitAll () swagger cannot be accessed after adding the interceptor
The problem that swagger cannot be accessed after spring boot is added to the interceptor
When the interceptor is not added, swagger can access the interface information normally, but after adding the interceptor, swagger cannot access it.
Cause analysis
The built-in interface of swagger that cannot be accessed is blocked by the interceptor.
You can see all the requested url information of swagger in the picture, just add them to the interceptor's exclusion list.
Package com.trimps928.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;/** * @ author liubing * @ version 2018-06-26 * interceptor configuration * * / @ Configurationpublic class MyWebAppConfig extends WebMvcConfigurationSupport {@ Bean LoginInterceptor localInterceptor () {return new LoginInterceptor () } @ Override public void addInterceptors (InterceptorRegistry registry) {registry.addInterceptor (localInterceptor ()) .addPathPatterns ("/ * *") .principdePathPatterns ("/ user/login") .acquidePathPa tterns ("/ swagger-resources/**", "/ webjars/**", "/ v2According *", "/ swagger-ui.html/**") } @ Override protected void addResourceHandlers (ResourceHandlerRegistry registry) {registry.addResourceHandler ("swagger-ui.html") .addResourceLocations ("classpath:/META-INF/resources/"); registry.addResourceHandler ("/ webjars/**") .addResourceLocations ("classpath:/META-INF/resources/webjars/") }} most of the materials found on the Internet only said to add this @ Override public void addInterceptors (InterceptorRegistry registry) {registry.addInterceptor (localInterceptor ()) .addPathPatterns ("/ * *") .origindePathPatterns ("/ user/login") .exc ludePathPatterns ("/ swagger-resources/**", "/ webjars/**", "/ v2 swagger-ui.html/**"). } or just add @ Override protected void addResourceHandlers (ResourceHandlerRegistry registry) {registry.addResourceHandler ("swagger-ui.html") .addResourceLocations ("classpath:/META-INF/resources/"); registry.addResourceHandler ("/ webjars/**") .addResourceLocations ("classpath:/META-INF/resources/webjars/");}
Countless experiments have found that both methods need to be rewritten, and neither of them will work.
This is the end of the article on "how Spring security opens Swagger access". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.