【发布时间】: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