http://localhost:8081/v3/api-docs без каких-либо проблем, но для http://localhost:8081/swagger-ui/ index.html#/ Меня продолжают запрашивать учетные данные для входа, хотя API Swagger разрешен через мои средства сопоставления запросов.

Код: Выделить всё
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import static com.francislainy.sobe.enums.UserRole.ADMIN;
import static com.francislainy.sobe.enums.UserRole.USER;
@Configuration
public class WebAuthorizationConfig {
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.cors(Customizer.withDefaults())
.httpBasic(Customizer.withDefaults());
http.authorizeHttpRequests(
c -> c
.requestMatchers(HttpMethod.POST, "/api/v1/test-admin").hasRole(String.valueOf(ADMIN)) //todo: remove this endpoint once new valid endpoints are added - 06/11/2024
.requestMatchers(HttpMethod.GET, "/api/v1/test-user").hasRole(String.valueOf(USER)) //todo: remove this endpoint once new valid endpoints are added - 06/11/2024
.requestMatchers(HttpMethod.POST, "/api/v1/auth/*").permitAll()
.requestMatchers("/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**", "/webjars/**", "/v2/api-docs/**").permitAll() // Allow access to Swagger UI
.anyRequest().authenticated()
);
http.csrf(
c -> c.disable()
);
return http.build();
}
}
Код: Выделить всё
org.springdoc
springdoc-openapi-starter-webmvc-ui
${springdoc-openapi-starter-webmvc-ui.version}
io.swagger.parser.v3
swagger-parser
${swagger-parser.version}
org.yaml
snakeyaml
${snakeyaml.version}
Код: Выделить всё
17
2.6.0
2.0.31
1.32
Весь проект находится здесь:
https://github.com/francislainy/so-be
Спасибо.
PS: Мы используем чванство- Зависимости parser и Snakeyaml, поскольку мы настраиваем Swagger через файл openapi.yml, и без них доступен только /v3/api-docs (с включенной безопасностью или без нее), но проблема все равно возникает без них зависимости при использовании только более простой реализации Swagger по умолчанию.

Подробнее здесь: https://stackoverflow.com/questions/791 ... ugh-spring