Compare commits

..

5 Commits

Author SHA1 Message Date
dongHyo
a14020dfb5 refactor: buildSrc를 통한 의존성 관리 2022-08-14 16:10:04 +09:00
손창현
975e03b7bd add: prometheus (#92) 2022-08-10 14:42:41 +09:00
Kim DongHyo
657c9e7f7d feat: 티켓 구매, 환불 메서드 분산 락 적용 (#86)
* feat: 티켓 구매, 환불 메서드 분산 락 적용

* refactor: aop 를 통한 lock 검증 메서드 분리

* fix: @TicketLock annotations delete
2022-08-05 17:54:45 +09:00
Kim DongHyo
c5b779fda7 fix: 리프레쉬 토큰 업데이트 시 ROLE_이 중복으로 붙여서 나오는 부분 수정 (#90) 2022-08-01 23:45:09 +09:00
손창현
b7057cfc73 Feature/dockerize (#88)
* add: pkcs12 ssl key

* add: application-prod.yml

* add: Dockerfile

* add: redis host, port

* fix: 하단 공백 추가

* refactor: set ddl-auto: validate
2022-08-01 18:32:43 +09:00
11 changed files with 204 additions and 37 deletions

12
server/Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM openjdk:11-jre-slim
ENV APP_HOME=/usr/app/
WORKDIR $APP_HOME
COPY build/libs/server-0.0.1-SNAPSHOT.jar application.jar
EXPOSE 8443
EXPOSE 8080
CMD ["java", "-jar", "application.jar"]

View File

@@ -1,7 +1,13 @@
import Dependencies.AnnotationProcessorLib
import Dependencies.DependencyManagementLib
import Dependencies.ModuleLib
import Dependencies.RuntimeOnlyLib
import Dependencies.TestLib
plugins {
java
id("org.springframework.boot") version "2.6.7"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
id("org.springframework.boot") version Versions.SPRING_BOOT_STARTER
id("io.spring.dependency-management") version Versions.SPRING_DEPENDENCY_MANAGEMENT
}
group = "com.ticketing"
@@ -23,48 +29,50 @@ repositories {
mavenCentral()
}
extra["springCloudVersion"] = "2021.0.3"
extra["springCloudVersion"] = Versions.SPRING_CLOUD
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("org.projectlombok:lombok:1.18.24")
implementation("io.springfox:springfox-boot-starter:3.0.0")
implementation("io.springfox:springfox-swagger-ui:3.0.0")
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
implementation("com.lmax:disruptor:3.4.4")
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
implementation("com.googlecode.json-simple:json-simple:1.1.1")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation ("org.springframework.cloud:spring-cloud-starter-config")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
implementation(Dependencies.SPRING_BOOT_STARTER_DATA_JPA)
implementation(Dependencies.SPRING_BOOT_STARTER_SECURITY)
implementation(Dependencies.SPRING_BOOT_STARTER_VALIDATION)
implementation(Dependencies.SPRING_BOOT_STARTER_WEB)
implementation(Dependencies.SPRING_BOOT_STARTER_ACTUATOR)
implementation(Dependencies.SPRING_BOOT_STARTER_LOG4J2)
implementation(Dependencies.LOMBOK)
implementation(Dependencies.SPRING_FOX_STARTER)
implementation(Dependencies.SWAGGER)
implementation(Dependencies.JASYPT_SPRING_BOOT_STARTER)
implementation(Dependencies.DISRUPTOR)
implementation(Dependencies.JJWT)
implementation(Dependencies.JSON_SIMPLE)
implementation(Dependencies.SPRING_BOOT_STARTER_REDIS)
implementation(Dependencies.JSR350)
implementation(Dependencies.SPRING_CLOUD_STARTER)
implementation(Dependencies.SPRING_CLOUD_FEIGN)
implementation(Dependencies.MICROMETER_CORE)
implementation(Dependencies.MICROMETER_REGISTRY_PROMETHEUS)
modules {
module("org.springframework.boot:spring-boot-starter-logging") {
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
module(ModuleLib.SPRING_BOOT_STARTER_LOGGING) {
replacedBy(ModuleLib.SPRING_BOOT_STARTER_LOG4J2, "Use Log4j2 instead of Logback")
}
}
compileOnly("org.projectlombok:lombok")
runtimeOnly("mysql:mysql-connector-java")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
annotationProcessor("org.projectlombok:lombok")
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
compileOnly(Dependencies.LOMBOK)
runtimeOnly(RuntimeOnlyLib.MYSQL)
runtimeOnly(RuntimeOnlyLib.JJWT_IMPL)
runtimeOnly(RuntimeOnlyLib.JJWT_JACKSON)
annotationProcessor(Dependencies.LOMBOK)
annotationProcessor(AnnotationProcessorLib.SPRING_BOOT_PROCESSOR)
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation(TestLib.JUPITER)
testImplementation(TestLib.SPRING_BOOT_STARTER)
testImplementation(TestLib.SPRING_SECURITY)
}
dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
mavenBom(DependencyManagementLib.SPRING_CLOUD)
}
}

View File

@@ -0,0 +1,8 @@
plugins {
`kotlin-dsl`
}
repositories {
gradlePluginPortal()
mavenCentral()
}

View File

@@ -0,0 +1,56 @@
object Dependencies {
const val SPRING_BOOT_STARTER_DATA_JPA = "org.springframework.boot:spring-boot-starter-data-jpa:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_BOOT_STARTER_SECURITY = "org.springframework.boot:spring-boot-starter-security:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_BOOT_STARTER_VALIDATION = "org.springframework.boot:spring-boot-starter-validation:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_BOOT_STARTER_WEB = "org.springframework.boot:spring-boot-starter-web:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_BOOT_STARTER_ACTUATOR = "org.springframework.boot:spring-boot-starter-actuator:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_BOOT_STARTER_LOG4J2 = "org.springframework.boot:spring-boot-starter-log4j2:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_BOOT_STARTER_REDIS = "org.springframework.boot:spring-boot-starter-data-redis:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_CLOUD_STARTER = "org.springframework.cloud:spring-cloud-starter-config:${Versions.SPRING_CLOUD_STARTER}"
const val SPRING_CLOUD_FEIGN = "org.springframework.cloud:spring-cloud-starter-openfeign:${Versions.SPRING_CLOUD_STARTER}"
const val LOMBOK = "org.projectlombok:lombok:${Versions.LOMBOK}"
const val SPRING_FOX_STARTER = "io.springfox:springfox-boot-starter:${Versions.SPRING_FOX}"
const val SWAGGER = "io.springfox:springfox-swagger-ui:${Versions.SPRING_FOX}"
const val JASYPT_SPRING_BOOT_STARTER = "com.github.ulisesbocchio:jasypt-spring-boot-starter:${Versions.JASYPT}"
const val DISRUPTOR = "com.lmax:disruptor:${Versions.DISRUPTOR}"
const val JJWT = "io.jsonwebtoken:jjwt-api:${Versions.JJWT}"
const val JSON_SIMPLE = "com.googlecode.json-simple:json-simple:${Versions.JSON_SIMPLE}"
const val MICROMETER_CORE = "io.micrometer:micrometer-core:${Versions.MICROMETER}"
const val MICROMETER_REGISTRY_PROMETHEUS = "io.micrometer:micrometer-registry-prometheus:${Versions.MICROMETER}"
const val JSR350 = "com.google.code.findbugs:jsr305:${Versions.JSR350}"
object ModuleLib {
const val SPRING_BOOT_STARTER_LOGGING = "org.springframework.boot:spring-boot-starter-logging"
const val SPRING_BOOT_STARTER_LOG4J2 = "org.springframework.boot:spring-boot-starter-log4j2"
}
object RuntimeOnlyLib {
const val MYSQL = "mysql:mysql-connector-java:${Versions.MYSQL_CONNECTOR_JAVA}"
const val JJWT_IMPL = "io.jsonwebtoken:jjwt-impl:${Versions.JJWT}"
const val JJWT_JACKSON = "io.jsonwebtoken:jjwt-jackson:${Versions.JJWT}"
}
object AnnotationProcessorLib {
const val SPRING_BOOT_PROCESSOR = "org.springframework.boot:spring-boot-configuration-processor:${Versions.SPRING_BOOT_STARTER}"
}
object TestLib {
const val JUPITER = "org.junit.jupiter:junit-jupiter-api:${Versions.JUPITER}"
const val SPRING_BOOT_STARTER = "org.springframework.boot:spring-boot-starter-test:${Versions.SPRING_BOOT_STARTER}"
const val SPRING_SECURITY = "org.springframework.security:spring-security-test:${Versions.SECURITY}"
}
object DependencyManagementLib {
const val SPRING_CLOUD = "org.springframework.cloud:spring-cloud-dependencies:${Versions.SPRING_CLOUD}"
}
}

View File

@@ -0,0 +1,23 @@
object Versions {
const val SPRING_BOOT_STARTER = "2.6.7"
const val SPRING_DEPENDENCY_MANAGEMENT = "1.0.11.RELEASE"
const val SPRING_CLOUD_STARTER = "3.1.3"
const val SPRING_CLOUD = "2021.0.3"
const val MYSQL_CONNECTOR_JAVA = "8.0.28"
const val LOMBOK = "1.18.24"
const val SPRING_FOX = "3.0.0"
const val JASYPT = "3.0.4"
const val DISRUPTOR = "3.4.4"
const val JJWT = "0.11.5"
const val JSON_SIMPLE = "1.1.1"
const val MICROMETER = "1.8.5"
const val JSR350 = "3.0.2"
const val JUPITER = "5.8.1"
const val SECURITY = "5.6.3"
}

View File

@@ -28,8 +28,9 @@ public class RefreshToken {
this.token = token;
}
public void changeToken(String token) {
public RefreshToken changeToken(String token) {
this.token = token;
return this;
}
}

View File

@@ -27,6 +27,7 @@ public class JwtProvider {
private static final String AUTHORITIES_KEY = "auth";
private static final String AUTHORITIES_DELIMITER = ",";
private static final String ROLE = "ROLE_";
private final Key key;
private final String prefix;
@@ -89,7 +90,7 @@ public class JwtProvider {
}
private String makeRoleName(String role) {
return "ROLE_" + role.toUpperCase();
return role.contains(ROLE) ? role.toUpperCase() : ROLE + role.toUpperCase();
}
public Authentication getAuthentication(String token) {

View File

@@ -5,8 +5,8 @@ import com.ticketing.server.global.redis.RefreshRedisRepository;
import com.ticketing.server.global.redis.RefreshToken;
import com.ticketing.server.global.security.jwt.JwtProperties;
import com.ticketing.server.global.security.jwt.JwtProvider;
import com.ticketing.server.user.service.dto.TokenDTO;
import com.ticketing.server.user.service.dto.DeleteRefreshTokenDTO;
import com.ticketing.server.user.service.dto.TokenDTO;
import com.ticketing.server.user.service.interfaces.AuthenticationService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -40,8 +40,14 @@ public class AuthenticationServiceImpl implements AuthenticationService {
// refresh 토큰이 있으면 수정, 없으면 생성
refreshRedisRepository.findByEmail(email)
.ifPresentOrElse(
tokenEntity -> tokenEntity.changeToken(tokenDto.getRefreshToken()),
() -> refreshRedisRepository.save(new RefreshToken(email, tokenDto.getRefreshToken()))
tokenEntity -> refreshRedisRepository.save(
tokenEntity.changeToken(
tokenDto.getRefreshToken()
)
),
() -> refreshRedisRepository.save(
new RefreshToken(email, tokenDto.getRefreshToken())
)
);
return tokenDto;

View File

@@ -0,0 +1,34 @@
server:
port: 8443
address: 0.0.0.0
http:
port: 8080
ssl:
key-store: classpath:keystore/ticketing.p12
key-store-password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
key-store-type: PKCS12
spring:
datasource:
url: jdbc:mysql://ticketing-db/ticketing?serverTimezone=Asia/Seoul&characterEncoding=UTF-8
username: ENC(LowN1n4w0Ep/DqLD8+q5Bq6AXM4b8e3V)
password: ENC(OMvGcpZLpggFTiGNkqNe66Zq/SmJXF6o)
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
properties:
hibernate:
show_sql: true
format_sql: true
hibernate:
ddl-auto: validate
redis:
host: 172.18.0.3
port: 6379
application:
name: monitoring

View File

@@ -26,6 +26,24 @@ spring:
config:
import: "optional:configserver:"
application:
name: monitoring
management:
endpoint:
metrics:
enabled: true
prometheus:
enabled: true
endpoints:
web:
exposure:
include: health, info, metrics, prometheus
metrics:
tags:
application: ${spring.application.name}
jasypt:
encryptor:

Binary file not shown.