Skip to content

Commit

Permalink
Release for v2.0.0
Browse files Browse the repository at this point in the history
- eureka 애플리케이션 개발
- gateway 애플리케이션 개발
- 멀티 모듈 구조 설계 및 개발
  • Loading branch information
tableMinPark authored Aug 3, 2024
2 parents 2ae16c4 + a7a66e7 commit 123ff04
Show file tree
Hide file tree
Showing 29 changed files with 993 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .gitignore
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/
6 changes: 6 additions & 0 deletions .gitmodules
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
38 changes: 38 additions & 0 deletions apps/build.gradle
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)
}
}
40 changes: 40 additions & 0 deletions apps/monglife-discovery-eureka/.gitignore
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
16 changes: 16 additions & 0 deletions apps/monglife-discovery-eureka/build.gradle
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'
}
}
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);
}

}
40 changes: 40 additions & 0 deletions apps/monglife-discovery-gateway/.gitignore
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
24 changes: 24 additions & 0 deletions apps/monglife-discovery-gateway/build.gradle
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'
}
}
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);
}

}
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
) {
}
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);
}
}
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);
});
};
}
}
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;
}
Loading

0 comments on commit 123ff04

Please sign in to comment.