I have the springdoc in my application that generates swagger using the default url http://localhost:8090/swagger-ui/index.html If I run the application without docker it works fine, but when using docker it doesn't
Here my dockerfile
FROM openjdk:17
COPY target/subscription-manager-0.0.1-SNAPSHOT.jar subscription-manager.jar
ENTRYPOINT ["java", "-jar", "subscription-manager.jar"]
The docker-compose.yml
services:
subscription-manager_app:
container_name: subscription-manager_app
image: hizam/subscription-manager_app:1.0.0
build: .
ports:
- '8090:8080'
environment:
DATABASE_URL: jdbc:postgresql://db:5432/subscription-manager
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: 1
depends_on:
- db
db:
container_name: db
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 1
POSTGRES_DB: subscription-manager
ports:
- '5333:5432'
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata: { }
Here Iam using securityfilterchain which gives authorization to access swagger as shown in this code
@Configuration
@EnableWebSecurity
@EnableMethodSecurity
@RequiredArgsConstructor
public class SecurityConfiguration {
private final UserService userService;
private final JwtAuthenticationFilter jwtAuthenticationFilter;
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception
{
http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(authorize->
authorize.requestMatchers("/swagger-ui/**","/swagger-resources/*","/v3/api-docs/**")
.permitAll()
.requestMatchers("/api/v1/auth/register","/api/v1/auth/login")
.permitAll()
.anyRequest().authenticated())
.httpBasic(Customizer.withDefaults())
.sessionManagement(session->session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authenticationProvider(authenticationProvider())
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
@Bean
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
daoAuthenticationProvider.setUserDetailsService(userService.userDetailsService());
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder());
return daoAuthenticationProvider;
}
@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception
{
return authenticationConfiguration.getAuthenticationManager();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}