我通过@ EnableSwagger2启用swagger2。但是,当我尝试点击“/swagger-ui.html”时,它首先点击了我的身份验证过滤器。然后,我编写了以下代码来绕过身份验证检查
String resourcePath = new UrlPathHelper().getPathWithinApplication(httpRequest);
if ("/swagger-ui.html".equalsIgnoreCase(resourcePath)) {
filterChain.doFilter(request, response);
}
我可以看到
filterChain.doFilter(request, response);
被击中了。但是,当我放开调试时,它会返回一个页面,其中包含以下信息Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Apr 04 15:41:50 EDT 2018
There was an unexpected error (type=Unauthorized, status=401).
No message available
知道吗,伙计们?
最佳答案
认为您可以添加自己的WebSecurityConfig extends WebSecurityConfigurerAdapter
,而不是重写configure(WebSecurity web)
方法,然后在web.ignoring().antMatchers("/swagger-ui.html")
ofc中使用@Configuration对该类进行注释
关于spring-boot - 401未经授权的页面会 Swagger 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49659409/