-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- eureka 애플리케이션 개발 - gateway 애플리케이션 개발 - 멀티 모듈 구조 설계 및 개발
- Loading branch information
Showing
29 changed files
with
993 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "configs"] | ||
path = configs | ||
url = https://github.com/MongLife/monglife-discovery-sub.git | ||
[submodule "core"] | ||
path = core | ||
url = https://github.com/MongLife/monglife-core.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
plugins { | ||
id 'java-library' | ||
id 'org.springframework.boot' version '3.1.1' | ||
id 'io.spring.dependency-management' version '1.1.4' | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
bootJar { | ||
enabled(false) | ||
} | ||
} | ||
|
||
subprojects { | ||
apply plugin: 'java-library' | ||
apply plugin: 'org.springframework.boot' | ||
apply plugin: 'io.spring.dependency-management' | ||
|
||
sourceCompatibility = '17' | ||
|
||
dependencyManagement { | ||
imports { | ||
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2022.0.3" | ||
} | ||
} | ||
|
||
bootJar { | ||
enabled(true) | ||
} | ||
|
||
jar { | ||
enabled(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### yml ### | ||
src/main/resources/application*.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
dependencies { | ||
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-actuator:3.2.1' | ||
runtimeOnly 'io.micrometer:micrometer-registry-prometheus' | ||
} | ||
|
||
tasks.register('copyPrivate', Copy) { | ||
copy { | ||
from '../../configs/monglife-discovery-eureka/' | ||
include 'application*.yml' | ||
into 'src/main/resources' | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...glife-discovery-eureka/src/main/java/com/monglife/discovery/eureka/EurekaApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.monglife.discovery.eureka; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; | ||
|
||
@SpringBootApplication | ||
@EnableEurekaServer | ||
public class EurekaApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(EurekaApplication.class, args); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### yml ### | ||
src/main/resources/application*.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
dependencies { | ||
implementation project(':core') | ||
|
||
compileOnly 'org.projectlombok:lombok' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
|
||
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' | ||
implementation 'org.springframework.cloud:spring-cloud-starter-gateway' | ||
developmentOnly 'org.springframework.boot:spring-boot-devtools' | ||
|
||
implementation 'org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j' | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-actuator:3.2.1' | ||
runtimeOnly 'io.micrometer:micrometer-registry-prometheus' | ||
} | ||
|
||
tasks.register('copyPrivate', Copy) { | ||
copy { | ||
from '../../configs/monglife-discovery-gateway/' | ||
include 'application*.yml' | ||
into 'src/main/resources' | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...fe-discovery-gateway/src/main/java/com/monglife/discovery/gateway/GatewayApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.monglife.discovery.gateway; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
|
||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
public class GatewayApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(GatewayApplication.class, args); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...ain/java/com/monglife/discovery/gateway/business/dto/res/ValidationAccessTokenResDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.monglife.discovery.gateway.business.dto.res; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ValidationAccessTokenResDto( | ||
String accessToken | ||
) { | ||
} |
41 changes: 41 additions & 0 deletions
41
...teway/src/main/java/com/monglife/discovery/gateway/business/service/WebClientService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.monglife.discovery.gateway.business.service; | ||
|
||
import com.monglife.core.vo.passport.PassportDataAccountVo; | ||
import com.monglife.discovery.gateway.business.dto.res.ValidationAccessTokenResDto; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Service | ||
public class WebClientService { | ||
|
||
private final WebClient authWebClient; | ||
|
||
public WebClientService(@Qualifier("authWebClient") WebClient authWebClient) { | ||
this.authWebClient = authWebClient; | ||
} | ||
|
||
public Mono<ValidationAccessTokenResDto> validationAccessToken(String accessToken) { | ||
|
||
String url = "/auth/validation/accessToken?accessToken=%s".formatted(accessToken); | ||
|
||
return authWebClient.get() | ||
.uri(url) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.retrieve() | ||
.bodyToMono(ValidationAccessTokenResDto.class); | ||
} | ||
|
||
public Mono<PassportDataAccountVo> getPassport(String accessToken) { | ||
|
||
String url = "/auth/passport?accessToken=%s".formatted(accessToken); | ||
|
||
return authWebClient.get() | ||
.uri(url) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.retrieve() | ||
.bodyToMono(PassportDataAccountVo.class); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ery-gateway/src/main/java/com/monglife/discovery/gateway/filter/AuthenticationFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.monglife.discovery.gateway.filter; | ||
|
||
import com.monglife.discovery.gateway.business.service.WebClientService; | ||
import com.monglife.discovery.gateway.global.code.error.GatewayErrorCode; | ||
import com.monglife.discovery.gateway.global.exception.error.GenerateException; | ||
import com.monglife.discovery.gateway.global.exception.error.NotFoundException; | ||
import com.monglife.discovery.gateway.global.utils.HttpUtils; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cloud.gateway.filter.GatewayFilter; | ||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; | ||
import org.springframework.http.server.reactive.ServerHttpRequest; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class AuthenticationFilter extends AbstractGatewayFilterFactory<FilterConfig> { | ||
|
||
private final WebClientService webClientService; | ||
private final HttpUtils httpUtils; | ||
|
||
public AuthenticationFilter(WebClientService webClientService, HttpUtils httpUtils) { | ||
super(FilterConfig.class); | ||
this.webClientService = webClientService; | ||
this.httpUtils = httpUtils; | ||
} | ||
|
||
@Override | ||
public GatewayFilter apply(FilterConfig config) { | ||
return (exchange, chain) -> { | ||
ServerHttpRequest request = exchange.getRequest(); | ||
|
||
String accessToken = httpUtils.getHeader(request, "Authorization") | ||
.orElseThrow(() -> new NotFoundException(GatewayErrorCode.ACCESS_TOKEN_NOT_FOUND)) | ||
.substring(7); | ||
|
||
return webClientService.validationAccessToken(accessToken) | ||
.onErrorMap(throwable -> new GenerateException(GatewayErrorCode.ACCESS_TOKEN_EXPIRED)) | ||
.flatMap(validationAccessTokenResDto -> { | ||
|
||
if (config.preLogger) { | ||
log.info("[AuthorizationFilter] AccessToken: {}", accessToken); | ||
} | ||
|
||
return chain.filter(exchange); | ||
}); | ||
}; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...e-discovery-gateway/src/main/java/com/monglife/discovery/gateway/filter/FilterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.monglife.discovery.gateway.filter; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class FilterConfig { | ||
boolean preLogger; | ||
} |
Oops, something went wrong.