Я нашел решение этой проблемы.Дело в том, что у меня была неправильная конфигурация безопасности в WebSecurityConfigurerAdapter
.Конфигурация защищала любой запрос, подобный этому
http.csrf().disable().authorizeRequests()
.antMatchers("/api/registration/**").permitAll()
.antMatchers("/api/dictionary/**").permitAll()
.antMatchers("/api/common/**").permitAll()
.antMatchers("/api/advert_public/**").permitAll()
.antMatchers("/api/company_public/**").permitAll()
.anyRequest().hasRole(DEFAULT_ROLE)
.and().httpBasic()
.authenticationEntryPoint(authEntryPoint);
И таким образом точка входа Swagger также требует логин / пароль.
Теперь я переписал конфигурацию для защиты определенных методов в моем API, и Swagger работаетотлично
http.csrf().disable().authorizeRequests()
.antMatchers("/api/advert/**").hasRole(DEFAULT_ROLE)
.antMatchers("/api/company/**").hasRole(DEFAULT_ROLE)
.antMatchers("/api/user/**").hasRole(DEFAULT_ROLE)
.and().httpBasic()
.authenticationEntryPoint(authEntryPoint);
Как вы могли видеть, здесь нет опции конфигурации, такой как .anyRequest().hasRole(DEFAULT_ROLE)