application.yaml
This commit is contained in:
@@ -22,6 +22,26 @@ services:
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# MongoDB Database
|
||||
mongodb:
|
||||
image: mongo:7.0
|
||||
container_name: konturai-mongodb
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: konturai
|
||||
MONGO_INITDB_ROOT_PASSWORD: konturai2024
|
||||
MONGO_INITDB_DATABASE: konturai
|
||||
ports:
|
||||
- '27017:27017'
|
||||
volumes:
|
||||
- mongodb_data:/data/db
|
||||
networks:
|
||||
- konturai-network
|
||||
healthcheck:
|
||||
test: ['CMD', 'mongosh', '--eval', 'db.adminCommand("ping")']
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
# Spring Boot Application
|
||||
app:
|
||||
build:
|
||||
@@ -33,11 +53,15 @@ services:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: password
|
||||
SPRING_JPA_HIBERNATE_DDL_AUTO: none
|
||||
MONGODB_URI: mongodb://konturai:konturai2024@mongodb:27017/konturai?authSource=admin
|
||||
MONGODB_DATABASE: konturai
|
||||
ports:
|
||||
- '8080:8080'
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
mongodb:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- konturai-network
|
||||
healthcheck:
|
||||
@@ -49,6 +73,7 @@ services:
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
mongodb_data:
|
||||
|
||||
networks:
|
||||
konturai-network:
|
||||
|
||||
@@ -106,6 +106,12 @@
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Data MongoDB -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -13,19 +13,12 @@ import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
@Configuration
|
||||
@EnableMethodSecurity
|
||||
public class SecurityConfig {
|
||||
|
||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||
@Value("${app.cors.allowed-origin:*}")
|
||||
private String allowedOrigin;
|
||||
|
||||
public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter) {
|
||||
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
|
||||
@@ -44,7 +37,6 @@ public class SecurityConfig {
|
||||
response.getWriter().write("{\"message\":\"Forbidden\"}");
|
||||
};
|
||||
http
|
||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
@@ -58,20 +50,6 @@ public class SecurityConfig {
|
||||
return http.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowedOrigins(List.of(allowedOrigin));
|
||||
config.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"));
|
||||
config.setAllowedHeaders(List.of("Authorization", "Content-Type", "Accept", "X-Requested-With"));
|
||||
config.setExposedHeaders(List.of("Authorization"));
|
||||
config.setAllowCredentials(true);
|
||||
config.setMaxAge(3600L);
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
|
||||
@@ -17,6 +17,7 @@ spring:
|
||||
init:
|
||||
mode: never
|
||||
|
||||
app:
|
||||
cors:
|
||||
allowed-origin: ${CORS_ALLOWED_ORIGIN:*}
|
||||
data:
|
||||
mongodb:
|
||||
uri: ${MONGODB_URI:mongodb://konturai:konturai2024@92.38.48.166:27017/konturai?authSource=admin}
|
||||
database: ${MONGODB_DATABASE:konturai}
|
||||
|
||||
Reference in New Issue
Block a user