Java 无需身份验证即可访问Swagger UI Spring Boot
尝试访问此URL时,我收到以下错误http://localhost:8080/swagger-ui.html/ {“错误”:“错误请求”,“消息”:“令牌为空或不以开头。” 持票人,“时间戳”:“2020-10-16T18:06:02.121550”,“状态”:400}Java 无需身份验证即可访问Swagger UI Spring Boot,java,spring-boot,swagger-ui,Java,Spring Boot,Swagger Ui,尝试访问此URL时,我收到以下错误http://localhost:8080/swagger-ui.html/ {“错误”:“错误请求”,“消息”:“令牌为空或不以开头。” 持票人,“时间戳”:“2020-10-16T18:06:02.121550”,“状态”:400} 我怀疑这是由您自定义的jwtAuthFilter造成的。你能把代码贴出来吗?我也很好奇你使用的是什么版本的SpringSecurity?SpringSecurity5内置了对jwt身份验证的支持。看看这个 @Override
我怀疑这是由您自定义的jwtAuthFilter造成的。你能把代码贴出来吗?我也很好奇你使用的是什么版本的SpringSecurity?SpringSecurity5内置了对jwt身份验证的支持。看看这个
@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);
}