spring-boot - 401未经授权的页面会 Swagger 吗?

标签 spring-boot swagger swagger-ui swagger-2.0

我通过@ 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/

相关文章:

java - URL 中带点的 Spring MVC 资源映射

java - 如何在 Spring Boot 中获取索引的 json 作为响应?

java - spring-boot中的@ControllerAdvice注释是什么,为什么以及何时使用它?

hashmap - 具有动态键值 HashMap 的 Swagger 复杂响应模型

java - 添加swagger lib后,所有响应内容类型更改为application/xml

rest - 如何在 Springfox 的 Swagger 2 中为 JSONObject 请求正文自定义示例值?

java - Spring Boot 未连接到 RabbitMQ

c# - Swagger UI 显示带有点符号的 asp.net webapi 参数名称

asp.net - Swashbuckle 重命名模型中的数据类型

java - List<String> 属性的 swagger @ApiModelProperty 示例值