Spring Security で保護された Spring Boot アプリケーションでspringdoc-openapi-ui (OpenAPI 3.0 )への匿名アクセスを許可するにはどうすればよいですか?/swagger-ui.html
5901 次
3 に答える
14
springdoc-openapi-ui を使用するには、 usingメソッド/swagger-ui.html
で次のエンドポイントへの匿名アクセスを許可します。WebSecurityConfigurerAdapter
permitAll
/v3/api-docs/**
/swagger-ui/**
/swagger-ui.html
例:
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.
.authorizeRequests()
.antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-ui.html").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic(); //or anything else, e.g. .oauth2ResourceServer().jwt()
}
}
プロジェクトに次の依存関係があることを確認してください。
于 2020-01-24T14:27:46.630 に答える