首页 > 解决方案 > 使用 Spring Security 时如何访问我的 swagger-ui

问题描述

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

这是招摇配置

@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/**");
    }

标签: javaspring-securityswagger

解决方案


protected void configure(HttpSecurity httpSecurity)做你对"/register"端点所做的事情。


推荐阅读