From aabce4d64627048ca1e515d0511852cd975d45ba Mon Sep 17 00:00:00 2001 From: vladp Date: Thu, 4 Dec 2025 15:28:52 +0700 Subject: [PATCH] add cookie --- docker-compose.yaml | 4 -- .../no_copy/configuration/CorsConfig.java | 34 --------------- src/main/resources/application.yaml | 43 +------------------ 3 files changed, 1 insertion(+), 80 deletions(-) delete mode 100644 src/main/java/ru/soune/no_copy/configuration/CorsConfig.java diff --git a/docker-compose.yaml b/docker-compose.yaml index 3884313..13e1b65 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,10 +27,6 @@ services: POSTGRES_PASSWORD: postgres POSTGRES_PORT: 5432 POSTGRES_HOST: db - SERVER_PORT: "8080" - CORS_ALLOWED_ORIGINS: "http://92.242.61.23:2998,http://localhost:3000,http://localhost:2998" - SPRING_SESSION_COOKIE_SAMESITE: none - SPRING_SESSION_COOKIE_SECURE: "false" depends_on: - db ports: diff --git a/src/main/java/ru/soune/no_copy/configuration/CorsConfig.java b/src/main/java/ru/soune/no_copy/configuration/CorsConfig.java deleted file mode 100644 index 0bb8259..0000000 --- a/src/main/java/ru/soune/no_copy/configuration/CorsConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -package ru.soune.no_copy.configuration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; - -import java.util.Arrays; - -@Configuration -public class CorsConfig { - - @Bean - public CorsFilter corsFilter() { - CorsConfiguration config = new CorsConfiguration(); - - config.setAllowedOrigins(Arrays.asList( - "http://92.242.61.23:2998", - "http://localhost:3000", - "http://localhost:2998" - )); - - config.setAllowedMethods(Arrays.asList("*")); - config.setAllowedHeaders(Arrays.asList("*")); - config.setExposedHeaders(Arrays.asList("Set-Cookie", "Authorization")); - config.setAllowCredentials(true); // ВАЖНО! - config.setMaxAge(3600L); - - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", config); - - return new CorsFilter(source); - } -} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index a33cc4c..e1e88fd 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -1,27 +1,4 @@ spring: - session: - timeout: 7d - cookie: - name: SESSION_ID - http-only: true - secure: false - same-site: none - max-age: 604800 - - cors: - allowed-origins: ${CORS_ALLOWED_ORIGINS:http://92.242.61.23:2998,http://localhost:3000} - allowed-methods: GET,POST,PUT,DELETE,OPTIONS,PATCH,HEAD - allowed-headers: "*" - exposed-headers: Set-Cookie,Authorization,Content-Type - allow-credentials: true # ВАЖНО для кук! - max-age: 3600 - - logging: - level: - org.springframework.web.cors: DEBUG - org.springframework.security: DEBUG - org.springframework.web: DEBUG - datasource: url: jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB} username: ${POSTGRES_USER} @@ -32,28 +9,10 @@ spring: hibernate: ddl-auto: update show-sql: true - properties: - hibernate: - format_sql: true server: port: ${SERVER_PORT:8080} - servlet: - session: - cookie: - same-site: none - encoding: - charset: UTF-8 - enabled: true logging: level: - root: INFO - org.springframework.web.cors: TRACE # Более детальные логи - org.springframework.session: DEBUG - pattern: - console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" - file: - name: ./logs/app.log - max-size: 10MB - max-history: 30 \ No newline at end of file + root: INFO \ No newline at end of file