java - 使用 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/**");
}
解决方案
在protected void configure(HttpSecurity httpSecurity)
做你对"/register"
端点所做的事情。
推荐阅读
- android - 在不同的端口运行多个 react-native 应用程序
- django - 在属性 = 值上过滤/排序 django rest api,但属性是值而不是字段
- python - 尝试分析列表列表之间的值
- c# - 如何从 Umbraco 的特定文化中获取内容
- c - 解决访问冲突
- c# - Linq.Dynamic FirstOrDefault() 嵌套在 OrderBy
- node.js - “要求”子流程;如何阻止他们?
- python - 使用嵌套列表附加列表
- javascript - 将 css 更改为“selected=selected value”
- spring-boot - 将 application.properties 中的值外部化(例如 server.port、spring.datasource.url 等)