java - 无需身份验证即可访问 Swagger UI Spring Boot
问题描述
尝试访问此 URL http://localhost:8080/swagger-ui.html/ 时收到以下错误
{"error":"Bad Request","message":"令牌为空或不以 Bearer 开头","timestamp":"2020-10-16T18:06:02.121550","status":400}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/v2/api-docs",
"/configuration/ui",
"/swagger-resources",
"/configuration/**",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**",
"/swagger-resources/configuration/ui",
"/swagger-ui.html",
"/swagger-resources/configuration/security")
.permitAll()
.anyRequest()
.authenticated();
// Add our custom JWT security filter
http.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
}
解决方案
推荐阅读
- regex - 在 perl 中读取日志文件并在方括号中找到值
- authentication - Kerberos 中的 401 未授权响应
- java - 使用 RestTemplate 发送 Multipart 文件
- bigcommerce - 基石有没有办法通过 url 注入 html?
- python - 当部分单词包含特殊字符时,Python正则表达式匹配单词边界
- excel - 使用 For 循环选择 Access 中的特定字段并将它们粘贴到 Excel
- java - 当我的布局中的 NestedScrollView 在其下方添加更多小视图时,它变得迟缓
- django - 使用 Django 和 Angular 进行 Windows 身份验证?
- html - 当 col-*-* 存在时,Bootsrap col-* 不起作用,但它应该是默认值
- tensorflow - 交叉熵损失的权重