Невозможно настроить OpenAPI для RestController в Spring BootJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Невозможно настроить OpenAPI для RestController в Spring Boot

Сообщение Anonymous »

Я пытаюсь настроить OpenAPI. Мое приложение использует порт 9002, и каждый раз, когда я пытаюсь получить доступ к http://localhost:9002/swagger-ui/index.html в браузере, сервер отклоняет мой запрос с кодом 403.
Это мой файл pom.xml:

Код: Выделить всё

org.springframework.boot
spring-boot-starter-parent
3.4.2


...


org.springdoc
springdoc-openapi-starter-webmvc-ui
2.6.0

Код: Выделить всё

application.properties
:

Код: Выделить всё

# OpenApi
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true
Это мой SecurityConfig.java:

Код: Выделить всё

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfig {

@Bean
AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception{
return configuration.getAuthenticationManager();
}

@Bean
AuthenticationProvider authenticationProvider(WeavileUserDetailsImpl weavileUserDetailsImpl) {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(weavileUserDetailsImpl);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}

@Bean
SecurityContextRepository securityContextRepository() {
return new NullSecurityContextRepository();
}

@Bean
PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
configuration.setAllowedOrigins(Arrays.asList(dotenv.get("CLIENT_ALLOWED")));
configuration.setAllowedMethods(Arrays.asList("GET","POST","PUT","DELETE"));
configuration.setAllowCredentials(false);
configuration.addAllowedHeader("*");

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}

@Bean
SecurityFilterChain filterChain(HttpSecurity http, AuthenticationProvider authenticationProvider,
JwtAuthenticationFilter jwtAuthenticationFilter) throws Exception {

http.headers(headersConfigurer -> headersConfigurer.frameOptions(frameOptions -> frameOptions.sameOrigin()));

http.authenticationProvider(authenticationProvider)
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);

http.sessionManagement(httpSecuritySessionManagementConfigurer ->
httpSecuritySessionManagementConfigurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS));

http.authorizeHttpRequests(auth -> auth
.requestMatchers(
"/nonLoggedUsers/**","/pokemonData/**","/natureData/**",
"/itemData/allItems","/something_something/**",
"/v3/api-docs/**","/swagger-ui/**"
).permitAll()
.anyRequest().authenticated()
);

http.cors(cors -> cors.configurationSource(corsConfigurationSource()));
http.csrf(csrf -> csrf.disable());

return http.build();
}
}
Все остальные конечные точки в моей filterChain работают нормально, но когда я пытаюсь получить доступ к OpenAPI, сервер отклоняет их с кодом 403. Почему?


Подробнее здесь: https://stackoverflow.com/questions/798 ... pring-boot
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»