有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在使用spring安全性时如何访问我的swaggerui

我试图访问我的大摇大摆的用户界面,但SpringSecurity一直阻止它。我如何防止这种情况

这是昂首阔步的配置

@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();
    }

}

这是Web安全配置

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

共 (1) 个答案

  1. # 1 楼答案

    protected void configure(HttpSecurity httpSecurity)中,执行"/register"端点的操作