Spring Oauth2资源服务器跳过swagger URL-打开API



我需要帮助从安全配置中跳过swagger URL。我在斯塔克夫弗洛尝试了所有的解决方案。以下是我当前的配置。当我试图打开招摇过市的URL 时,我得到了401

public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
private static final String[] AUTH_WHITELIST = {
"/v2/api-docs",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**",
"/v3/api-docs/**",
"/swagger-ui/**", "/configuration/**", "/swagger-ui.html"
};

@Override
protected void configure(HttpSecurity http) throws Exception {
http.
cors().disable().csrf().disable().
authorizeRequests()
.antMatchers(AUTH_WHITELIST).permitAll()
.anyRequest().authenticated()
.and()
.oauth2ResourceServer()
.jwt();
}}

下面是我的OpenAPI配置

@Configuration
@OpenAPIDefinition(servers = { @Server(url = "/", description = "Default Server URL") })
public class SwaggerConfig {
@Bean
public OpenAPI customOpenAPI(@Value("${application-description") String appDesciption,
@Value("${application-version:1.0.0}") String appVersion) {
Contact contact = new Contact();
contact.setEmail("www.abc.com");
contact.setName("abc");
return new OpenAPI()
.info(new Info()
.title("ABC Cloud Application API")
.version(appVersion)
.description(appDesciption)
.contact(contact));
}
}

我使用的是spring-bot版本2.5.8和开放式API版本springdoc openapi ui:1.5.13

试试这个。在tomcat中,我们需要添加WebSecurity

private static final String[] AUTH_WHITELIST = {
"help/**", "swagger**", "swagger-resources/**", "v2/**", "webjars/**"

};

@Overridepublic void configure(WebSecurity-web(throws Exception{

web.ignoring().antMatchers(HttpMethod.GET, AUTH_WHITELIST);

}

最新更新