首页 > 解决方案 > 无需身份验证即可访问 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);
  }

标签: javaspring-bootswagger-ui

解决方案


推荐阅读