I need some help. Below you can see my security config. I want to make localhost:8080/swagger endpoint to be publicly available. When I call swagger ui I am getting Failed to load remote configuration.
What changed in spring boot 3?
@Autowired
private AuthFilter authFilter;
@Bean
@ConditionalOnProperty(name="auth.enabled", havingValue = "true")
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
return httpSecurity
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(hs -> hs.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth-> auth.requestMatchers("/swagger/**","/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui/index.html", "/actuator/health")
.permitAll()
.anyRequest()
.authenticated()
)
.cors(co-> co.configurationSource(corsConfigurationSource()))
.addFilterBefore(authFilter, UsernamePasswordAuthenticationFilter.class)
.build();
}
@Bean
public UrlBasedCorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOriginPatterns(List.of("*")); // Allow all origins
configuration.setAllowedMethods(List.of("GET", "PUT", "POST", "DELETE", "PATCH"));
configuration.setAllowedHeaders(List.of("accept", "Authorization", "Content-Type"));
configuration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}