From f93e576406ff09c9c928bd2406f39eb86d9bc0c3 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 6 Aug 2024 11:55:19 +0900 Subject: [PATCH 01/53] =?UTF-8?q?[#3]chore:=20=EB=A1=AC=EB=B3=B5=EA=B3=BC?= =?UTF-8?q?=20eureka-client=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index bc785ef..2f52868 100644 --- a/build.gradle +++ b/build.gradle @@ -1,45 +1,49 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.3.2' - id 'io.spring.dependency-management' version '1.1.6' + id 'java' + id 'org.springframework.boot' version '3.3.2' + id 'io.spring.dependency-management' version '1.1.6' } group = 'soma.haeya' version = '0.0.1-SNAPSHOT' java { - toolchain { - languageVersion = JavaLanguageVersion.of(17) - } + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } repositories { - mavenCentral() + mavenCentral() } ext { - set('springCloudVersion', "2023.0.3") + set('springCloudVersion', "2023.0.3") } dependencies { - // spring cloud gateway - implementation 'org.springframework.cloud:spring-cloud-starter-gateway' - - // jjwt + implementation 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + // spring cloud gateway + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' + + // jjwt implementation 'io.jsonwebtoken:jjwt-api:0.12.3' runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3' runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' } dependencyManagement { - imports { - mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" - } + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() } From 31f211b32226ba9ac268debd8cbaac9c3d83116c Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 6 Aug 2024 12:07:51 +0900 Subject: [PATCH 02/53] =?UTF-8?q?[#3]feat:=20=EB=9D=BC=EC=9A=B0=ED=8C=85?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupi_gateway/config/RoutingConfig.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java diff --git a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java new file mode 100644 index 0000000..27087aa --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java @@ -0,0 +1,29 @@ +package soma.haeya.edupi_gateway.config; + +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import soma.haeya.edupi_gateway.filter.AuthenticationFilter; + +@Configuration +public class RoutingConfig { + + @Bean + public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFilter authorizationFilter) { + return builder.routes() + + .route(predicate -> predicate.path("/edupi_visualize/**") + .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) + .uri("http://localhost:8081/")) // code_visualize + + .route(predicate -> predicate.path("/edupi_user/**") + .uri("http://localhost:8083/")) // edupi_user + + .route(predicate -> predicate.path("/edupi_db/**") + .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) + .uri("http://localhost:8084/")) // edupi_db + .build(); + } + +} From e8807d96c64aaa57d51e3d111691e1e351a24eef Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 6 Aug 2024 12:08:01 +0900 Subject: [PATCH 03/53] =?UTF-8?q?[#3]feat:=20cors=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupi_gateway/config/SecurityConfig.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java diff --git a/src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java new file mode 100644 index 0000000..21355f3 --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java @@ -0,0 +1,18 @@ +package soma.haeya.edupi_gateway.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class SecurityConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins("*") + .allowedMethods("*") + .allowedHeaders("*"); + } + +} From 1396129f6f57a2f0dd25ac06bec721b5cd25b4e1 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 6 Aug 2024 12:11:37 +0900 Subject: [PATCH 04/53] =?UTF-8?q?[#3]feat:=20jwt=20=EC=9D=B8=EA=B0=80=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=95=88?= =?UTF-8?q?=ED=95=98=EB=A9=B4=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupi_gateway/auth/TokenProvider.java | 41 +++++++++++ .../edupi_gateway/dto/ErrorResponse.java | 5 ++ .../exception/GlobalExceptionHandler.java | 24 +++++++ .../exception/UnAuthorizedException.java | 13 ++++ .../filter/AuthenticationFilter.java | 71 +++++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java create mode 100644 src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java create mode 100644 src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java create mode 100644 src/main/java/soma/haeya/edupi_gateway/exception/UnAuthorizedException.java create mode 100644 src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java diff --git a/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java b/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java new file mode 100644 index 0000000..ee0d941 --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java @@ -0,0 +1,41 @@ +package soma.haeya.edupi_gateway.auth; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.JwtException; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.io.Decoders; +import io.jsonwebtoken.security.Keys; +import java.util.Date; +import javax.crypto.SecretKey; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; +import soma.haeya.edupi_gateway.exception.UnAuthorizedException; + +@Component +public class TokenProvider { + + private final SecretKey key; + + public TokenProvider(@Value("${jwt.secret}") String secret) { + byte[] keyBytes = Decoders.BASE64.decode(secret); + this.key = Keys.hmacShaKeyFor(keyBytes); + } + + public void validateToken(String token) { + Claims claims = getClaims(token); + + if (claims.getExpiration().before(new Date())) { + throw new UnAuthorizedException(HttpStatus.UNAUTHORIZED, "토큰이 유효하지 않습니다."); + } + } + + private Claims getClaims(String token) { + try { + return Jwts.parser().verifyWith(key).build().parseSignedClaims(token).getPayload(); + } catch (JwtException e) { + throw new UnAuthorizedException(HttpStatus.UNAUTHORIZED, "토큰이 유효하지 않습니다."); + } + } + +} diff --git a/src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java b/src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java new file mode 100644 index 0000000..31b50c1 --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java @@ -0,0 +1,5 @@ +package soma.haeya.edupi_gateway.dto; + +public record ErrorResponse(String message) { + +} diff --git a/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java b/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..02d23bc --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java @@ -0,0 +1,24 @@ +package soma.haeya.edupi_gateway.exception; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import soma.haeya.edupi_gateway.dto.ErrorResponse; + +@Slf4j +@RestControllerAdvice +public class GlobalExceptionHandler { + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(UnAuthorizedException.class) + public ResponseEntity handleValidationExceptions(UnAuthorizedException ex) { + + return ResponseEntity + .status(HttpStatus.BAD_REQUEST) + .body(new ErrorResponse(ex.getReason())); + } + +} diff --git a/src/main/java/soma/haeya/edupi_gateway/exception/UnAuthorizedException.java b/src/main/java/soma/haeya/edupi_gateway/exception/UnAuthorizedException.java new file mode 100644 index 0000000..2df90d3 --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/exception/UnAuthorizedException.java @@ -0,0 +1,13 @@ +package soma.haeya.edupi_gateway.exception; + +import lombok.Getter; +import org.springframework.http.HttpStatus; +import org.springframework.web.server.ResponseStatusException; + +@Getter +public class UnAuthorizedException extends ResponseStatusException { + + public UnAuthorizedException(HttpStatus status, String message) { + super(status, message); + } +} diff --git a/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java b/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java new file mode 100644 index 0000000..b401ac1 --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java @@ -0,0 +1,71 @@ +package soma.haeya.edupi_gateway.filter; + +import java.util.Optional; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +import org.springframework.http.HttpCookie; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.util.MultiValueMap; +import soma.haeya.edupi_gateway.auth.TokenProvider; +import soma.haeya.edupi_gateway.exception.UnAuthorizedException; + +@Slf4j +@Component +public class AuthenticationFilter extends AbstractGatewayFilterFactory { + + private final TokenProvider jwtProvider; + + public AuthenticationFilter(TokenProvider jwtProvider) { + super(Config.class); + this.jwtProvider = jwtProvider; + } + + @Setter + @Getter + public static class Config { + + private String requiredRole; + + } + + @Override + public GatewayFilter apply(Config config) throws NullPointerException { + return ((exchange, chain) -> { + ServerHttpRequest request = exchange.getRequest(); + + MultiValueMap cookies = request.getCookies(); + + String token = extractToken(cookies); + + if (!isJwtValid(token)) { + throw new UnAuthorizedException(HttpStatus.UNAUTHORIZED, "토큰이 유효하지 않습니다."); + } + + return chain.filter(exchange); + }); + + } + + // cookies에서 token을 추출하는 메서드 + public String extractToken(MultiValueMap cookies) { + return Optional.ofNullable(cookies.getFirst("token")) + .map(HttpCookie::getValue) + .orElseThrow(() -> new UnAuthorizedException(HttpStatus.UNAUTHORIZED, "토큰이 없습니다.")); + } + + private boolean isJwtValid(String token) { + try { + jwtProvider.validateToken(token); + return true; + } catch (Exception e) { + return false; + } + + } + +} From 03b99b30795b5a4e64bd5d759a2fc3b1d120dbfb Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 6 Aug 2024 13:37:13 +0900 Subject: [PATCH 05/53] =?UTF-8?q?[#3]feat:=20=EB=AA=A8=EB=93=A0=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=EC=97=90=20=EB=8C=80=ED=95=B4=20log=EB=A5=BC?= =?UTF-8?q?=20=EC=B0=8D=EC=96=B4=EC=A3=BC=EB=8A=94=20filter=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../filter/RequestLoggingFilter.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/main/java/soma/haeya/edupi_gateway/filter/RequestLoggingFilter.java diff --git a/src/main/java/soma/haeya/edupi_gateway/filter/RequestLoggingFilter.java b/src/main/java/soma/haeya/edupi_gateway/filter/RequestLoggingFilter.java new file mode 100644 index 0000000..ee0977e --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/filter/RequestLoggingFilter.java @@ -0,0 +1,54 @@ +package soma.haeya.edupi_gateway.filter; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.cloud.gateway.filter.factory.rewrite.ModifyRequestBodyGatewayFilterFactory; +import org.springframework.core.Ordered; +import org.springframework.http.server.reactive.ServerHttpRequest; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +@Slf4j +@Component +@RequiredArgsConstructor +public class RequestLoggingFilter implements GlobalFilter, Ordered { + + private final ModifyRequestBodyGatewayFilterFactory modifyRequestBodyGatewayFilterFactory; + + private static void logRequest(final ServerHttpRequest request, final String body) { + + log.info("Request Id: {}, URI: {}, Headers: {}, QueryParams: {}, Body: {}", + request.getId(), + request.getURI(), + request.getHeaders(), + request.getQueryParams(), + body); + } + + @Override + public Mono filter(final ServerWebExchange exchange, final GatewayFilterChain chain) { + + return modifyRequestBodyGatewayFilterFactory + .apply(modifyRequestBodyGatewayFilterConfig()) + .filter(exchange, chain); + } + + @Override + public int getOrder() { + + return Ordered.HIGHEST_PRECEDENCE; + } + + private ModifyRequestBodyGatewayFilterFactory.Config modifyRequestBodyGatewayFilterConfig() { + + return new ModifyRequestBodyGatewayFilterFactory.Config() + .setRewriteFunction(String.class, String.class, (exchange, body) -> { + logRequest(exchange.getRequest(), body); + return Mono.justOrEmpty(body); + } + ); + } +} From 954d796f035a8ae212c67035d5c3968c72988fcb Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 8 Aug 2024 13:07:37 +0900 Subject: [PATCH 06/53] =?UTF-8?q?[#3]remove:=20eureka=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2f52868..8e8b711 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,6 @@ dependencies { // spring cloud gateway implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.cloud:spring-cloud-starter-gateway' - implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' // jjwt implementation 'io.jsonwebtoken:jjwt-api:0.12.3' From f3dbbbb05280e1e9cfdbeba2086e7e849112b3ef Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 8 Aug 2024 13:07:52 +0900 Subject: [PATCH 07/53] [#3]style: record -> class --- .../java/soma/haeya/edupi_gateway/dto/ErrorResponse.java | 5 ----- .../soma/haeya/edupi_gateway/models/ErrorResponse.java | 9 +++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) delete mode 100644 src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java create mode 100644 src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java diff --git a/src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java b/src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java deleted file mode 100644 index 31b50c1..0000000 --- a/src/main/java/soma/haeya/edupi_gateway/dto/ErrorResponse.java +++ /dev/null @@ -1,5 +0,0 @@ -package soma.haeya.edupi_gateway.dto; - -public record ErrorResponse(String message) { - -} diff --git a/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java b/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java new file mode 100644 index 0000000..d930355 --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java @@ -0,0 +1,9 @@ +package soma.haeya.edupi_gateway.models; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class ErrorResponse { + + private final String message; +} From 36390f4bee784fce9c1c51b7743cff30c268ea20 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 8 Aug 2024 13:08:14 +0900 Subject: [PATCH 08/53] =?UTF-8?q?[#3]style:=20config=20=ED=95=98=EB=93=9C?= =?UTF-8?q?=EC=BD=94=EB=94=A9=EC=9D=84=20yml=ED=8C=8C=EC=9D=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupi_gateway/config/RoutingConfig.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java index 27087aa..e938417 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java @@ -1,5 +1,6 @@ package soma.haeya.edupi_gateway.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.gateway.route.RouteLocator; import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.context.annotation.Bean; @@ -9,20 +10,36 @@ @Configuration public class RoutingConfig { + @Value("${server-url.db.url}") + private String DB_URL; + @Value("${server-url.db.default-path}") + private String DB_PATH; + + @Value("${server-url.user.url}") + private String USER_URL; + @Value("${server-url.user.default-path}") + private String USER_PATH; + + @Value("${server-url.visualize.url}") + private String VISUALIZE_URL; + @Value("${server-url.visualize.default-path}") + private String VISUALIZE_PATH; + + @Bean public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFilter authorizationFilter) { return builder.routes() - .route(predicate -> predicate.path("/edupi_visualize/**") + .route(predicate -> predicate.path(VISUALIZE_PATH) .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) - .uri("http://localhost:8081/")) // code_visualize + .uri(VISUALIZE_URL)) // code_visualize - .route(predicate -> predicate.path("/edupi_user/**") - .uri("http://localhost:8083/")) // edupi_user + .route(predicate -> predicate.path(USER_PATH) + .uri(USER_URL)) // edupi_user + + .route(predicate -> predicate.path(DB_PATH) + .uri(DB_URL)) // edupi_db - .route(predicate -> predicate.path("/edupi_db/**") - .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) - .uri("http://localhost:8084/")) // edupi_db .build(); } From 5b1d465f2b12d11824ebd177f1669b4bf6c28130 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 8 Aug 2024 13:10:47 +0900 Subject: [PATCH 09/53] =?UTF-8?q?[#3]remove:=20=EC=A4=91=EB=B3=B5=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../haeya/edupi_gateway/exception/GlobalExceptionHandler.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java b/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java index 02d23bc..838ac9b 100644 --- a/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java +++ b/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java @@ -4,15 +4,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; -import soma.haeya.edupi_gateway.dto.ErrorResponse; +import soma.haeya.edupi_gateway.models.ErrorResponse; @Slf4j @RestControllerAdvice public class GlobalExceptionHandler { - @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(UnAuthorizedException.class) public ResponseEntity handleValidationExceptions(UnAuthorizedException ex) { From 5b51a90580d826654700a67df3ae757910302566 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Sat, 17 Aug 2024 18:28:11 +0900 Subject: [PATCH 10/53] =?UTF-8?q?[#5]chore:=20health=20check=20=EC=9A=A9?= =?UTF-8?q?=EB=8F=84=EC=9D=98=20/=20=EB=9D=BC=EC=9A=B0=ED=8C=85=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/soma/haeya/edupi_gateway/config/RoutingConfig.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java index e938417..be86c60 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java @@ -29,7 +29,9 @@ public class RoutingConfig { @Bean public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFilter authorizationFilter) { return builder.routes() - + .route("root_route", r -> r.path("/") + .filters(f -> f.setStatus(200)) + .uri("no://op")) // health check .route(predicate -> predicate.path(VISUALIZE_PATH) .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) .uri(VISUALIZE_URL)) // code_visualize From 07fa41be8a31bb4824b977f09957d7f9909e718a Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Sat, 17 Aug 2024 18:28:26 +0900 Subject: [PATCH 11/53] =?UTF-8?q?[#5]chore:=20=EA=B8=B0=EB=B3=B8=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20dockerfile=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ec9b4d2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM openjdk:17 + +ARG JAR_FILE=build/libs/*.jar + +COPY ${JAR_FILE} app.jar + +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file From 0d81eb3b8e87936ce7cbc90fb0870163e643290c Mon Sep 17 00:00:00 2001 From: GS_song <105411445+SongGwanSeok@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:03:06 +0900 Subject: [PATCH 12/53] Create cicd-dev.yml --- ".github/workflows/\bcicd-dev.yml" | 111 +++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 ".github/workflows/\bcicd-dev.yml" diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" new file mode 100644 index 0000000..45edce0 --- /dev/null +++ "b/.github/workflows/\bcicd-dev.yml" @@ -0,0 +1,111 @@ +# This workflow will build and push a new container image to Amazon ECR, +# and then will deploy a new task definition to Amazon ECS, when there is a push to the "develop" branch. +# +# To use this workflow, you will need to complete the following set-up steps: +# +# 1. Create an ECR repository to store your images. +# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. +# Replace the value of the `ECR_REPOSITORY` environment variable in the workflow below with your repository's name. +# Replace the value of the `AWS_REGION` environment variable in the workflow below with your repository's region. +# +# 2. Create an ECS task definition, an ECS cluster, and an ECS service. +# For example, follow the Getting Started guide on the ECS console: +# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun +# Replace the value of the `ECS_SERVICE` environment variable in the workflow below with the name you set for the Amazon ECS service. +# Replace the value of the `ECS_CLUSTER` environment variable in the workflow below with the name you set for the cluster. +# +# 3. Store your ECS task definition as a JSON file in your repository. +# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. +# Replace the value of the `ECS_TASK_DEFINITION` environment variable in the workflow below with the path to the JSON file. +# Replace the value of the `CONTAINER_NAME` environment variable in the workflow below with the name of the container +# in the `containerDefinitions` section of the task definition. +# +# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. +# See the documentation for each action used below for the recommended IAM policies for this IAM user, +# and best practices on handling the access key credentials. + +name: Deploy to Amazon ECS + +on: + push: + branches: [ "develop" ] + +env: + AWS_REGION: ap-northeast-2 + ECR_REPOSITORY: edupi_gateway + ECS_SERVICE: gateway + ECS_CLUSTER: BE + ECS_TASK_DEFINITION: edupi_gateway-revision.json + CONTAINER_NAME: gateway + +permissions: + contents: read + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Copy Secret yml + env: + CREATE_SECRET: ${{secrets.EDUPI_GATEWAY_DEV_APPLICATION_YML}} + CREATE_SECRET_DIR: src/main/resources + CREATE_SECRET_DIR_FILE_NAME: application.yml + run: echo $CREATE_SECRET | base64 --decode > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME + + - name: Build with Gradle + run: ./gradlew build + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ID }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + + - name: Fill in the new image ID in the Amazon ECS task definition + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: ${{ env.ECS_TASK_DEFINITION }} + container-name: ${{ env.CONTAINER_NAME }} + image: ${{ steps.build-image.outputs.image }} + + - name: Deploy Amazon ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.task-def.outputs.task-definition }} + service: ${{ env.ECS_SERVICE }} + cluster: ${{ env.ECS_CLUSTER }} + wait-for-service-stability: true From 08fd9c43c99b8920dcd9d35bb7c4a390ced8919a Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 10:44:41 +0900 Subject: [PATCH 13/53] =?UTF-8?q?[#1]deploy:=20gateway=20ecs=20task=20json?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- edupi_gateway-revision.json | 91 +++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 edupi_gateway-revision.json diff --git a/edupi_gateway-revision.json b/edupi_gateway-revision.json new file mode 100644 index 0000000..5cfd5ef --- /dev/null +++ b/edupi_gateway-revision.json @@ -0,0 +1,91 @@ +{ + "taskDefinitionArn": "arn:aws:ecs:ap-northeast-2:590184013289:task-definition/edupi_gateway:12", + "containerDefinitions": [ + { + "name": "gateway", + "image": "590184013289.dkr.ecr.ap-northeast-2.amazonaws.com/edupi_gateway:latest", + "cpu": 0, + "portMappings": [ + { + "name": "gateway-port", + "containerPort": 8080, + "hostPort": 8080, + "protocol": "tcp", + "appProtocol": "http" + } + ], + "essential": true, + "environment": [], + "environmentFiles": [], + "mountPoints": [], + "volumesFrom": [], + "ulimits": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "/ecs/edupi_gateway", + "mode": "non-blocking", + "awslogs-create-group": "true", + "max-buffer-size": "25m", + "awslogs-region": "ap-northeast-2", + "awslogs-stream-prefix": "ecs" + }, + "secretOptions": [] + }, + "systemControls": [] + } + ], + "family": "edupi_gateway", + "executionRoleArn": "arn:aws:iam::590184013289:role/ecsTaskExecutionRole", + "networkMode": "awsvpc", + "revision": 12, + "volumes": [], + "status": "ACTIVE", + "requiresAttributes": [ + { + "name": "com.amazonaws.ecs.capability.logging-driver.awslogs" + }, + { + "name": "ecs.capability.execution-role-awslogs" + }, + { + "name": "com.amazonaws.ecs.capability.ecr-auth" + }, + { + "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19" + }, + { + "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28" + }, + { + "name": "ecs.capability.execution-role-ecr-pull" + }, + { + "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" + }, + { + "name": "ecs.capability.task-eni" + }, + { + "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29" + } + ], + "placementConstraints": [], + "compatibilities": [ + "EC2", + "FARGATE" + ], + "requiresCompatibilities": [ + "EC2", + "FARGATE" + ], + "cpu": "512", + "memory": "1024", + "runtimePlatform": { + "cpuArchitecture": "X86_64", + "operatingSystemFamily": "LINUX" + }, + "registeredAt": "2024-08-15T14:05:44.934Z", + "registeredBy": "arn:aws:iam::590184013289:user/gwanseok", + "tags": [] +} \ No newline at end of file From f15aaa20091a1de752906ac07e47336ede841ec3 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 10:42:28 +0900 Subject: [PATCH 14/53] =?UTF-8?q?[#9]deploy:=20CORS=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20reactive=20=EB=B0=A9=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupi_gateway/config/CorsConfig.java | 34 +++++++++++++++++++ .../edupi_gateway/config/SecurityConfig.java | 18 ---------- 2 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java delete mode 100644 src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java diff --git a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java new file mode 100644 index 0000000..69a0867 --- /dev/null +++ b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java @@ -0,0 +1,34 @@ +package soma.haeya.edupi_gateway.config; + +import java.util.List; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.reactive.CorsConfigurationSource; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; + +@Configuration +public class CorsConfig { + + @Bean + public CorsWebFilter corsWebFilter() { + return new CorsWebFilter(corsConfigurationSource()); + } + + @Bean + public CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.setAllowedOrigins(List.of("*")); + configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); + configuration.setAllowedHeaders(List.of("*")); + configuration.setAllowCredentials(true); + configuration.setMaxAge(3600L); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + + return source; + } + +} diff --git a/src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java deleted file mode 100644 index 21355f3..0000000 --- a/src/main/java/soma/haeya/edupi_gateway/config/SecurityConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package soma.haeya.edupi_gateway.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class SecurityConfig implements WebMvcConfigurer { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOrigins("*") - .allowedMethods("*") - .allowedHeaders("*"); - } - -} From 16d9670d466be9f1f877be1d2df9e28448182f39 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 10:55:53 +0900 Subject: [PATCH 15/53] =?UTF-8?q?[#1]deploy:=20cicd=20=ED=8C=8C=EC=9D=B4?= =?UTF-8?q?=ED=94=84=EB=9D=BC=EC=9D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ".github/workflows/\bcicd-dev.yml" | 144 ++++++++++++----------------- 1 file changed, 59 insertions(+), 85 deletions(-) diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" index 45edce0..842b386 100644 --- "a/.github/workflows/\bcicd-dev.yml" +++ "b/.github/workflows/\bcicd-dev.yml" @@ -1,29 +1,3 @@ -# This workflow will build and push a new container image to Amazon ECR, -# and then will deploy a new task definition to Amazon ECS, when there is a push to the "develop" branch. -# -# To use this workflow, you will need to complete the following set-up steps: -# -# 1. Create an ECR repository to store your images. -# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. -# Replace the value of the `ECR_REPOSITORY` environment variable in the workflow below with your repository's name. -# Replace the value of the `AWS_REGION` environment variable in the workflow below with your repository's region. -# -# 2. Create an ECS task definition, an ECS cluster, and an ECS service. -# For example, follow the Getting Started guide on the ECS console: -# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun -# Replace the value of the `ECS_SERVICE` environment variable in the workflow below with the name you set for the Amazon ECS service. -# Replace the value of the `ECS_CLUSTER` environment variable in the workflow below with the name you set for the cluster. -# -# 3. Store your ECS task definition as a JSON file in your repository. -# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. -# Replace the value of the `ECS_TASK_DEFINITION` environment variable in the workflow below with the path to the JSON file. -# Replace the value of the `CONTAINER_NAME` environment variable in the workflow below with the name of the container -# in the `containerDefinitions` section of the task definition. -# -# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. -# See the documentation for each action used below for the recommended IAM policies for this IAM user, -# and best practices on handling the access key credentials. - name: Deploy to Amazon ECS on: @@ -31,12 +5,12 @@ on: branches: [ "develop" ] env: - AWS_REGION: ap-northeast-2 - ECR_REPOSITORY: edupi_gateway - ECS_SERVICE: gateway - ECS_CLUSTER: BE - ECS_TASK_DEFINITION: edupi_gateway-revision.json - CONTAINER_NAME: gateway + AWS_REGION: ap-northeast-2 + ECR_REPOSITORY: edupi_gateway + ECS_SERVICE: gateway + ECS_CLUSTER: BE + ECS_TASK_DEFINITION: edupi_gateway-revision.json + CONTAINER_NAME: gateway permissions: contents: read @@ -48,64 +22,64 @@ jobs: environment: production steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' - - name: Grant execute permission for gradlew - run: chmod +x gradlew + - name: Grant execute permission for gradlew + run: chmod +x gradlew - - name: Copy Secret yml - env: - CREATE_SECRET: ${{secrets.EDUPI_GATEWAY_DEV_APPLICATION_YML}} - CREATE_SECRET_DIR: src/main/resources - CREATE_SECRET_DIR_FILE_NAME: application.yml - run: echo $CREATE_SECRET | base64 --decode > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME + - name: Copy Secret yml + env: + CREATE_SECRET: ${{secrets.EDUPI_GATEWAY_DEV_APPLICATION_YML}} + CREATE_SECRET_DIR: src/main/resources + CREATE_SECRET_DIR_FILE_NAME: application.yml + run: echo $CREATE_SECRET > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME - - name: Build with Gradle - run: ./gradlew build + - name: Build with Gradle + run: ./gradlew build - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ID }} - aws-region: ${{ env.AWS_REGION }} + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_ID }} + aws-region: ${{ env.AWS_REGION }} - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 - - name: Build, tag, and push image to Amazon ECR - id: build-image - env: - ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - IMAGE_TAG: ${{ github.sha }} - run: | - # Build a docker container and - # push it to ECR so that it can - # be deployed to ECS. - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG - echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + run: | + # Build a docker container and + # push it to ECR so that it can + # be deployed to ECS. + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT - - name: Fill in the new image ID in the Amazon ECS task definition - id: task-def - uses: aws-actions/amazon-ecs-render-task-definition@v1 - with: - task-definition: ${{ env.ECS_TASK_DEFINITION }} - container-name: ${{ env.CONTAINER_NAME }} - image: ${{ steps.build-image.outputs.image }} + - name: Fill in the new image ID in the Amazon ECS task definition + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: ${{ env.ECS_TASK_DEFINITION }} + container-name: ${{ env.CONTAINER_NAME }} + image: ${{ steps.build-image.outputs.image }} - - name: Deploy Amazon ECS task definition - uses: aws-actions/amazon-ecs-deploy-task-definition@v1 - with: - task-definition: ${{ steps.task-def.outputs.task-definition }} - service: ${{ env.ECS_SERVICE }} - cluster: ${{ env.ECS_CLUSTER }} - wait-for-service-stability: true + - name: Deploy Amazon ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v1 + with: + task-definition: ${{ steps.task-def.outputs.task-definition }} + service: ${{ env.ECS_SERVICE }} + cluster: ${{ env.ECS_CLUSTER }} + wait-for-service-stability: true From 29f9756b91cf00ae5520463f5c333d2cef350c64 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 11:02:55 +0900 Subject: [PATCH 16/53] =?UTF-8?q?[#1]deploy:=20src/main/resources=EC=97=90?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=EC=9D=B4=20=EC=97=86=EC=96=B4=EC=84=9C=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=EA=B0=80=20git=EC=97=90=20=EC=97=86=EB=8A=94?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/resources/.gitkeep diff --git a/src/main/resources/.gitkeep b/src/main/resources/.gitkeep new file mode 100644 index 0000000..e69de29 From e3e8e13081ee64b0a38d947995709f212cfc93eb Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 13:46:59 +0900 Subject: [PATCH 17/53] =?UTF-8?q?[#1]deploy:=20scr/main/resources=EC=97=90?= =?UTF-8?q?=20=EC=9E=88=EB=8A=94=20yml=ED=8C=8C=EC=9D=BC=EB=A7=8C=20git?= =?UTF-8?q?=EC=97=90=20=EC=95=88=EC=98=AC=EB=9D=BC=EA=B0=80=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ed62916..e4a8b83 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ out/ ### VS Code ### .vscode/ -*.yml +src/main/resources/*.yml application.properties .DS_Store From 82425c7ac94c614038e68abc5f99fc57199e3280 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 13:47:35 +0900 Subject: [PATCH 18/53] =?UTF-8?q?[#1]deploy:=20pull=20request=EB=A5=BC=20?= =?UTF-8?q?=EC=98=AC=EB=A0=B8=EC=9D=84=20=EB=95=8C=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-build.yml | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/pull-request-build.yml diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml new file mode 100644 index 0000000..6b7bae0 --- /dev/null +++ b/.github/workflows/pull-request-build.yml @@ -0,0 +1,47 @@ +name: Deploy to Amazon ECS + +on: + push: + branches: [ "develop" ] + +env: + AWS_REGION: ap-northeast-2 + ECR_REPOSITORY: edupi_gateway + ECS_SERVICE: gateway + ECS_CLUSTER: BE + ECS_TASK_DEFINITION: edupi_gateway-revision.json + CONTAINER_NAME: gateway + +permissions: + contents: read + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Copy Secret yml + env: + CREATE_SECRET: ${{secrets.EDUPI_GATEWAY_DEV_APPLICATION_YML}} + CREATE_SECRET_DIR: src/main/resources + CREATE_SECRET_DIR_FILE_NAME: application.yml + run: echo $CREATE_SECRET > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build + + From 8c40f7d8cc91e86e492cb3e9e5dafd80d6741b53 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 13:48:02 +0900 Subject: [PATCH 19/53] =?UTF-8?q?[#1]deploy:=20gradlew=20=EA=B6=8C?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=88=9C=EC=84=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ".github/workflows/\bcicd-dev.yml" | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" index 842b386..9b62ee2 100644 --- "a/.github/workflows/\bcicd-dev.yml" +++ "b/.github/workflows/\bcicd-dev.yml" @@ -31,9 +31,6 @@ jobs: java-version: '17' distribution: 'temurin' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Copy Secret yml env: CREATE_SECRET: ${{secrets.EDUPI_GATEWAY_DEV_APPLICATION_YML}} @@ -41,6 +38,9 @@ jobs: CREATE_SECRET_DIR_FILE_NAME: application.yml run: echo $CREATE_SECRET > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle run: ./gradlew build From 452da7f323f0e0dcb6daba29f28aeb79d1f21632 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 13:59:28 +0900 Subject: [PATCH 20/53] =?UTF-8?q?[#1]deploy:=20secret=20yml=20decoding=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml index 6b7bae0..0ca468f 100644 --- a/.github/workflows/pull-request-build.yml +++ b/.github/workflows/pull-request-build.yml @@ -36,7 +36,7 @@ jobs: CREATE_SECRET: ${{secrets.EDUPI_GATEWAY_DEV_APPLICATION_YML}} CREATE_SECRET_DIR: src/main/resources CREATE_SECRET_DIR_FILE_NAME: application.yml - run: echo $CREATE_SECRET > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME + run: echo $CREATE_SECRET | base64 --decode > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME - name: Grant execute permission for gradlew run: chmod +x gradlew From 776ee6d98224bedfb7863609ad4592e6bd96053e Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 13:59:55 +0900 Subject: [PATCH 21/53] =?UTF-8?q?[#1]deploy:=20push=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=88=EB=9D=BC=20pull=20request=EB=A1=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml index 0ca468f..36858a0 100644 --- a/.github/workflows/pull-request-build.yml +++ b/.github/workflows/pull-request-build.yml @@ -1,7 +1,7 @@ name: Deploy to Amazon ECS on: - push: + pull_request: branches: [ "develop" ] env: From f0fc71323a368744cdad3ccb2b238ccb7c46b9b8 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 14:05:48 +0900 Subject: [PATCH 22/53] =?UTF-8?q?[#1]deploy:=20cicd=EB=8F=84=20decoding=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ".github/workflows/\bcicd-dev.yml" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" index 9b62ee2..6a99028 100644 --- "a/.github/workflows/\bcicd-dev.yml" +++ "b/.github/workflows/\bcicd-dev.yml" @@ -36,7 +36,7 @@ jobs: CREATE_SECRET: ${{secrets.EDUPI_GATEWAY_DEV_APPLICATION_YML}} CREATE_SECRET_DIR: src/main/resources CREATE_SECRET_DIR_FILE_NAME: application.yml - run: echo $CREATE_SECRET > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME + run: echo $CREATE_SECRET | base64 --decode > $CREATE_SECRET_DIR/$CREATE_SECRET_DIR_FILE_NAME - name: Grant execute permission for gradlew run: chmod +x gradlew From b28032bf304bf52a56475523ac102aae62b1bee6 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 18:38:56 +0900 Subject: [PATCH 23/53] =?UTF-8?q?[#1]deploy:=20pull=20request=20action=20n?= =?UTF-8?q?ame=20=EC=88=98=EC=A0=95,=20ecs=20task=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=EC=97=86=EB=8A=94=20=EC=A0=95=EB=B3=B4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-build.yml | 2 +- edupi_gateway-revision.json | 138 ++++++++--------------- 2 files changed, 51 insertions(+), 89 deletions(-) diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml index 36858a0..6a09443 100644 --- a/.github/workflows/pull-request-build.yml +++ b/.github/workflows/pull-request-build.yml @@ -1,4 +1,4 @@ -name: Deploy to Amazon ECS +name: Pull Request build on: pull_request: diff --git a/edupi_gateway-revision.json b/edupi_gateway-revision.json index 5cfd5ef..e54a931 100644 --- a/edupi_gateway-revision.json +++ b/edupi_gateway-revision.json @@ -1,91 +1,53 @@ { - "taskDefinitionArn": "arn:aws:ecs:ap-northeast-2:590184013289:task-definition/edupi_gateway:12", - "containerDefinitions": [ - { - "name": "gateway", - "image": "590184013289.dkr.ecr.ap-northeast-2.amazonaws.com/edupi_gateway:latest", - "cpu": 0, - "portMappings": [ - { - "name": "gateway-port", - "containerPort": 8080, - "hostPort": 8080, - "protocol": "tcp", - "appProtocol": "http" - } - ], - "essential": true, - "environment": [], - "environmentFiles": [], - "mountPoints": [], - "volumesFrom": [], - "ulimits": [], - "logConfiguration": { - "logDriver": "awslogs", - "options": { - "awslogs-group": "/ecs/edupi_gateway", - "mode": "non-blocking", - "awslogs-create-group": "true", - "max-buffer-size": "25m", - "awslogs-region": "ap-northeast-2", - "awslogs-stream-prefix": "ecs" - }, - "secretOptions": [] - }, - "systemControls": [] - } - ], - "family": "edupi_gateway", - "executionRoleArn": "arn:aws:iam::590184013289:role/ecsTaskExecutionRole", - "networkMode": "awsvpc", - "revision": 12, - "volumes": [], - "status": "ACTIVE", - "requiresAttributes": [ - { - "name": "com.amazonaws.ecs.capability.logging-driver.awslogs" - }, - { - "name": "ecs.capability.execution-role-awslogs" - }, - { - "name": "com.amazonaws.ecs.capability.ecr-auth" - }, - { - "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19" - }, - { - "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28" - }, - { - "name": "ecs.capability.execution-role-ecr-pull" - }, - { - "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" - }, - { - "name": "ecs.capability.task-eni" - }, - { - "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29" + "containerDefinitions": [ + { + "name": "gateway", + "image": "590184013289.dkr.ecr.ap-northeast-2.amazonaws.com/edupi_gateway:latest", + "cpu": 0, + "portMappings": [ + { + "name": "gateway-port", + "containerPort": 8080, + "hostPort": 8080, + "protocol": "tcp", + "appProtocol": "http" } - ], - "placementConstraints": [], - "compatibilities": [ - "EC2", - "FARGATE" - ], - "requiresCompatibilities": [ - "EC2", - "FARGATE" - ], - "cpu": "512", - "memory": "1024", - "runtimePlatform": { - "cpuArchitecture": "X86_64", - "operatingSystemFamily": "LINUX" - }, - "registeredAt": "2024-08-15T14:05:44.934Z", - "registeredBy": "arn:aws:iam::590184013289:user/gwanseok", - "tags": [] + ], + "essential": true, + "environment": [], + "environmentFiles": [], + "mountPoints": [], + "volumesFrom": [], + "ulimits": [], + "logConfiguration": { + "logDriver": "awslogs", + "options": { + "awslogs-group": "/ecs/edupi_gateway", + "mode": "non-blocking", + "awslogs-create-group": "true", + "max-buffer-size": "25m", + "awslogs-region": "ap-northeast-2", + "awslogs-stream-prefix": "ecs" + }, + "secretOptions": [] + }, + "systemControls": [] + } + ], + "family": "edupi_gateway", + "executionRoleArn": "arn:aws:iam::590184013289:role/ecsTaskExecutionRole", + "networkMode": "awsvpc", + "volumes": [], + "placementConstraints": [], + "requiresCompatibilities": [ + "EC2", + "FARGATE" + ], + "cpu": "512", + "memory": "1024", + "runtimePlatform": { + "cpuArchitecture": "X86_64", + "operatingSystemFamily": "LINUX" + }, + "tags": [] } \ No newline at end of file From f8dd5d7eeda633755d6783e928528b738eaa55ba Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 20:18:42 +0900 Subject: [PATCH 24/53] =?UTF-8?q?[#1]deploy:=20pull=20request=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B9=8C=EB=93=9C=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EA=B3=A0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A7=8C=20=EC=A7=84?= =?UTF-8?q?=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-build.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml index 6a09443..24e02c3 100644 --- a/.github/workflows/pull-request-build.yml +++ b/.github/workflows/pull-request-build.yml @@ -41,7 +41,13 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - - name: Build with Gradle - run: ./gradlew build + - name: Test with Gradle + run: ./gradlew --info test + + - name: Cleanup Gradle Cache + if: ${{ always() }} + run: | + rm -f ~/.gradle/caches/modules-2/modules-2.lock + rm -f ~/.gradle/caches/modules-2/gc.properties From 03a6559b519ba98cd454b39786c2de91a1320f8f Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 20:22:02 +0900 Subject: [PATCH 25/53] =?UTF-8?q?[#1]deploy:=20pull=20request=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B9=8C=EB=93=9C=ED=95=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EA=B3=A0=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A7=8C=20=EC=A7=84?= =?UTF-8?q?=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pull-request-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml index 24e02c3..94f7cc8 100644 --- a/.github/workflows/pull-request-build.yml +++ b/.github/workflows/pull-request-build.yml @@ -42,7 +42,7 @@ jobs: run: chmod +x gradlew - name: Test with Gradle - run: ./gradlew --info test + run: ./gradlew test - name: Cleanup Gradle Cache if: ${{ always() }} From ace12e655f486b7b6df9a6faea90a3d6edded52c Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 4 Sep 2024 20:40:40 +0900 Subject: [PATCH 26/53] =?UTF-8?q?[#9]fix:=20Cors=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/soma/haeya/edupi_gateway/config/CorsConfig.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java index 69a0867..b41297a 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java @@ -19,7 +19,11 @@ public CorsWebFilter corsWebFilter() { @Bean public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(List.of("*")); + configuration.setAllowedOrigins( + List.of( + "http://localhost:5000", + "http://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com" + )); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders(List.of("*")); configuration.setAllowCredentials(true); From 445897909ea6d3d22bb51feba2275f4720e83ddb Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 5 Sep 2024 14:30:03 +0900 Subject: [PATCH 27/53] =?UTF-8?q?[#9]fix:=20visualize=20authorizationFilte?= =?UTF-8?q?r=20=EC=9E=84=EC=8B=9C=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/soma/haeya/edupi_gateway/config/RoutingConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java index be86c60..b925e20 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java @@ -33,7 +33,7 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil .filters(f -> f.setStatus(200)) .uri("no://op")) // health check .route(predicate -> predicate.path(VISUALIZE_PATH) - .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) +// .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) .uri(VISUALIZE_URL)) // code_visualize .route(predicate -> predicate.path(USER_PATH) From 0843f7c1592407c6d32dd801933bebdd3c79fa1e Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 5 Sep 2024 14:41:30 +0900 Subject: [PATCH 28/53] =?UTF-8?q?[#9]fix:=20cors=20=EC=9D=B8=EC=A6=9D=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20WebFluxConfigurer=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupi_gateway/config/CorsConfig.java | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java index b41297a..d5df9de 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java @@ -1,38 +1,23 @@ package soma.haeya.edupi_gateway.config; -import java.util.List; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.reactive.CorsConfigurationSource; -import org.springframework.web.cors.reactive.CorsWebFilter; -import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; +import org.springframework.web.reactive.config.CorsRegistry; +import org.springframework.web.reactive.config.WebFluxConfigurer; @Configuration -public class CorsConfig { +public class CorsConfig implements WebFluxConfigurer { - @Bean - public CorsWebFilter corsWebFilter() { - return new CorsWebFilter(corsConfigurationSource()); - } - - @Bean - public CorsConfigurationSource corsConfigurationSource() { - CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins( - List.of( + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOrigins( "http://localhost:5000", - "http://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com" - )); - configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); - configuration.setAllowedHeaders(List.of("*")); - configuration.setAllowCredentials(true); - configuration.setMaxAge(3600L); - - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", configuration); - - return source; + "http://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com", + "https://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com" + ) + .allowedMethods("GET", "POST", "PUT", "DELETE") + .allowedHeaders("*") + .allowCredentials(true) + .maxAge(3600); } - } From 839ccf6154d0b2e27c1e5200df3986517e156027 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 5 Sep 2024 15:55:12 +0900 Subject: [PATCH 29/53] =?UTF-8?q?[#9]fix:=20cors=20=EC=9D=B8=EC=A6=9D=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20header=EC=97=90=20Access-Control-Allow-Ori?= =?UTF-8?q?gin=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 - .../edupi_gateway/config/CorsConfig.java | 44 +++++++++++++------ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index 8e8b711..f5dd862 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,6 @@ dependencies { implementation 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' // spring cloud gateway - implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.cloud:spring-cloud-starter-gateway' // jjwt diff --git a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java index d5df9de..8ba884d 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java @@ -1,23 +1,39 @@ package soma.haeya.edupi_gateway.config; +import java.util.List; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.reactive.config.CorsRegistry; -import org.springframework.web.reactive.config.WebFluxConfigurer; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.reactive.CorsConfigurationSource; +import org.springframework.web.cors.reactive.CorsWebFilter; +import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; @Configuration -public class CorsConfig implements WebFluxConfigurer { +public class CorsConfig { - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOrigins( + @Bean + public CorsWebFilter corsWebFilter() { + return new CorsWebFilter(corsConfigurationSource()); + } + + @Bean + public CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration configuration = new CorsConfiguration(); + configuration.setAllowedOrigins( + List.of( "http://localhost:5000", - "http://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com", - "https://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com" + "http://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com" ) - .allowedMethods("GET", "POST", "PUT", "DELETE") - .allowedHeaders("*") - .allowCredentials(true) - .maxAge(3600); + ); + configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); + configuration.setAllowedHeaders( + List.of("Content-Type", "Authorization", "Accept", "Access-Control-Allow-Origin")); + configuration.setAllowCredentials(true); + configuration.setMaxAge(3600L); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", configuration); + + return source; } -} +} \ No newline at end of file From 491d4fa20ef7867ebf674ca2ef48ae39b73fc6b1 Mon Sep 17 00:00:00 2001 From: UJeans Date: Fri, 6 Sep 2024 14:12:40 +0900 Subject: [PATCH 30/53] =?UTF-8?q?[#16]dependency:=20swagger=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index f5dd862..89c7d55 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,9 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' // spring cloud gateway implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + // swagger + implementation 'org.springdoc:springdoc-openapi-webflux-ui' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui' // jjwt implementation 'io.jsonwebtoken:jjwt-api:0.12.3' From 4ebb8ec1350b14b11cf997189b1e2a48aee783ff Mon Sep 17 00:00:00 2001 From: UJeans Date: Sun, 8 Sep 2024 16:06:39 +0900 Subject: [PATCH 31/53] =?UTF-8?q?[#16]dependency:=20openAPI-webflux=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 89c7d55..2fe3a22 100644 --- a/build.gradle +++ b/build.gradle @@ -26,9 +26,9 @@ dependencies { annotationProcessor 'org.projectlombok:lombok' // spring cloud gateway implementation 'org.springframework.cloud:spring-cloud-starter-gateway' + // swagger - implementation 'org.springdoc:springdoc-openapi-webflux-ui' - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui' + implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.0.2' // jjwt implementation 'io.jsonwebtoken:jjwt-api:0.12.3' From 02e6ba5c4626f3761aad2594c9e2688e231bd968 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Sun, 8 Sep 2024 22:02:48 +0900 Subject: [PATCH 32/53] =?UTF-8?q?[#17]feat:=20lms=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soma/haeya/edupi_gateway/config/RoutingConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java index b925e20..2cb3383 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java @@ -25,6 +25,11 @@ public class RoutingConfig { @Value("${server-url.visualize.default-path}") private String VISUALIZE_PATH; + @Value("${server-url.lms.url}") + private String LMS_URL; + @Value("${server-url.lms.default-path}") + private String LMS_PATH; + @Bean public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFilter authorizationFilter) { @@ -42,6 +47,10 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil .route(predicate -> predicate.path(DB_PATH) .uri(DB_URL)) // edupi_db + .route(predicate -> predicate.path(LMS_PATH) + .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) + .uri(LMS_URL)) // edupi_lms + .build(); } From 9149c471df471c25a677966bb853874e14191bd7 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Sun, 8 Sep 2024 22:06:44 +0900 Subject: [PATCH 33/53] =?UTF-8?q?[#17]feat:=20=ED=86=A0=EA=B7=BC=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20->=20id=20=EC=B6=94?= =?UTF-8?q?=EC=B6=9C=ED=95=B4=20header=EC=97=90=20=EB=8B=B4=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupi_gateway/auth/TokenProvider.java | 8 ++++--- .../filter/AuthenticationFilter.java | 21 +++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java b/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java index ee0d941..c444c72 100644 --- a/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java +++ b/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java @@ -22,15 +22,17 @@ public TokenProvider(@Value("${jwt.secret}") String secret) { this.key = Keys.hmacShaKeyFor(keyBytes); } - public void validateToken(String token) { - Claims claims = getClaims(token); + public Claims getClaimsJson(String token) { + Claims claims = extractClaimsFromJwt(token); if (claims.getExpiration().before(new Date())) { throw new UnAuthorizedException(HttpStatus.UNAUTHORIZED, "토큰이 유효하지 않습니다."); } + + return claims; } - private Claims getClaims(String token) { + private Claims extractClaimsFromJwt(String token) { try { return Jwts.parser().verifyWith(key).build().parseSignedClaims(token).getPayload(); } catch (JwtException e) { diff --git a/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java b/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java index b401ac1..960e480 100644 --- a/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java +++ b/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java @@ -1,5 +1,6 @@ package soma.haeya.edupi_gateway.filter; +import io.jsonwebtoken.Claims; import java.util.Optional; import lombok.Getter; import lombok.Setter; @@ -42,11 +43,13 @@ public GatewayFilter apply(Config config) throws NullPointerException { String token = extractToken(cookies); - if (!isJwtValid(token)) { - throw new UnAuthorizedException(HttpStatus.UNAUTHORIZED, "토큰이 유효하지 않습니다."); - } + Claims claims = jwtProvider.getClaimsJson(token); - return chain.filter(exchange); + ServerHttpRequest modifiedRequest = exchange.getRequest().mutate() + .header("X-User-Id", claims.get("id", Integer.class).toString()) + .build(); + + return chain.filter(exchange.mutate().request(modifiedRequest).build()); }); } @@ -58,14 +61,4 @@ public String extractToken(MultiValueMap cookies) { .orElseThrow(() -> new UnAuthorizedException(HttpStatus.UNAUTHORIZED, "토큰이 없습니다.")); } - private boolean isJwtValid(String token) { - try { - jwtProvider.validateToken(token); - return true; - } catch (Exception e) { - return false; - } - - } - } From 0ede1b7a68becec615680ff92bab18f65b7a513e Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Sun, 8 Sep 2024 22:07:15 +0900 Subject: [PATCH 34/53] =?UTF-8?q?[#17]feat:=20=ED=86=A0=ED=81=B0=EC=9D=B4?= =?UTF-8?q?=20=EC=97=86=EB=8A=94=20=EA=B2=BD=EC=9A=B0=EC=9D=98=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/GlobalExceptionHandler.java | 4 +--- .../haeya/edupi_gateway/models/ErrorResponse.java | 12 +++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java b/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java index 838ac9b..782d882 100644 --- a/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java +++ b/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java @@ -1,7 +1,6 @@ package soma.haeya.edupi_gateway.exception; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -13,9 +12,8 @@ public class GlobalExceptionHandler { @ExceptionHandler(UnAuthorizedException.class) public ResponseEntity handleValidationExceptions(UnAuthorizedException ex) { - return ResponseEntity - .status(HttpStatus.BAD_REQUEST) + .status(ex.getStatusCode()) .body(new ErrorResponse(ex.getReason())); } diff --git a/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java b/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java index d930355..7cb24d4 100644 --- a/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java +++ b/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java @@ -1,9 +1,15 @@ package soma.haeya.edupi_gateway.models; -import lombok.RequiredArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; -@RequiredArgsConstructor +@Getter +@NoArgsConstructor public class ErrorResponse { - private final String message; + private String message; + + public ErrorResponse(String message) { + this.message = message; + } } From a73dbac475f89135c4135b06815bc821f73e0a8f Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Sun, 8 Sep 2024 22:53:32 +0900 Subject: [PATCH 35/53] =?UTF-8?q?Revert=20"[#17]feat:=20lms=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=20=EC=B6=94=EA=B0=80"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 02e6ba5c4626f3761aad2594c9e2688e231bd968. --- .../soma/haeya/edupi_gateway/config/RoutingConfig.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java index 2cb3383..b925e20 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java +++ b/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java @@ -25,11 +25,6 @@ public class RoutingConfig { @Value("${server-url.visualize.default-path}") private String VISUALIZE_PATH; - @Value("${server-url.lms.url}") - private String LMS_URL; - @Value("${server-url.lms.default-path}") - private String LMS_PATH; - @Bean public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFilter authorizationFilter) { @@ -47,10 +42,6 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil .route(predicate -> predicate.path(DB_PATH) .uri(DB_URL)) // edupi_db - .route(predicate -> predicate.path(LMS_PATH) - .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) - .uri(LMS_URL)) // edupi_lms - .build(); } From 8b6cff2acdb60486f932ab9d2836320e5b5727a4 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Mon, 9 Sep 2024 16:21:54 +0900 Subject: [PATCH 36/53] =?UTF-8?q?[#17]fix:=20ErrorResponse=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EC=9E=90=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../soma/haeya/edupi_gateway/models/ErrorResponse.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java b/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java index 7cb24d4..4760ca5 100644 --- a/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java +++ b/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java @@ -1,15 +1,12 @@ package soma.haeya.edupi_gateway.models; import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; @Getter -@NoArgsConstructor +@RequiredArgsConstructor public class ErrorResponse { - private String message; + private final String message; - public ErrorResponse(String message) { - this.message = message; - } } From ca8f7fd0eeb6ea3a3c9ac023d4a7b47b0a837e30 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 12 Sep 2024 13:13:32 +0900 Subject: [PATCH 37/53] =?UTF-8?q?[#19]refactor:=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway}/EdupiGatewayApplication.java | 8 ++++---- .../gateway}/auth/TokenProvider.java | 4 ++-- .../gateway}/config/CorsConfig.java | 2 +- .../gateway}/config/RoutingConfig.java | 4 ++-- .../gateway}/exception/GlobalExceptionHandler.java | 4 ++-- .../gateway}/exception/UnAuthorizedException.java | 2 +- .../gateway}/filter/AuthenticationFilter.java | 6 +++--- .../gateway}/filter/RequestLoggingFilter.java | 2 +- .../gateway}/models/ErrorResponse.java | 2 +- .../gateway}/EdupiGatewayApplicationTests.java | 8 ++++---- 10 files changed, 21 insertions(+), 21 deletions(-) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/EdupiGatewayApplication.java (56%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/auth/TokenProvider.java (92%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/config/CorsConfig.java (97%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/config/RoutingConfig.java (93%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/exception/GlobalExceptionHandler.java (85%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/exception/UnAuthorizedException.java (87%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/filter/AuthenticationFilter.java (92%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/filter/RequestLoggingFilter.java (97%) rename src/main/java/soma/{haeya/edupi_gateway => edupi/gateway}/models/ErrorResponse.java (79%) rename src/test/java/soma/{haeya/edupi_gateway => edupi/gateway}/EdupiGatewayApplicationTests.java (68%) diff --git a/src/main/java/soma/haeya/edupi_gateway/EdupiGatewayApplication.java b/src/main/java/soma/edupi/gateway/EdupiGatewayApplication.java similarity index 56% rename from src/main/java/soma/haeya/edupi_gateway/EdupiGatewayApplication.java rename to src/main/java/soma/edupi/gateway/EdupiGatewayApplication.java index 01f3584..bb4a0d4 100644 --- a/src/main/java/soma/haeya/edupi_gateway/EdupiGatewayApplication.java +++ b/src/main/java/soma/edupi/gateway/EdupiGatewayApplication.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway; +package soma.edupi.gateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -6,8 +6,8 @@ @SpringBootApplication public class EdupiGatewayApplication { - public static void main(String[] args) { - SpringApplication.run(EdupiGatewayApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(EdupiGatewayApplication.class, args); + } } diff --git a/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java b/src/main/java/soma/edupi/gateway/auth/TokenProvider.java similarity index 92% rename from src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java rename to src/main/java/soma/edupi/gateway/auth/TokenProvider.java index c444c72..05734f7 100644 --- a/src/main/java/soma/haeya/edupi_gateway/auth/TokenProvider.java +++ b/src/main/java/soma/edupi/gateway/auth/TokenProvider.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway.auth; +package soma.edupi.gateway.auth; import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtException; @@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; -import soma.haeya.edupi_gateway.exception.UnAuthorizedException; +import soma.edupi.gateway.exception.UnAuthorizedException; @Component public class TokenProvider { diff --git a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java b/src/main/java/soma/edupi/gateway/config/CorsConfig.java similarity index 97% rename from src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java rename to src/main/java/soma/edupi/gateway/config/CorsConfig.java index 8ba884d..e3ecf3b 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/CorsConfig.java +++ b/src/main/java/soma/edupi/gateway/config/CorsConfig.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway.config; +package soma.edupi.gateway.config; import java.util.List; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java b/src/main/java/soma/edupi/gateway/config/RoutingConfig.java similarity index 93% rename from src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java rename to src/main/java/soma/edupi/gateway/config/RoutingConfig.java index b925e20..89825e7 100644 --- a/src/main/java/soma/haeya/edupi_gateway/config/RoutingConfig.java +++ b/src/main/java/soma/edupi/gateway/config/RoutingConfig.java @@ -1,11 +1,11 @@ -package soma.haeya.edupi_gateway.config; +package soma.edupi.gateway.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.gateway.route.RouteLocator; import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import soma.haeya.edupi_gateway.filter.AuthenticationFilter; +import soma.edupi.gateway.filter.AuthenticationFilter; @Configuration public class RoutingConfig { diff --git a/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java b/src/main/java/soma/edupi/gateway/exception/GlobalExceptionHandler.java similarity index 85% rename from src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java rename to src/main/java/soma/edupi/gateway/exception/GlobalExceptionHandler.java index 782d882..1301c93 100644 --- a/src/main/java/soma/haeya/edupi_gateway/exception/GlobalExceptionHandler.java +++ b/src/main/java/soma/edupi/gateway/exception/GlobalExceptionHandler.java @@ -1,10 +1,10 @@ -package soma.haeya.edupi_gateway.exception; +package soma.edupi.gateway.exception; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import soma.haeya.edupi_gateway.models.ErrorResponse; +import soma.edupi.gateway.models.ErrorResponse; @Slf4j @RestControllerAdvice diff --git a/src/main/java/soma/haeya/edupi_gateway/exception/UnAuthorizedException.java b/src/main/java/soma/edupi/gateway/exception/UnAuthorizedException.java similarity index 87% rename from src/main/java/soma/haeya/edupi_gateway/exception/UnAuthorizedException.java rename to src/main/java/soma/edupi/gateway/exception/UnAuthorizedException.java index 2df90d3..0660ee1 100644 --- a/src/main/java/soma/haeya/edupi_gateway/exception/UnAuthorizedException.java +++ b/src/main/java/soma/edupi/gateway/exception/UnAuthorizedException.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway.exception; +package soma.edupi.gateway.exception; import lombok.Getter; import org.springframework.http.HttpStatus; diff --git a/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java b/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java similarity index 92% rename from src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java rename to src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java index 960e480..f815f24 100644 --- a/src/main/java/soma/haeya/edupi_gateway/filter/AuthenticationFilter.java +++ b/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway.filter; +package soma.edupi.gateway.filter; import io.jsonwebtoken.Claims; import java.util.Optional; @@ -12,8 +12,8 @@ import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.stereotype.Component; import org.springframework.util.MultiValueMap; -import soma.haeya.edupi_gateway.auth.TokenProvider; -import soma.haeya.edupi_gateway.exception.UnAuthorizedException; +import soma.edupi.gateway.auth.TokenProvider; +import soma.edupi.gateway.exception.UnAuthorizedException; @Slf4j @Component diff --git a/src/main/java/soma/haeya/edupi_gateway/filter/RequestLoggingFilter.java b/src/main/java/soma/edupi/gateway/filter/RequestLoggingFilter.java similarity index 97% rename from src/main/java/soma/haeya/edupi_gateway/filter/RequestLoggingFilter.java rename to src/main/java/soma/edupi/gateway/filter/RequestLoggingFilter.java index ee0977e..6dbba76 100644 --- a/src/main/java/soma/haeya/edupi_gateway/filter/RequestLoggingFilter.java +++ b/src/main/java/soma/edupi/gateway/filter/RequestLoggingFilter.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway.filter; +package soma.edupi.gateway.filter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java b/src/main/java/soma/edupi/gateway/models/ErrorResponse.java similarity index 79% rename from src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java rename to src/main/java/soma/edupi/gateway/models/ErrorResponse.java index 4760ca5..022efd4 100644 --- a/src/main/java/soma/haeya/edupi_gateway/models/ErrorResponse.java +++ b/src/main/java/soma/edupi/gateway/models/ErrorResponse.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway.models; +package soma.edupi.gateway.models; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/soma/haeya/edupi_gateway/EdupiGatewayApplicationTests.java b/src/test/java/soma/edupi/gateway/EdupiGatewayApplicationTests.java similarity index 68% rename from src/test/java/soma/haeya/edupi_gateway/EdupiGatewayApplicationTests.java rename to src/test/java/soma/edupi/gateway/EdupiGatewayApplicationTests.java index 19158b7..5f4e287 100644 --- a/src/test/java/soma/haeya/edupi_gateway/EdupiGatewayApplicationTests.java +++ b/src/test/java/soma/edupi/gateway/EdupiGatewayApplicationTests.java @@ -1,4 +1,4 @@ -package soma.haeya.edupi_gateway; +package soma.edupi.gateway; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @@ -6,8 +6,8 @@ @SpringBootTest class EdupiGatewayApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } } From a47bbdfd025a5b3677de3ea44b4e45514ecad626 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 12 Sep 2024 13:15:10 +0900 Subject: [PATCH 38/53] =?UTF-8?q?[#19]chore:=20ecs=20cluster=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ".github/workflows/\bcicd-dev.yml" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" index 6a99028..3a02cb3 100644 --- "a/.github/workflows/\bcicd-dev.yml" +++ "b/.github/workflows/\bcicd-dev.yml" @@ -8,7 +8,7 @@ env: AWS_REGION: ap-northeast-2 ECR_REPOSITORY: edupi_gateway ECS_SERVICE: gateway - ECS_CLUSTER: BE + ECS_CLUSTER: BE-fargate ECS_TASK_DEFINITION: edupi_gateway-revision.json CONTAINER_NAME: gateway From 5364ef49968e36224566be1b688dd0b52dc79e5f Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 12 Sep 2024 16:39:03 +0900 Subject: [PATCH 39/53] =?UTF-8?q?[#17]chore:=20ecs=20task=20definition=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ".github/workflows/\bcicd-dev.yml" | 2 +- .github/workflows/pull-request-build.yml | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" index 3a02cb3..1c65174 100644 --- "a/.github/workflows/\bcicd-dev.yml" +++ "b/.github/workflows/\bcicd-dev.yml" @@ -9,7 +9,7 @@ env: ECR_REPOSITORY: edupi_gateway ECS_SERVICE: gateway ECS_CLUSTER: BE-fargate - ECS_TASK_DEFINITION: edupi_gateway-revision.json + ECS_TASK_DEFINITION: edupi_gateway.json CONTAINER_NAME: gateway permissions: diff --git a/.github/workflows/pull-request-build.yml b/.github/workflows/pull-request-build.yml index 94f7cc8..ba281de 100644 --- a/.github/workflows/pull-request-build.yml +++ b/.github/workflows/pull-request-build.yml @@ -4,14 +4,6 @@ on: pull_request: branches: [ "develop" ] -env: - AWS_REGION: ap-northeast-2 - ECR_REPOSITORY: edupi_gateway - ECS_SERVICE: gateway - ECS_CLUSTER: BE - ECS_TASK_DEFINITION: edupi_gateway-revision.json - CONTAINER_NAME: gateway - permissions: contents: read From 1e6c3388c44bc954501b82aebebe59b5fbee075d Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 12 Sep 2024 16:40:59 +0900 Subject: [PATCH 40/53] =?UTF-8?q?[#17]chore:=20ecs=20task=20definition=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- edupi_gateway-revision.json => edupi_gateway.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename edupi_gateway-revision.json => edupi_gateway.json (100%) diff --git a/edupi_gateway-revision.json b/edupi_gateway.json similarity index 100% rename from edupi_gateway-revision.json rename to edupi_gateway.json From 81f778ee547a22fa28a9fa37df60d3c7a6aa8cfc Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Thu, 12 Sep 2024 18:17:29 +0900 Subject: [PATCH 41/53] =?UTF-8?q?[#21]feat:=20CloudFront=20CORS=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/soma/edupi/gateway/config/CorsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/soma/edupi/gateway/config/CorsConfig.java b/src/main/java/soma/edupi/gateway/config/CorsConfig.java index e3ecf3b..c865db0 100644 --- a/src/main/java/soma/edupi/gateway/config/CorsConfig.java +++ b/src/main/java/soma/edupi/gateway/config/CorsConfig.java @@ -22,7 +22,7 @@ public CorsConfigurationSource corsConfigurationSource() { configuration.setAllowedOrigins( List.of( "http://localhost:5000", - "http://fe-alb-142217835.ap-northeast-2.elb.amazonaws.com" + "http://d33notepxaalcd.cloudfront.net" ) ); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); From 1136bdf4feacce92758fa3e23bd5674cbac47a88 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 17 Sep 2024 21:52:36 +0900 Subject: [PATCH 42/53] [#19]rename: X-User-Id -> X-Account-Id --- .../soma/edupi/gateway/config/RoutingConfig.java | 16 +++++++++++++--- .../gateway/filter/AuthenticationFilter.java | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/soma/edupi/gateway/config/RoutingConfig.java b/src/main/java/soma/edupi/gateway/config/RoutingConfig.java index 89825e7..3833bca 100644 --- a/src/main/java/soma/edupi/gateway/config/RoutingConfig.java +++ b/src/main/java/soma/edupi/gateway/config/RoutingConfig.java @@ -20,6 +20,11 @@ public class RoutingConfig { @Value("${server-url.user.default-path}") private String USER_PATH; +// @Value("${server-url.lms.url}") +// private String LMS_URL; +// @Value("${server-url.lms.default-path}") +// private String LMS_PATH; + @Value("${server-url.visualize.url}") private String VISUALIZE_URL; @Value("${server-url.visualize.default-path}") @@ -32,15 +37,20 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil .route("root_route", r -> r.path("/") .filters(f -> f.setStatus(200)) .uri("no://op")) // health check + .route(predicate -> predicate.path(VISUALIZE_PATH) // .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) - .uri(VISUALIZE_URL)) // code_visualize + .uri(VISUALIZE_URL)) // edupi-visualize + +// .route(predicate -> predicate.path(LMS_PATH) +// .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) +// .uri(LMS_URL)) // edupi-lms .route(predicate -> predicate.path(USER_PATH) - .uri(USER_URL)) // edupi_user + .uri(USER_URL)) // edupi-user .route(predicate -> predicate.path(DB_PATH) - .uri(DB_URL)) // edupi_db + .uri(DB_URL)) // edupi-db .build(); } diff --git a/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java b/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java index f815f24..444967b 100644 --- a/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java +++ b/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java @@ -46,7 +46,7 @@ public GatewayFilter apply(Config config) throws NullPointerException { Claims claims = jwtProvider.getClaimsJson(token); ServerHttpRequest modifiedRequest = exchange.getRequest().mutate() - .header("X-User-Id", claims.get("id", Integer.class).toString()) + .header("X-Account-Id", claims.get("accountId", Long.class).toString()) .build(); return chain.filter(exchange.mutate().request(modifiedRequest).build()); From 4908670f9e072007ecc926efd4d597116c0810e2 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 1 Oct 2024 15:39:59 +0900 Subject: [PATCH 43/53] =?UTF-8?q?[#24]feat:=20sse-connection=20exposedHead?= =?UTF-8?q?er=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/soma/edupi/gateway/config/CorsConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/soma/edupi/gateway/config/CorsConfig.java b/src/main/java/soma/edupi/gateway/config/CorsConfig.java index c865db0..862d81f 100644 --- a/src/main/java/soma/edupi/gateway/config/CorsConfig.java +++ b/src/main/java/soma/edupi/gateway/config/CorsConfig.java @@ -28,6 +28,7 @@ public CorsConfigurationSource corsConfigurationSource() { configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders( List.of("Content-Type", "Authorization", "Accept", "Access-Control-Allow-Origin")); + configuration.setExposedHeaders(List.of("Content-Type")); configuration.setAllowCredentials(true); configuration.setMaxAge(3600L); From 8a6cdf294892b75613343d9982127b6221b59299 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 1 Oct 2024 15:52:00 +0900 Subject: [PATCH 44/53] =?UTF-8?q?[#24]refactor:=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway => edupigateway}/EdupiGatewayApplication.java | 2 +- .../{edupi/gateway => edupigateway}/auth/TokenProvider.java | 4 ++-- .../{edupi/gateway => edupigateway}/config/CorsConfig.java | 2 +- .../gateway => edupigateway}/config/RoutingConfig.java | 4 ++-- .../exception/GlobalExceptionHandler.java | 4 ++-- .../exception/UnAuthorizedException.java | 2 +- .../filter/AuthenticationFilter.java | 6 +++--- .../filter/RequestLoggingFilter.java | 2 +- .../gateway => edupigateway}/models/ErrorResponse.java | 2 +- .../EdupiGatewayApplicationTests.java | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) rename src/main/java/soma/{edupi/gateway => edupigateway}/EdupiGatewayApplication.java (91%) rename src/main/java/soma/{edupi/gateway => edupigateway}/auth/TokenProvider.java (93%) rename src/main/java/soma/{edupi/gateway => edupigateway}/config/CorsConfig.java (97%) rename src/main/java/soma/{edupi/gateway => edupigateway}/config/RoutingConfig.java (95%) rename src/main/java/soma/{edupi/gateway => edupigateway}/exception/GlobalExceptionHandler.java (86%) rename src/main/java/soma/{edupi/gateway => edupigateway}/exception/UnAuthorizedException.java (89%) rename src/main/java/soma/{edupi/gateway => edupigateway}/filter/AuthenticationFilter.java (93%) rename src/main/java/soma/{edupi/gateway => edupigateway}/filter/RequestLoggingFilter.java (98%) rename src/main/java/soma/{edupi/gateway => edupigateway}/models/ErrorResponse.java (82%) rename src/test/java/soma/{edupi/gateway => edupigateway}/EdupiGatewayApplicationTests.java (87%) diff --git a/src/main/java/soma/edupi/gateway/EdupiGatewayApplication.java b/src/main/java/soma/edupigateway/EdupiGatewayApplication.java similarity index 91% rename from src/main/java/soma/edupi/gateway/EdupiGatewayApplication.java rename to src/main/java/soma/edupigateway/EdupiGatewayApplication.java index bb4a0d4..06491dc 100644 --- a/src/main/java/soma/edupi/gateway/EdupiGatewayApplication.java +++ b/src/main/java/soma/edupigateway/EdupiGatewayApplication.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway; +package soma.edupigateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/soma/edupi/gateway/auth/TokenProvider.java b/src/main/java/soma/edupigateway/auth/TokenProvider.java similarity index 93% rename from src/main/java/soma/edupi/gateway/auth/TokenProvider.java rename to src/main/java/soma/edupigateway/auth/TokenProvider.java index 05734f7..86eb5d3 100644 --- a/src/main/java/soma/edupi/gateway/auth/TokenProvider.java +++ b/src/main/java/soma/edupigateway/auth/TokenProvider.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway.auth; +package soma.edupigateway.auth; import io.jsonwebtoken.Claims; import io.jsonwebtoken.JwtException; @@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; -import soma.edupi.gateway.exception.UnAuthorizedException; +import soma.edupigateway.exception.UnAuthorizedException; @Component public class TokenProvider { diff --git a/src/main/java/soma/edupi/gateway/config/CorsConfig.java b/src/main/java/soma/edupigateway/config/CorsConfig.java similarity index 97% rename from src/main/java/soma/edupi/gateway/config/CorsConfig.java rename to src/main/java/soma/edupigateway/config/CorsConfig.java index 862d81f..85c4ee4 100644 --- a/src/main/java/soma/edupi/gateway/config/CorsConfig.java +++ b/src/main/java/soma/edupigateway/config/CorsConfig.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway.config; +package soma.edupigateway.config; import java.util.List; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/soma/edupi/gateway/config/RoutingConfig.java b/src/main/java/soma/edupigateway/config/RoutingConfig.java similarity index 95% rename from src/main/java/soma/edupi/gateway/config/RoutingConfig.java rename to src/main/java/soma/edupigateway/config/RoutingConfig.java index 3833bca..e76775f 100644 --- a/src/main/java/soma/edupi/gateway/config/RoutingConfig.java +++ b/src/main/java/soma/edupigateway/config/RoutingConfig.java @@ -1,11 +1,11 @@ -package soma.edupi.gateway.config; +package soma.edupigateway.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.gateway.route.RouteLocator; import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import soma.edupi.gateway.filter.AuthenticationFilter; +import soma.edupigateway.filter.AuthenticationFilter; @Configuration public class RoutingConfig { diff --git a/src/main/java/soma/edupi/gateway/exception/GlobalExceptionHandler.java b/src/main/java/soma/edupigateway/exception/GlobalExceptionHandler.java similarity index 86% rename from src/main/java/soma/edupi/gateway/exception/GlobalExceptionHandler.java rename to src/main/java/soma/edupigateway/exception/GlobalExceptionHandler.java index 1301c93..4f613e0 100644 --- a/src/main/java/soma/edupi/gateway/exception/GlobalExceptionHandler.java +++ b/src/main/java/soma/edupigateway/exception/GlobalExceptionHandler.java @@ -1,10 +1,10 @@ -package soma.edupi.gateway.exception; +package soma.edupigateway.exception; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; -import soma.edupi.gateway.models.ErrorResponse; +import soma.edupigateway.models.ErrorResponse; @Slf4j @RestControllerAdvice diff --git a/src/main/java/soma/edupi/gateway/exception/UnAuthorizedException.java b/src/main/java/soma/edupigateway/exception/UnAuthorizedException.java similarity index 89% rename from src/main/java/soma/edupi/gateway/exception/UnAuthorizedException.java rename to src/main/java/soma/edupigateway/exception/UnAuthorizedException.java index 0660ee1..da41d28 100644 --- a/src/main/java/soma/edupi/gateway/exception/UnAuthorizedException.java +++ b/src/main/java/soma/edupigateway/exception/UnAuthorizedException.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway.exception; +package soma.edupigateway.exception; import lombok.Getter; import org.springframework.http.HttpStatus; diff --git a/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java b/src/main/java/soma/edupigateway/filter/AuthenticationFilter.java similarity index 93% rename from src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java rename to src/main/java/soma/edupigateway/filter/AuthenticationFilter.java index 444967b..9724696 100644 --- a/src/main/java/soma/edupi/gateway/filter/AuthenticationFilter.java +++ b/src/main/java/soma/edupigateway/filter/AuthenticationFilter.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway.filter; +package soma.edupigateway.filter; import io.jsonwebtoken.Claims; import java.util.Optional; @@ -12,8 +12,8 @@ import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.stereotype.Component; import org.springframework.util.MultiValueMap; -import soma.edupi.gateway.auth.TokenProvider; -import soma.edupi.gateway.exception.UnAuthorizedException; +import soma.edupigateway.auth.TokenProvider; +import soma.edupigateway.exception.UnAuthorizedException; @Slf4j @Component diff --git a/src/main/java/soma/edupi/gateway/filter/RequestLoggingFilter.java b/src/main/java/soma/edupigateway/filter/RequestLoggingFilter.java similarity index 98% rename from src/main/java/soma/edupi/gateway/filter/RequestLoggingFilter.java rename to src/main/java/soma/edupigateway/filter/RequestLoggingFilter.java index 6dbba76..e6ef6f8 100644 --- a/src/main/java/soma/edupi/gateway/filter/RequestLoggingFilter.java +++ b/src/main/java/soma/edupigateway/filter/RequestLoggingFilter.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway.filter; +package soma.edupigateway.filter; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/soma/edupi/gateway/models/ErrorResponse.java b/src/main/java/soma/edupigateway/models/ErrorResponse.java similarity index 82% rename from src/main/java/soma/edupi/gateway/models/ErrorResponse.java rename to src/main/java/soma/edupigateway/models/ErrorResponse.java index 022efd4..a485d1d 100644 --- a/src/main/java/soma/edupi/gateway/models/ErrorResponse.java +++ b/src/main/java/soma/edupigateway/models/ErrorResponse.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway.models; +package soma.edupigateway.models; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/test/java/soma/edupi/gateway/EdupiGatewayApplicationTests.java b/src/test/java/soma/edupigateway/EdupiGatewayApplicationTests.java similarity index 87% rename from src/test/java/soma/edupi/gateway/EdupiGatewayApplicationTests.java rename to src/test/java/soma/edupigateway/EdupiGatewayApplicationTests.java index 5f4e287..96fbaa8 100644 --- a/src/test/java/soma/edupi/gateway/EdupiGatewayApplicationTests.java +++ b/src/test/java/soma/edupigateway/EdupiGatewayApplicationTests.java @@ -1,4 +1,4 @@ -package soma.edupi.gateway; +package soma.edupigateway; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; From ffa33575c70820d7e8fb5dd35ef79b12cfca4f21 Mon Sep 17 00:00:00 2001 From: UJeans Date: Mon, 7 Oct 2024 15:56:10 +0900 Subject: [PATCH 45/53] =?UTF-8?q?[#26]feat:=20syntax=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=20=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupigateway/config/RoutingConfig.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/soma/edupigateway/config/RoutingConfig.java b/src/main/java/soma/edupigateway/config/RoutingConfig.java index e76775f..53a13d6 100644 --- a/src/main/java/soma/edupigateway/config/RoutingConfig.java +++ b/src/main/java/soma/edupigateway/config/RoutingConfig.java @@ -10,6 +10,16 @@ @Configuration public class RoutingConfig { + @Value("${server-url.syntax.url}") + private String SYNTAX_URL; + @Value("${server-url.syntax.default-path}") + private String SYNTAX_PATH; + + @Value("${server-url.visualize.url}") + private String VISUALIZE_URL; + @Value("${server-url.visualize.default-path}") + private String VISUALIZE_PATH; + @Value("${server-url.db.url}") private String DB_URL; @Value("${server-url.db.default-path}") @@ -25,11 +35,6 @@ public class RoutingConfig { // @Value("${server-url.lms.default-path}") // private String LMS_PATH; - @Value("${server-url.visualize.url}") - private String VISUALIZE_URL; - @Value("${server-url.visualize.default-path}") - private String VISUALIZE_PATH; - @Bean public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFilter authorizationFilter) { @@ -38,6 +43,9 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil .filters(f -> f.setStatus(200)) .uri("no://op")) // health check + .route(predicate -> predicate.path(SYNTAX_PATH) + .uri(SYNTAX_URL)) // edupi-syntax + .route(predicate -> predicate.path(VISUALIZE_PATH) // .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) .uri(VISUALIZE_URL)) // edupi-visualize From 43f54a74f0d8aea29f7b17ae661d31b4f951f211 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Fri, 18 Oct 2024 15:29:28 +0900 Subject: [PATCH 46/53] =?UTF-8?q?[#29]refactor:=20routing=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edupigateway/config/RoutingConfig.java | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/main/java/soma/edupigateway/config/RoutingConfig.java b/src/main/java/soma/edupigateway/config/RoutingConfig.java index 53a13d6..5ac92a4 100644 --- a/src/main/java/soma/edupigateway/config/RoutingConfig.java +++ b/src/main/java/soma/edupigateway/config/RoutingConfig.java @@ -20,45 +20,58 @@ public class RoutingConfig { @Value("${server-url.visualize.default-path}") private String VISUALIZE_PATH; - @Value("${server-url.db.url}") - private String DB_URL; - @Value("${server-url.db.default-path}") - private String DB_PATH; + @Value("${server-url.meta.url}") + private String META_URL; + @Value("${server-url.meta.default-path}") + private String META_PATH; @Value("${server-url.user.url}") private String USER_URL; @Value("${server-url.user.default-path}") private String USER_PATH; -// @Value("${server-url.lms.url}") -// private String LMS_URL; -// @Value("${server-url.lms.default-path}") -// private String LMS_PATH; + @Value("${server-url.lms.url}") + private String LMS_URL; + @Value("${server-url.lms.default-path}") + private String LMS_PATH; @Bean public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFilter authorizationFilter) { - return builder.routes() - .route("root_route", r -> r.path("/") + return builder + .routes() + .route("root_route", r -> r.path("/health-check") .filters(f -> f.setStatus(200)) - .uri("no://op")) // health check - - .route(predicate -> predicate.path(SYNTAX_PATH) - .uri(SYNTAX_URL)) // edupi-syntax - - .route(predicate -> predicate.path(VISUALIZE_PATH) -// .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) - .uri(VISUALIZE_URL)) // edupi-visualize - -// .route(predicate -> predicate.path(LMS_PATH) -// .filters(f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER")))) -// .uri(LMS_URL)) // edupi-lms - - .route(predicate -> predicate.path(USER_PATH) - .uri(USER_URL)) // edupi-user - - .route(predicate -> predicate.path(DB_PATH) - .uri(DB_URL)) // edupi-db + .uri("no://op") + ) // health check + + .route(predicate -> predicate + .path(SYNTAX_PATH) + .uri(SYNTAX_URL) + ) // edupi-syntax + + .route(predicate -> predicate + .path(VISUALIZE_PATH) + .uri(VISUALIZE_URL) + ) // edupi-visualize + + .route(predicate -> predicate + .path(LMS_PATH) + .filters( + f -> f.filter(authorizationFilter.apply(config -> config.setRequiredRole("ROLE_USER"))) + ) + .uri(LMS_URL) + ) // edupi-lms + + .route(predicate -> predicate + .path(USER_PATH) + .uri(USER_URL) + ) // edupi-user + + .route(predicate -> predicate + .path(META_PATH) + .uri(META_URL) + ) // edupi-db .build(); } From f3c82b763c996815f3068e9b7fd37e05edf4b054 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Fri, 18 Oct 2024 15:36:21 +0900 Subject: [PATCH 47/53] =?UTF-8?q?[#30]refactor:=20cicd-dev=20image-tag=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ".github/workflows/\bcicd-dev.yml" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" index 1c65174..965043f 100644 --- "a/.github/workflows/\bcicd-dev.yml" +++ "b/.github/workflows/\bcicd-dev.yml" @@ -59,7 +59,7 @@ jobs: id: build-image env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} - IMAGE_TAG: ${{ github.sha }} + IMAGE_TAG: latest run: | # Build a docker container and # push it to ECR so that it can From 7ed4957154c5dc78c9e8ea2a14e9fb35346df78c Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Mon, 21 Oct 2024 15:03:42 +0900 Subject: [PATCH 48/53] [32]rename: Syntax -> assist --- .../java/soma/edupigateway/config/RoutingConfig.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/soma/edupigateway/config/RoutingConfig.java b/src/main/java/soma/edupigateway/config/RoutingConfig.java index 5ac92a4..68e8e79 100644 --- a/src/main/java/soma/edupigateway/config/RoutingConfig.java +++ b/src/main/java/soma/edupigateway/config/RoutingConfig.java @@ -10,10 +10,10 @@ @Configuration public class RoutingConfig { - @Value("${server-url.syntax.url}") - private String SYNTAX_URL; - @Value("${server-url.syntax.default-path}") - private String SYNTAX_PATH; + @Value("${server-url.assist.url}") + private String ASSIST_URL; + @Value("${server-url.assist.default-path}") + private String ASSIST_PATH; @Value("${server-url.visualize.url}") private String VISUALIZE_URL; @@ -46,8 +46,8 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil ) // health check .route(predicate -> predicate - .path(SYNTAX_PATH) - .uri(SYNTAX_URL) + .path(ASSIST_PATH) + .uri(ASSIST_URL) ) // edupi-syntax .route(predicate -> predicate From d4dea2db99850cfaa1556fec5651fb55d40d41cc Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Mon, 21 Oct 2024 16:24:48 +0900 Subject: [PATCH 49/53] =?UTF-8?q?[#32]rename:=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/soma/edupigateway/config/RoutingConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/soma/edupigateway/config/RoutingConfig.java b/src/main/java/soma/edupigateway/config/RoutingConfig.java index 68e8e79..9c34a0e 100644 --- a/src/main/java/soma/edupigateway/config/RoutingConfig.java +++ b/src/main/java/soma/edupigateway/config/RoutingConfig.java @@ -48,7 +48,7 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil .route(predicate -> predicate .path(ASSIST_PATH) .uri(ASSIST_URL) - ) // edupi-syntax + ) // edupi-assist .route(predicate -> predicate .path(VISUALIZE_PATH) @@ -71,7 +71,7 @@ public RouteLocator gatewayRoutes(RouteLocatorBuilder builder, AuthenticationFil .route(predicate -> predicate .path(META_PATH) .uri(META_URL) - ) // edupi-db + ) // edupi-meta .build(); } From 546a0e9bb9775ca879eb4e6b78086fab22edbd5c Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 29 Oct 2024 15:45:34 +0900 Subject: [PATCH 50/53] =?UTF-8?q?[#34]feat:=20edupi.co.kr=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20CORS=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/soma/edupigateway/config/CorsConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/soma/edupigateway/config/CorsConfig.java b/src/main/java/soma/edupigateway/config/CorsConfig.java index 85c4ee4..6e687de 100644 --- a/src/main/java/soma/edupigateway/config/CorsConfig.java +++ b/src/main/java/soma/edupigateway/config/CorsConfig.java @@ -22,7 +22,8 @@ public CorsConfigurationSource corsConfigurationSource() { configuration.setAllowedOrigins( List.of( "http://localhost:5000", - "http://d33notepxaalcd.cloudfront.net" + "http://edupi.co.kr", + "https://edupi.co.kr" ) ); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); @@ -37,4 +38,4 @@ public CorsConfigurationSource corsConfigurationSource() { return source; } -} \ No newline at end of file +} From c1c88c05c2458437aa99051af7df59783658c8b6 Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 29 Oct 2024 16:12:36 +0900 Subject: [PATCH 51/53] =?UTF-8?q?[#34]feat:=20cloudfront=20=EB=8F=84?= =?UTF-8?q?=EB=A9=94=EC=9D=B8=20CORS=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/soma/edupigateway/config/CorsConfig.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/soma/edupigateway/config/CorsConfig.java b/src/main/java/soma/edupigateway/config/CorsConfig.java index 6e687de..88a386b 100644 --- a/src/main/java/soma/edupigateway/config/CorsConfig.java +++ b/src/main/java/soma/edupigateway/config/CorsConfig.java @@ -22,6 +22,8 @@ public CorsConfigurationSource corsConfigurationSource() { configuration.setAllowedOrigins( List.of( "http://localhost:5000", + "http://d33notepxaalcd.cloudfront.net", + "https://d33notepxaalcd.cloudfront.net", "http://edupi.co.kr", "https://edupi.co.kr" ) From f60224e04772b8a054714b51baac7192a5942aea Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Tue, 5 Nov 2024 19:17:08 +0900 Subject: [PATCH 52/53] =?UTF-8?q?[#38]feat:=20gateway=20=EB=92=A4=EC=97=90?= =?UTF-8?q?=20=EC=9E=88=EB=8A=94=20=EC=84=9C=EB=B2=84=EA=B0=80=20=EC=A3=BD?= =?UTF-8?q?=EC=97=88=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServerConnectionExceptionFilter.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/soma/edupigateway/filter/ServerConnectionExceptionFilter.java diff --git a/src/main/java/soma/edupigateway/filter/ServerConnectionExceptionFilter.java b/src/main/java/soma/edupigateway/filter/ServerConnectionExceptionFilter.java new file mode 100644 index 0000000..22fd240 --- /dev/null +++ b/src/main/java/soma/edupigateway/filter/ServerConnectionExceptionFilter.java @@ -0,0 +1,34 @@ +package soma.edupigateway.filter; + +import java.net.ConnectException; +import java.nio.charset.StandardCharsets; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.io.buffer.DataBuffer; +import org.springframework.core.io.buffer.DataBufferFactory; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; + +@Component +public class ServerConnectionExceptionFilter implements GlobalFilter { + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + return chain.filter(exchange) + .onErrorResume(ConnectException.class, throwable -> handleConnectException(exchange)); + } + + private Mono handleConnectException(ServerWebExchange exchange) { + // 응답 설정 + exchange.getResponse().setStatusCode(HttpStatus.SERVICE_UNAVAILABLE); + + String responseBody = "The backend server is unavailable."; + + DataBufferFactory dataBufferFactory = exchange.getResponse().bufferFactory(); + DataBuffer buffer = dataBufferFactory.wrap(responseBody.getBytes(StandardCharsets.UTF_8)); + + return exchange.getResponse().writeWith(Mono.just(buffer)); + } +} From 1e81c7c16d58d92bad95682b0b07cb90a8fca09d Mon Sep 17 00:00:00 2001 From: GS_song98 <20003204@sju.ac.kr> Date: Wed, 6 Nov 2024 13:04:30 +0900 Subject: [PATCH 53/53] =?UTF-8?q?[#40]fix:=20develop=EC=9D=B4=20=EC=95=84?= =?UTF-8?q?=EB=8B=8C=20main=EC=97=90=20=ED=91=B8=EC=89=AC=EB=90=98?= =?UTF-8?q?=EB=A9=B4=20aws=20=EB=B0=B0=ED=8F=AC=ED=95=98=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ".github/workflows/\bcicd-dev.yml" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/.github/workflows/\bcicd-dev.yml" "b/.github/workflows/\bcicd-dev.yml" index 965043f..b4c2487 100644 --- "a/.github/workflows/\bcicd-dev.yml" +++ "b/.github/workflows/\bcicd-dev.yml" @@ -2,7 +2,7 @@ name: Deploy to Amazon ECS on: push: - branches: [ "develop" ] + branches: [ "main" ] env: AWS_REGION: ap-northeast-2