application.yaml
This commit is contained in:
@@ -22,6 +22,26 @@ services:
|
|||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
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
|
# Spring Boot Application
|
||||||
app:
|
app:
|
||||||
build:
|
build:
|
||||||
@@ -33,11 +53,15 @@ services:
|
|||||||
POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
POSTGRES_PASSWORD: password
|
POSTGRES_PASSWORD: password
|
||||||
SPRING_JPA_HIBERNATE_DDL_AUTO: none
|
SPRING_JPA_HIBERNATE_DDL_AUTO: none
|
||||||
|
MONGODB_URI: mongodb://konturai:konturai2024@mongodb:27017/konturai?authSource=admin
|
||||||
|
MONGODB_DATABASE: konturai
|
||||||
ports:
|
ports:
|
||||||
- '8080:8080'
|
- '8080:8080'
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
mongodb:
|
||||||
|
condition: service_healthy
|
||||||
networks:
|
networks:
|
||||||
- konturai-network
|
- konturai-network
|
||||||
healthcheck:
|
healthcheck:
|
||||||
@@ -49,6 +73,7 @@ services:
|
|||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
|
mongodb_data:
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
konturai-network:
|
konturai-network:
|
||||||
|
|||||||
@@ -106,6 +106,12 @@
|
|||||||
<version>2.2.0</version>
|
<version>2.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Data MongoDB -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<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.AuthenticationEntryPoint;
|
||||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
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
|
@Configuration
|
||||||
@EnableMethodSecurity
|
@EnableMethodSecurity
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
|
|
||||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||||
@Value("${app.cors.allowed-origin:*}")
|
|
||||||
private String allowedOrigin;
|
|
||||||
|
|
||||||
public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter) {
|
public SecurityConfig(JwtAuthenticationFilter jwtAuthenticationFilter) {
|
||||||
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
|
this.jwtAuthenticationFilter = jwtAuthenticationFilter;
|
||||||
@@ -44,7 +37,6 @@ public class SecurityConfig {
|
|||||||
response.getWriter().write("{\"message\":\"Forbidden\"}");
|
response.getWriter().write("{\"message\":\"Forbidden\"}");
|
||||||
};
|
};
|
||||||
http
|
http
|
||||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
|
||||||
.csrf(csrf -> csrf.disable())
|
.csrf(csrf -> csrf.disable())
|
||||||
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
@@ -58,20 +50,6 @@ public class SecurityConfig {
|
|||||||
return http.build();
|
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
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public PasswordEncoder passwordEncoder() {
|
||||||
return new BCryptPasswordEncoder();
|
return new BCryptPasswordEncoder();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ spring:
|
|||||||
init:
|
init:
|
||||||
mode: never
|
mode: never
|
||||||
|
|
||||||
app:
|
data:
|
||||||
cors:
|
mongodb:
|
||||||
allowed-origin: ${CORS_ALLOWED_ORIGIN:*}
|
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