无需身份验证即可访问Swagger UI Spring Boot

时间:2020-10-16 18:15:01

标签: java spring-boot swagger-ui

尝试访问此URL http:// localhost:8080 / swagger-ui.html /

时收到以下错误

{“错误”:“错误请求”,“消息”:“令牌为空或开头不为 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);
  }

0 个答案:

没有答案