【问题标题】:How can i access my swagger-ui when using spring security使用 Spring Security 时如何访问我的 swagger-ui
【发布时间】:2021-09-28 08:11:16
【问题描述】:

我正在尝试访问我的 swagger-ui,但 spring security 一直阻止它。如何防止这种情况发生?

这是swagger配置

@Configuration
public class SwaggerConfig  {

    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.safariwebstore008"))
                .paths(PathSelectors.any())
                .build();
    }

}

这是 webSecurity 配置

 @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
                .csrf().disable()
                .authorizeRequests()
                .antMatchers("/register","/authenticate").permitAll()
                .antMatchers().hasAnyRole()
                .anyRequest().authenticated().and()
                .exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
        httpSecurity.headers().frameOptions().disable();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/v3/api-docs/**", "/swagger-ui.html", "/swagger-ui/**");
    }

【问题讨论】:

    标签: java spring-security swagger


    【解决方案1】:

    protected void configure(HttpSecurity httpSecurity) 中执行您对"/register" 端点所做的操作。

    【讨论】:

      猜你喜欢
      • 2017-05-01
      • 2021-06-03
      • 2018-01-27
      • 2018-09-13
      • 1970-01-01
      • 2020-03-16
      • 2020-05-10
      • 2019-11-02
      • 2022-11-12
      相关资源
      最近更新 更多