I created a JWT
project with Java 17 and Spring Boot 3. I was trying to include Swagger UI in my application, but when i try to access the http://localhost:8080/swagger-ui/
, he asks me the credentials to access it.
My code:
@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {
private final JwtAuthenticationFilter jwtAuthFilter;
private final AuthenticationProvider authenticationProvider;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers("/api/v1/auth/**", "/v2/api-docs",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui.html",
"/webjars/**",
"/v3/api-docs/**",
"/swagger-ui/**", "/configuration/**", "/swagger-ui.html").permitAll()
.anyRequest().authenticated()
)
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider)
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
.httpBasic(Customizer.withDefaults());
return http.build();
}
}
My dependencies:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
Any help is highly appreciated.
I already tried to configure the WebConfigSecurity class with the necessary endpoints like it's explained here. I also tried to refactor the method as i've seen on this link and upgraded the springfox version from 2.9.2 to 3.0.0 with no results.
I solved the problem also thanks to @dauthDaert06's comment. I simply changed the dependency, following some tips on this link. SpringFox is not compatible with 3.0.0 and upper Spring Boot versions.