Compare commits
6 Commits
feature/re
...
feature/is
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d54b88aa28 | ||
|
|
7e31cea721 | ||
|
|
fecd48a160 | ||
|
|
55cbab0a58 | ||
|
|
e4003972fe | ||
|
|
cf9f5aa87f |
9
.idea/Ticketing.iml
generated
9
.idea/Ticketing.iml
generated
@@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$" />
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
8
.idea/modules.xml
generated
8
.idea/modules.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ProjectModuleManager">
|
|
||||||
<modules>
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/Ticketing.iml" filepath="$PROJECT_DIR$/.idea/Ticketing.iml" />
|
|
||||||
</modules>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
10
.idea/runConfigurations.xml
generated
10
.idea/runConfigurations.xml
generated
@@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RunConfigurationProducerService">
|
|
||||||
<option name="ignoredProducers">
|
|
||||||
<set>
|
|
||||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
33
.idea/workspace.xml
generated
33
.idea/workspace.xml
generated
@@ -1,33 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ChangeListManager">
|
|
||||||
<list default="true" id="2a93e153-a90c-44db-b1da-6c4424693422" name="Changes" comment="" />
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
||||||
</component>
|
|
||||||
<component name="Git.Settings">
|
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectId" id="29uM8tIDp7UqdPYE3auX216NPaN" />
|
|
||||||
<component name="ProjectViewState">
|
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
|
||||||
<option name="showLibraryContents" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="PropertiesComponent">
|
|
||||||
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
|
|
||||||
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
|
|
||||||
</component>
|
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
||||||
<component name="TaskManager">
|
|
||||||
<task active="true" id="Default" summary="Default task">
|
|
||||||
<changelist id="2a93e153-a90c-44db-b1da-6c4424693422" name="Changes" comment="" />
|
|
||||||
<created>1653958362269</created>
|
|
||||||
<option name="number" value="Default" />
|
|
||||||
<option name="presentableId" value="Default" />
|
|
||||||
<updated>1653958362269</updated>
|
|
||||||
</task>
|
|
||||||
<servers />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
81
README.md
81
README.md
@@ -14,85 +14,4 @@
|
|||||||
## 🎯 프로젝트 목표
|
## 🎯 프로젝트 목표
|
||||||
|
|
||||||
|
|
||||||
<br/><br/>
|
|
||||||
|
|
||||||
## 🧩 ERD
|
|
||||||
|
|
||||||
``` mermaid
|
|
||||||
erDiagram
|
|
||||||
MOVIE ||--o{ MOVIE_TIMES : ""
|
|
||||||
MOVIE {
|
|
||||||
bigint id PK "영화 ID"
|
|
||||||
varchar title "영화제목"
|
|
||||||
int running_time "러닝타임"
|
|
||||||
datetime created_at "등록일시"
|
|
||||||
datetime updated_at "수정일시"
|
|
||||||
}
|
|
||||||
THEATER ||--o{ MOVIE_TIMES : ""
|
|
||||||
THEATER ||--|{ SEAT : ""
|
|
||||||
THEATER {
|
|
||||||
bigint id PK "상영관 ID"
|
|
||||||
int theater_number "상영관 번호"
|
|
||||||
int seat_count "좌석수"
|
|
||||||
datetime created_at "등록일시"
|
|
||||||
datetime updated_at "수정일시"
|
|
||||||
}
|
|
||||||
SEAT ||--o{ TICKET : ""
|
|
||||||
SEAT {
|
|
||||||
bigint id PK "좌석 ID"
|
|
||||||
bigint theater_id FK "상영관 ID"
|
|
||||||
int column "열"
|
|
||||||
int row "행"
|
|
||||||
datetime created_at "등록일시"
|
|
||||||
datetime updated_at "수정일시"
|
|
||||||
}
|
|
||||||
MOVIE_TIMES ||--o{ TICKET : ""
|
|
||||||
MOVIE_TIMES {
|
|
||||||
bigint id PK "상영시간표 ID"
|
|
||||||
bigint movie_id FK "영화 ID"
|
|
||||||
bigint theater_id FK "상영관 ID"
|
|
||||||
date running_date "상영 날짜"
|
|
||||||
int round "회차"
|
|
||||||
time start_at "시작 시간"
|
|
||||||
time end_at "종료 시간"
|
|
||||||
datetime created_at "등록일시"
|
|
||||||
datetime updated_at "수정일시"
|
|
||||||
}
|
|
||||||
TICKET {
|
|
||||||
bigint id PK "티켓 ID"
|
|
||||||
bigint seat_id FK "좌석 ID"
|
|
||||||
bigint movie_times_id FK "상영시간표 ID"
|
|
||||||
bigint payment_id FK "결제 ID"
|
|
||||||
varchar status "상태 - 구매가능/예약진행중/판매완료"
|
|
||||||
int ticket_price "가격"
|
|
||||||
datetime created_at "등록일시"
|
|
||||||
datetime updated_at "수정일시"
|
|
||||||
}
|
|
||||||
TICKET }|--|| PAYMENT : ""
|
|
||||||
PAYMENT {
|
|
||||||
bigint id PK "결제 ID"
|
|
||||||
bigint user_id FK "유저ID"
|
|
||||||
varchar type "결제 타입 - 예) 네이버페이, 카카오페이"
|
|
||||||
varchar status "상태 - 완료/환불/실패"
|
|
||||||
varchar failed_message "실패사유 - 컬럼명을 알아보기 쉬운가?"
|
|
||||||
varchar payment_number "예매번호"
|
|
||||||
int total_price "결제 금액"
|
|
||||||
datetime created_at "결제일시"
|
|
||||||
datetime updated_at "수정일시"
|
|
||||||
}
|
|
||||||
USER ||--o{ PAYMENT : ""
|
|
||||||
USER {
|
|
||||||
bigint id "회원"
|
|
||||||
varchar name "이름"
|
|
||||||
varchar email "이메일"
|
|
||||||
varchar password "비밀번호"
|
|
||||||
varchar grade "등급 - 고객/임직원"
|
|
||||||
varchar phone "휴대폰 번호"
|
|
||||||
boolean is_deleted "탈퇴여부"
|
|
||||||
datetime deleted_at "탈퇴일시"
|
|
||||||
datetime created_at "가입일시"
|
|
||||||
datetime updated_at "수정일시"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
## 작업 분류
|
## 작업 내용
|
||||||
- [ ] 기능 추가
|
- [ ] 기능 추가
|
||||||
- [ ] 코드 수정
|
- [ ] 코드 수정
|
||||||
- [ ] 환경 설정
|
- [ ] 환경 설정
|
||||||
@@ -30,3 +30,4 @@
|
|||||||
- [ ] 구현 사항에 대한 테스트를 완료했습니다.
|
- [ ] 구현 사항에 대한 테스트를 완료했습니다.
|
||||||
- [ ] 의도한 내용 이외에 다른 코드에는 변경 사항이 없는지 확인했습니다.
|
- [ ] 의도한 내용 이외에 다른 코드에는 변경 사항이 없는지 확인했습니다.
|
||||||
- [ ] 코드 스타일을 적용하여 팀 코딩 컨벤션에 맞게 작성했습니다.
|
- [ ] 코드 스타일을 적용하여 팀 코딩 컨벤션에 맞게 작성했습니다.
|
||||||
|
- [ ] 팀원 모두 구현 내용 및 코드에 대해 이해하고 있습니다.
|
||||||
3
server/.gitignore
vendored
3
server/.gitignore
vendored
@@ -200,7 +200,4 @@ gradle-app.setting
|
|||||||
# JDT-specific (Eclipse Java Development Tools)
|
# JDT-specific (Eclipse Java Development Tools)
|
||||||
.classpath
|
.classpath
|
||||||
|
|
||||||
# log
|
|
||||||
/logs
|
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,visualstudiocode
|
# End of https://www.toptal.com/developers/gitignore/api/macos,windows,intellij+all,gradle,visualstudiocode
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
id("org.springframework.boot") version "2.6.7"
|
id ("org.springframework.boot") version "2.6.7"
|
||||||
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
id ("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "com.ticketing"
|
group = "com.ticketing"
|
||||||
@@ -9,60 +9,36 @@ version = "0.0.1-SNAPSHOT"
|
|||||||
|
|
||||||
val javaVersion = JavaVersion.VERSION_11
|
val javaVersion = JavaVersion.VERSION_11
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = javaVersion
|
sourceCompatibility = javaVersion
|
||||||
targetCompatibility = javaVersion
|
targetCompatibility = javaVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
compileOnly {
|
compileOnly {
|
||||||
extendsFrom(configurations.annotationProcessor.get())
|
extendsFrom(configurations.annotationProcessor.get())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
implementation ("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-security")
|
implementation ("org.springframework.boot:spring-boot-starter-security")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-validation")
|
implementation ("org.springframework.boot:spring-boot-starter-validation")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
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.20")
|
|
||||||
implementation("io.springfox:springfox-swagger2: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.2")
|
|
||||||
implementation("io.jsonwebtoken:jjwt-api:0.11.2")
|
|
||||||
implementation("com.googlecode.json-simple:json-simple:1.1.1")
|
|
||||||
implementation("org.springframework.boot:spring-boot-starter-data-redis")
|
|
||||||
|
|
||||||
modules {
|
implementation ("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
|
||||||
module("org.springframework.boot:spring-boot-starter-logging") {
|
|
||||||
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
compileOnly ("org.projectlombok:lombok")
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
runtimeOnly ("mysql:mysql-connector-java")
|
||||||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
|
annotationProcessor ("org.projectlombok:lombok")
|
||||||
|
|
||||||
compileOnly("org.projectlombok:lombok")
|
testImplementation ("org.springframework.boot:spring-boot-starter-test")
|
||||||
runtimeOnly("mysql:mysql-connector-java")
|
testImplementation ("org.springframework.security:spring-security-test")
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.2")
|
|
||||||
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.2")
|
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
|
||||||
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
|
||||||
|
|
||||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
|
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType<Test> {
|
tasks.withType<Test> {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
package com.ticketing.server;
|
package com.ticketing.server;
|
||||||
|
|
||||||
import com.ticketing.server.global.security.jwt.JwtProperties;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
|
||||||
|
|
||||||
@EnableJpaAuditing
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableConfigurationProperties(JwtProperties.class)
|
|
||||||
public class ServerApplication {
|
public class ServerApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.ticketing.server.global.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
|
||||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class MessagesConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ResourceBundleMessageSource messageSource() {
|
|
||||||
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
|
|
||||||
messageSource.setBasename("i18n/messages");
|
|
||||||
messageSource.setDefaultEncoding("UTF-8");
|
|
||||||
|
|
||||||
return messageSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public LocalValidatorFactoryBean getValidator() {
|
|
||||||
LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean();
|
|
||||||
factoryBean.setValidationMessageSource(messageSource());
|
|
||||||
|
|
||||||
return factoryBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.ticketing.server.global.config;
|
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.time.Duration;
|
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.client.BufferingClientHttpRequestFactory;
|
|
||||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class RestTemplateConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
|
|
||||||
return restTemplateBuilder
|
|
||||||
.requestFactory(() -> new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()))
|
|
||||||
.setConnectTimeout(Duration.ofMillis(5000)) // connection-timeout
|
|
||||||
.setReadTimeout(Duration.ofMillis(5000)) // read-timeout
|
|
||||||
.additionalMessageConverters(new StringHttpMessageConverter(Charset.forName("UTF-8")))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
package com.ticketing.server.global.config;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.builders.ApiInfoBuilder;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.service.ApiInfo;
|
|
||||||
import springfox.documentation.service.ApiKey;
|
|
||||||
import springfox.documentation.service.AuthorizationScope;
|
|
||||||
import springfox.documentation.service.SecurityReference;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spi.service.contexts.SecurityContext;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger.web.UiConfiguration;
|
|
||||||
import springfox.documentation.swagger.web.UiConfigurationBuilder;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class SwaggerConfig {
|
|
||||||
|
|
||||||
public static final String SECURITY_SCHEMA_NAME = "Authorization";
|
|
||||||
public static final String AUTHORIZATION_SCOPE_GLOBAL = "global";
|
|
||||||
public static final String AUTHORIZATION_SCOPE_GLOBAL_DESC = "accessEverything";
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Docket api() {
|
|
||||||
return new Docket(DocumentationType.OAS_30)
|
|
||||||
.useDefaultResponseMessages(false)
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.any())
|
|
||||||
.paths(PathSelectors.ant("/api/**")).build()
|
|
||||||
.apiInfo(apiInfo())
|
|
||||||
.securityContexts(Arrays.asList(securityContext()))
|
|
||||||
.securitySchemes(Arrays.asList(apiKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiInfo apiInfo() {
|
|
||||||
return new ApiInfoBuilder()
|
|
||||||
.title("Ticketing REST API Document")
|
|
||||||
.version("v1")
|
|
||||||
.description("Ticketing REST API 문서").build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ApiKey apiKey() {
|
|
||||||
return new ApiKey(SECURITY_SCHEMA_NAME, "Authorization", "header");
|
|
||||||
}
|
|
||||||
|
|
||||||
private SecurityContext securityContext() {
|
|
||||||
return SecurityContext.builder().securityReferences(defaultAuth()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<SecurityReference> defaultAuth() {
|
|
||||||
AuthorizationScope authorizationScope = new AuthorizationScope(AUTHORIZATION_SCOPE_GLOBAL,
|
|
||||||
AUTHORIZATION_SCOPE_GLOBAL_DESC);
|
|
||||||
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
|
|
||||||
authorizationScopes[0] = authorizationScope;
|
|
||||||
return Arrays.asList(new SecurityReference(SECURITY_SCHEMA_NAME, authorizationScopes));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
UiConfiguration uiConfig() {
|
|
||||||
return UiConfigurationBuilder.builder()
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package com.ticketing.server.global.dto.repository;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.EntityListeners;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.MappedSuperclass;
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
|
||||||
import org.springframework.data.annotation.LastModifiedDate;
|
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
|
||||||
|
|
||||||
@MappedSuperclass
|
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
|
||||||
@Getter
|
|
||||||
public abstract class AbstractEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(nullable = false, updatable = false)
|
|
||||||
@CreatedDate
|
|
||||||
private LocalDateTime createdAt;
|
|
||||||
|
|
||||||
@LastModifiedDate
|
|
||||||
private LocalDateTime updatedAt;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.global.exception;
|
|
||||||
|
|
||||||
public class AlreadyDeletedException extends RuntimeException {
|
|
||||||
|
|
||||||
public AlreadyDeletedException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.ticketing.server.global.exception;
|
|
||||||
|
|
||||||
public class EmailNotFoundException extends IllegalArgumentException {
|
|
||||||
|
|
||||||
private static final String MESSAGE = "존재하지 않는 이메일 입니다.";
|
|
||||||
|
|
||||||
public EmailNotFoundException() {
|
|
||||||
super(MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.ticketing.server.global.exception;
|
|
||||||
|
|
||||||
public class PasswordMismatchException extends RuntimeException {
|
|
||||||
|
|
||||||
private static final String MESSAGE = "패스워드가 일치하지 않습니다";
|
|
||||||
|
|
||||||
public PasswordMismatchException() {
|
|
||||||
super(MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.global.exception.token;
|
|
||||||
|
|
||||||
public class TokenException extends RuntimeException {
|
|
||||||
|
|
||||||
public TokenException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.global.exception.token;
|
|
||||||
|
|
||||||
public class TokenNotFindException extends TokenException {
|
|
||||||
|
|
||||||
private static final String MESSAGE = "일치하는 토큰을 찾지 못하였습니다.";
|
|
||||||
|
|
||||||
public TokenNotFindException() {
|
|
||||||
super(MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.global.exception.token;
|
|
||||||
|
|
||||||
public class TokenTypeException extends TokenException {
|
|
||||||
|
|
||||||
private static final String MESSAGE = "토큰 타입이 일치하지 않습니다.";
|
|
||||||
|
|
||||||
public TokenTypeException() {
|
|
||||||
super(MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package com.ticketing.server.global.exception.token;
|
|
||||||
|
|
||||||
public class UnavailableRefreshTokenException extends TokenException {
|
|
||||||
|
|
||||||
private static final String MESSAGE = "사용할 수 없는 refresh Token 입니다.";
|
|
||||||
|
|
||||||
public UnavailableRefreshTokenException() {
|
|
||||||
super(MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.ticketing.server.global.factory;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Properties;
|
|
||||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
|
||||||
import org.springframework.core.env.PropertiesPropertySource;
|
|
||||||
import org.springframework.core.env.PropertySource;
|
|
||||||
import org.springframework.core.io.support.EncodedResource;
|
|
||||||
import org.springframework.core.io.support.PropertySourceFactory;
|
|
||||||
import org.springframework.lang.Nullable;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
public class YamlPropertySourceFactory implements PropertySourceFactory {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySource<?> createPropertySource(@Nullable String name, EncodedResource resource) {
|
|
||||||
Properties yamlProperties = loadYamlProperties(resource);
|
|
||||||
String sourceName = StringUtils.hasText(name) ? name : resource.getResource().getFilename();
|
|
||||||
return new PropertiesPropertySource(Objects.requireNonNull(sourceName), Objects.requireNonNull(yamlProperties));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Properties loadYamlProperties(EncodedResource resource) {
|
|
||||||
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
|
|
||||||
factory.setResources(resource.getResource());
|
|
||||||
return factory.getObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package com.ticketing.server.global.health;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.boot.actuate.health.Status;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/l7check")
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class L7checkController {
|
|
||||||
|
|
||||||
private final MutableHealthIndicator indicator;
|
|
||||||
|
|
||||||
@GetMapping
|
|
||||||
public ResponseEntity<Object> health() {
|
|
||||||
Health health = indicator.health();
|
|
||||||
boolean isUp = health.getStatus().equals(Status.UP);
|
|
||||||
return ResponseEntity
|
|
||||||
.status(isUp ? HttpStatus.OK : HttpStatus.SERVICE_UNAVAILABLE)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping
|
|
||||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
|
||||||
public void down() {
|
|
||||||
indicator.setHealth(Health.down().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
@ResponseStatus(HttpStatus.CREATED)
|
|
||||||
public void up() {
|
|
||||||
indicator.setHealth(Health.up().build());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package com.ticketing.server.global.health;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class ManualHealthIndicator implements MutableHealthIndicator {
|
|
||||||
|
|
||||||
private final AtomicReference<Health> healthRef = new AtomicReference<>(Health.up().build());
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setHealth(Health health) {
|
|
||||||
healthRef.set(health);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Health health() {
|
|
||||||
return healthRef.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.global.health;
|
|
||||||
|
|
||||||
import org.springframework.boot.actuate.health.Health;
|
|
||||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
|
||||||
|
|
||||||
public interface MutableHealthIndicator extends HealthIndicator {
|
|
||||||
|
|
||||||
void setHealth(Health health);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package com.ticketing.server.global.redis;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
||||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
|
||||||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
|
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
|
||||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableRedisRepositories
|
|
||||||
public class RedisConfig {
|
|
||||||
|
|
||||||
@Value("${spring.redis.host}")
|
|
||||||
private String host;
|
|
||||||
|
|
||||||
@Value("${spring.redis.port}")
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RedisConnectionFactory redisConnectionFactory() {
|
|
||||||
return new LettuceConnectionFactory(host, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RedisTemplate<String, Object> redisTemplate() {
|
|
||||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
|
||||||
redisTemplate.setConnectionFactory(redisConnectionFactory());
|
|
||||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
|
||||||
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
|
||||||
|
|
||||||
return redisTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PlatformTransactionManager transactionManager() {
|
|
||||||
return new JpaTransactionManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.global.redis;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
|
||||||
|
|
||||||
public interface RefreshRedisRepository extends CrudRepository<RefreshToken, Long> {
|
|
||||||
|
|
||||||
Optional<RefreshToken> findByEmail(String email);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.ticketing.server.global.redis;
|
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.data.redis.core.RedisHash;
|
|
||||||
import org.springframework.data.redis.core.index.Indexed;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RedisHash("RefreshToken")
|
|
||||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
|
||||||
public class RefreshToken {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
@Column(name = "refresh_token_id")
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Indexed
|
|
||||||
private String email;
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
public RefreshToken(String email, String token) {
|
|
||||||
this.email = email;
|
|
||||||
this.token = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void changeToken(String token) {
|
|
||||||
this.token = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.ticketing.server.global.security;
|
|
||||||
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
|
|
||||||
public class SecurityUtil {
|
|
||||||
|
|
||||||
private SecurityUtil() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCurrentUserEmail() {
|
|
||||||
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
||||||
|
|
||||||
if (authentication == null || authentication.getName() == null) {
|
|
||||||
throw new IllegalStateException("Security Context 에 인증 정보가 없습니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return authentication.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package com.ticketing.server.global.security;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.security.jwt.JwtFilter;
|
|
||||||
import com.ticketing.server.global.security.jwt.JwtSecurityConfig;
|
|
||||||
import com.ticketing.server.global.security.jwt.handle.JwtAccessDeniedHandler;
|
|
||||||
import com.ticketing.server.global.security.jwt.handle.JwtAuthenticationEntryPoint;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
|
||||||
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableWebSecurity
|
|
||||||
@EnableGlobalMethodSecurity(securedEnabled = true)
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|
||||||
|
|
||||||
private final JwtFilter jwtFilter;
|
|
||||||
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
|
|
||||||
private final JwtAccessDeniedHandler jwtAccessDeniedHandler;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public PasswordEncoder passwordEncoder() {
|
|
||||||
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
|
||||||
|
|
||||||
http
|
|
||||||
.csrf().disable()
|
|
||||||
.exceptionHandling()
|
|
||||||
.authenticationEntryPoint(jwtAuthenticationEntryPoint)
|
|
||||||
.accessDeniedHandler(jwtAccessDeniedHandler)
|
|
||||||
|
|
||||||
.and()
|
|
||||||
.headers()
|
|
||||||
.frameOptions()
|
|
||||||
.sameOrigin()
|
|
||||||
|
|
||||||
// 시큐리티는 기본적으로 세션을 사용하지만, jwt 을 위해 세션을 Stateless 로 설정
|
|
||||||
.and()
|
|
||||||
.sessionManagement()
|
|
||||||
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
|
||||||
|
|
||||||
.and()
|
|
||||||
.authorizeRequests()
|
|
||||||
.antMatchers(HttpMethod.POST, "/api/user/login").permitAll()
|
|
||||||
.antMatchers(HttpMethod.POST, "/api/user/refresh").permitAll()
|
|
||||||
.antMatchers(HttpMethod.POST, "/api/user").permitAll()
|
|
||||||
.antMatchers("/l7check").permitAll()
|
|
||||||
.antMatchers("/actuator/health").permitAll()
|
|
||||||
.anyRequest().authenticated()
|
|
||||||
|
|
||||||
.and()
|
|
||||||
.apply(new JwtSecurityConfig(jwtFilter));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.jwt;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
public class JwtFilter extends OncePerRequestFilter {
|
|
||||||
|
|
||||||
private final JwtProvider tokenProvider;
|
|
||||||
private final JwtProperties jwtProperties;
|
|
||||||
|
|
||||||
public JwtFilter(JwtProperties jwtProperties, JwtProvider tokenProvider) {
|
|
||||||
this.jwtProperties = jwtProperties;
|
|
||||||
this.tokenProvider = tokenProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
|
|
||||||
String jwt = resolveToken(request);
|
|
||||||
|
|
||||||
// 토큰이 정상이면 Authentication 을 가져와서 SecurityContext 에 저장
|
|
||||||
if (StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) {
|
|
||||||
Authentication authentication = tokenProvider.getAuthentication(jwt);
|
|
||||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
||||||
}
|
|
||||||
|
|
||||||
chain.doFilter(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String resolveToken(HttpServletRequest request) {
|
|
||||||
String bearerToken = request.getHeader(jwtProperties.getAccessHeader());
|
|
||||||
if (StringUtils.hasText(bearerToken) && jwtProperties.hasTokenStartsWith(bearerToken)) {
|
|
||||||
return bearerToken.substring(7);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.jwt;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.factory.YamlPropertySourceFactory;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
|
||||||
import org.springframework.context.annotation.PropertySource;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@ConstructorBinding
|
|
||||||
@ConfigurationProperties(value = "jwt")
|
|
||||||
@PropertySource(value = "classpath:application.yml", factory = YamlPropertySourceFactory.class)
|
|
||||||
public class JwtProperties {
|
|
||||||
|
|
||||||
private final String accessHeader;
|
|
||||||
private final String refreshHeader;
|
|
||||||
private final String prefix;
|
|
||||||
private final String secretKey;
|
|
||||||
private final Integer accessTokenValidityInSeconds;
|
|
||||||
private final Integer refreshTokenValidityInSeconds;
|
|
||||||
|
|
||||||
public boolean hasTokenStartsWith(String token) {
|
|
||||||
return token.startsWith(prefix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.jwt;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.application.response.TokenDto;
|
|
||||||
import io.jsonwebtoken.Claims;
|
|
||||||
import io.jsonwebtoken.Jwts;
|
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
|
||||||
import io.jsonwebtoken.io.Decoders;
|
|
||||||
import io.jsonwebtoken.security.Keys;
|
|
||||||
import java.security.Key;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
import org.springframework.security.core.userdetails.User;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class JwtProvider {
|
|
||||||
|
|
||||||
private static final String AUTHORITIES_KEY = "auth";
|
|
||||||
private static final String AUTHORITIES_DELIMITER = ",";
|
|
||||||
|
|
||||||
private final Key key;
|
|
||||||
private final String prefix;
|
|
||||||
private final long accessTokenValidityInMilliseconds;
|
|
||||||
private final long refreshTokenValidityInMilliseconds;
|
|
||||||
|
|
||||||
public JwtProvider(JwtProperties jwtProperties) {
|
|
||||||
byte[] keyBytes = Decoders.BASE64.decode(jwtProperties.getSecretKey());
|
|
||||||
this.key = Keys.hmacShaKeyFor(keyBytes);
|
|
||||||
|
|
||||||
this.prefix = jwtProperties.getPrefix();
|
|
||||||
this.accessTokenValidityInMilliseconds = jwtProperties.getAccessTokenValidityInSeconds() * 1000L;
|
|
||||||
this.refreshTokenValidityInMilliseconds = jwtProperties.getRefreshTokenValidityInSeconds() * 1000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TokenDto generateTokenDto(Authentication authentication) {
|
|
||||||
String accessToken = createAccessToken(authentication);
|
|
||||||
String refreshToken = createRefreshToken(authentication);
|
|
||||||
long expiresIn = accessTokenValidityInMilliseconds / 1000L;
|
|
||||||
|
|
||||||
return TokenDto.of(accessToken, refreshToken, prefix, expiresIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createAccessToken(Authentication authentication) {
|
|
||||||
// 만료시간 계산
|
|
||||||
long now = (new Date()).getTime();
|
|
||||||
Date accessTokenExpiresIn = new Date(now + this.accessTokenValidityInMilliseconds);
|
|
||||||
|
|
||||||
return createToken(authentication, accessTokenExpiresIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createRefreshToken(Authentication authentication) {
|
|
||||||
// 만료시간 계산
|
|
||||||
long now = (new Date()).getTime();
|
|
||||||
Date refreshTokenExpiresIn = new Date(now + this.refreshTokenValidityInMilliseconds);
|
|
||||||
|
|
||||||
return createToken(authentication, refreshTokenExpiresIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createToken(Authentication authentication, Date expiration) {
|
|
||||||
// 권한 정보 가져오기
|
|
||||||
String authorities = generateStringToAuthorities(authentication);
|
|
||||||
|
|
||||||
// JWT 생성
|
|
||||||
return Jwts.builder()
|
|
||||||
.setSubject(authentication.getName()) // email
|
|
||||||
.claim(AUTHORITIES_KEY, authorities) // payload
|
|
||||||
.setExpiration(expiration) // 만료일
|
|
||||||
.signWith(key, SignatureAlgorithm.HS512) // 서명 키 값
|
|
||||||
.compact();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String generateStringToAuthorities(Authentication authentication) {
|
|
||||||
StringJoiner authorities = new StringJoiner(AUTHORITIES_DELIMITER);
|
|
||||||
for (GrantedAuthority grantedAuthority : authentication.getAuthorities()) {
|
|
||||||
String roleName = makeRoleName(grantedAuthority.getAuthority());
|
|
||||||
authorities.add(roleName);
|
|
||||||
}
|
|
||||||
return authorities.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String makeRoleName(String role) {
|
|
||||||
return "ROLE_" + role.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Authentication getAuthentication(String token) {
|
|
||||||
// 토큰 복호화
|
|
||||||
Claims claims = parseClaims(token);
|
|
||||||
|
|
||||||
// 권한조회
|
|
||||||
List<SimpleGrantedAuthority> authorities =
|
|
||||||
Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(AUTHORITIES_DELIMITER))
|
|
||||||
.map(SimpleGrantedAuthority::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
UserDetails principal = new User(claims.getSubject(), "", authorities);
|
|
||||||
return new UsernamePasswordAuthenticationToken(principal, token, authorities);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean validateToken(String token) {
|
|
||||||
parseClaims(token);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Claims parseClaims(String token) {
|
|
||||||
return Jwts.parserBuilder()
|
|
||||||
.setSigningKey(key)
|
|
||||||
.build()
|
|
||||||
.parseClaimsJws(token)
|
|
||||||
.getBody();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.jwt;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|
||||||
import org.springframework.security.web.DefaultSecurityFilterChain;
|
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class JwtSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {
|
|
||||||
|
|
||||||
private final JwtFilter jwtFilter;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void configure(HttpSecurity builder) {
|
|
||||||
builder.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.jwt.handle;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
|
||||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class JwtAccessDeniedHandler implements AccessDeniedHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException {
|
|
||||||
response.sendError(HttpServletResponse.SC_FORBIDDEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.jwt.handle;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import org.springframework.security.core.AuthenticationException;
|
|
||||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
|
|
||||||
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.ticketing.server.global.security.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
|
||||||
import java.util.Collections;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class CustomUserDetailsService implements UserDetailsService {
|
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
|
|
||||||
return userRepository.findByEmailAndIsDeletedFalse(email)
|
|
||||||
.map(this::createUserDetails)
|
|
||||||
.orElseThrow(() -> new UsernameNotFoundException("존재하지 않는 email 입니다. :: " + email));
|
|
||||||
}
|
|
||||||
|
|
||||||
private UserDetails createUserDetails(User user) {
|
|
||||||
SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(user.getGrade().name());
|
|
||||||
|
|
||||||
return new org.springframework.security.core.userdetails.User(
|
|
||||||
user.getEmail()
|
|
||||||
, user.getPassword()
|
|
||||||
, Collections.singleton(grantedAuthority)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.ticketing.server.global.validator.constraints;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraintvalidators.PhoneValidator;
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
import javax.validation.Constraint;
|
|
||||||
import javax.validation.Payload;
|
|
||||||
|
|
||||||
@Target(ElementType.FIELD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Constraint(validatedBy = {PhoneValidator.class})
|
|
||||||
@Documented
|
|
||||||
public @interface Phone {
|
|
||||||
|
|
||||||
String message() default "{validation.phone}";
|
|
||||||
|
|
||||||
Class<?>[] groups() default {};
|
|
||||||
|
|
||||||
Class<? extends Payload>[] payload() default {};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.ticketing.server.global.validator.constraintvalidators;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import javax.validation.ConstraintValidator;
|
|
||||||
import javax.validation.ConstraintValidatorContext;
|
|
||||||
|
|
||||||
public class PhoneValidator implements ConstraintValidator<Phone, String> {
|
|
||||||
|
|
||||||
private static final String PATTERN = "\\d{3}-\\d{4}-\\d{4}";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isValid(String value, ConstraintValidatorContext context) {
|
|
||||||
if (value == null || value.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Pattern.matches(PATTERN, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.ticketing.server.movie.application;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class MovieController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.ticketing.server.movie.application;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class MovieTimesController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.ticketing.server.movie.application;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class SeatController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.ticketing.server.movie.application;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class TheaterController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.ticketing.server.movie.application;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class TicketController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Movie extends AbstractEntity {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Column(unique = true)
|
|
||||||
private String title;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer runningTime;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
public class MovieTimes extends AbstractEntity {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "movie_id", referencedColumnName = "id", updatable = false)
|
|
||||||
private Movie movie;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "theater_id", referencedColumnName = "id", updatable = false)
|
|
||||||
private Theater theater;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private LocalDate runningDate;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer round;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private LocalDateTime startAt;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private LocalDateTime endAt;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
public class Seat extends AbstractEntity {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "theater_id", referencedColumnName = "id", updatable = false)
|
|
||||||
private Theater theater;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer seatColumn;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer seatRow;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class Theater extends AbstractEntity {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer theaterNumber;
|
|
||||||
|
|
||||||
private Integer seatCount;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
|
||||||
import com.ticketing.server.payment.domain.Payment;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
public class Ticket extends AbstractEntity {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "seat_id", referencedColumnName = "id", updatable = false)
|
|
||||||
private Seat seat;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "movie_times_id", referencedColumnName = "id", updatable = false)
|
|
||||||
private MovieTimes movieTimes;
|
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "payment_id", referencedColumnName = "id", updatable = false)
|
|
||||||
private Payment payment;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private TicketStatus status;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer ticketPrice;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum TicketStatus {
|
|
||||||
SALE("판매가능"),
|
|
||||||
SCHEDULED("환불"),
|
|
||||||
SOLD("판매완료");
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.Movie;
|
|
||||||
import java.util.Optional;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface MovieRepository extends JpaRepository<Movie, Long> {
|
|
||||||
|
|
||||||
Optional<Movie> findByTitle(String title);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.MovieTimes;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface MovieTimesRepository extends JpaRepository<MovieTimes, Long> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.Seat;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface SeatRepository extends JpaRepository<Seat, Long> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.Theater;
|
|
||||||
import java.util.Optional;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface TheaterRepository extends JpaRepository<Theater, Long> {
|
|
||||||
|
|
||||||
Optional<Theater> findByTheaterNumber(Integer theaterNumber);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.movie.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.domain.Ticket;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface TicketRepository extends JpaRepository<Ticket, Long> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.MovieService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class MovieServiceImpl implements MovieService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.MovieTimesService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class MovieTimesServiceImpl implements MovieTimesService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.SeatService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SeatServiceImpl implements SeatService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.TMDBService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class TMBDServiceImpl implements TMDBService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.TheaterService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class TheaterServiceImpl implements TheaterService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.movie.service.interfaces.TicketService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class TicketServiceImpl implements TicketService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface MovieService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface MovieTimesService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface SeatService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface TMDBService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface TheaterService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.movie.service.interfaces;
|
|
||||||
|
|
||||||
public interface TicketService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.ticketing.server.payment.application;
|
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
public class PaymentController {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.ticketing.server.payment.domain;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
public class Payment extends AbstractEntity {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "user_id", referencedColumnName = "id", updatable = false)
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
|
||||||
private PaymentType type;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
|
||||||
private PaymentStatus status;
|
|
||||||
|
|
||||||
private String failedMessage;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String paymentNumber;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Integer totalPrice;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.payment.domain;
|
|
||||||
|
|
||||||
public enum PaymentStatus {
|
|
||||||
COMPLETED, REFUNDED, FAILED
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.payment.domain;
|
|
||||||
|
|
||||||
public enum PaymentType {
|
|
||||||
KAKAO_PAY
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package com.ticketing.server.payment.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.payment.domain.Payment;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package com.ticketing.server.payment.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.payment.service.interfaces.PaymentService;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class PaymentServiceImpl implements PaymentService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.payment.service.interfaces;
|
|
||||||
|
|
||||||
public interface PaymentService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package com.ticketing.server.user.application;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.security.jwt.JwtProperties;
|
|
||||||
import com.ticketing.server.user.application.request.LoginRequest;
|
|
||||||
import com.ticketing.server.user.application.request.SignUpRequest;
|
|
||||||
import com.ticketing.server.user.application.request.UserDeleteRequest;
|
|
||||||
import com.ticketing.server.user.application.request.UserModifyPasswordRequest;
|
|
||||||
import com.ticketing.server.user.application.response.SignUpResponse;
|
|
||||||
import com.ticketing.server.user.application.response.TokenDto;
|
|
||||||
import com.ticketing.server.user.application.response.UserChangePasswordResponse;
|
|
||||||
import com.ticketing.server.user.application.response.UserDeleteResponse;
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.service.UserServiceImpl;
|
|
||||||
import com.ticketing.server.user.service.interfaces.AuthenticationService;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.access.annotation.Secured;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@RequestMapping("/api/user")
|
|
||||||
@Slf4j
|
|
||||||
|
|
||||||
public class UserController {
|
|
||||||
|
|
||||||
private final UserServiceImpl userService;
|
|
||||||
private final AuthenticationService authenticationService;
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
|
||||||
private final JwtProperties jwtProperties;
|
|
||||||
|
|
||||||
@PostMapping
|
|
||||||
public ResponseEntity<SignUpResponse> register(@RequestBody @Valid SignUpRequest request) {
|
|
||||||
User user = userService.register(request.toSignUpDto(passwordEncoder));
|
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(SignUpResponse.from(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeleteMapping
|
|
||||||
@Secured("ROLE_GUEST")
|
|
||||||
public ResponseEntity<UserDeleteResponse> deleteUser(@RequestBody @Valid UserDeleteRequest request) {
|
|
||||||
User user = userService.delete(request.toDeleteUserDto(passwordEncoder));
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(UserDeleteResponse.from(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PutMapping("/password")
|
|
||||||
@Secured("ROLE_GUEST")
|
|
||||||
public ResponseEntity<UserChangePasswordResponse> changePassword(@RequestBody @Valid UserModifyPasswordRequest request) {
|
|
||||||
if (request.oldEqualNew()) {
|
|
||||||
log.error("기존 패스워드와 동일한 패스워드로 변경할 수 없습니다.");
|
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
User user = userService.changePassword(request.toChangePasswordDto(passwordEncoder));
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(UserChangePasswordResponse.from(user));
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/login")
|
|
||||||
public ResponseEntity<TokenDto> login(@RequestBody LoginRequest loginRequest, HttpServletResponse response) {
|
|
||||||
TokenDto tokenDto = authenticationService.login(loginRequest.toAuthentication());
|
|
||||||
|
|
||||||
response.setHeader("Cache-Control", "no-store");
|
|
||||||
response.setHeader("Pragma", "no-store");
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(tokenDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/refresh")
|
|
||||||
public ResponseEntity<TokenDto> refreshToken(@RequestParam("refreshToken") String refreshToken, HttpServletResponse response) {
|
|
||||||
TokenDto tokenDto = authenticationService.reissueAccessToken(refreshToken);
|
|
||||||
|
|
||||||
response.setHeader(jwtProperties.getAccessHeader(), tokenDto.getAccessToken());
|
|
||||||
response.setHeader(jwtProperties.getRefreshHeader(), tokenDto.getRefreshToken());
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(tokenDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.request;
|
|
||||||
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class LoginRequest {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
public UsernamePasswordAuthenticationToken toAuthentication() {
|
|
||||||
return new UsernamePasswordAuthenticationToken(email, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.request;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import com.ticketing.server.user.service.dto.SignUpDTO;
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class SignUpRequest {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.name}")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
|
||||||
@Phone
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
public SignUpDTO toSignUpDto(PasswordEncoder passwordEncoder) {
|
|
||||||
return new SignUpDTO(name, email, getEncodePassword(passwordEncoder), phone);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getEncodePassword(PasswordEncoder passwordEncoder) {
|
|
||||||
return passwordEncoder.encode(password);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.request;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class UserDeleteRequest {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
public DeleteUserDTO toDeleteUserDto(PasswordEncoder passwordEncoder) {
|
|
||||||
return new DeleteUserDTO(email, password, passwordEncoder);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.request;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public class UserModifyPasswordRequest {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.oldpassword}")
|
|
||||||
private String oldPassword;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.newpassword}")
|
|
||||||
private String newPassword;
|
|
||||||
|
|
||||||
public ChangePasswordDTO toChangePasswordDto(PasswordEncoder passwordEncoder) {
|
|
||||||
return new ChangePasswordDTO(email, oldPassword, newPassword, passwordEncoder);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean oldEqualNew() {
|
|
||||||
return oldPassword.equals(newPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class SignUpResponse {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
public static SignUpResponse from(User user) {
|
|
||||||
return new SignUpResponse(user.getName(), user.getEmail());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.response;
|
|
||||||
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class TokenDto {
|
|
||||||
|
|
||||||
private final String accessToken;
|
|
||||||
private final String refreshToken;
|
|
||||||
private final String tokenType;
|
|
||||||
private final long expiresIn;
|
|
||||||
|
|
||||||
public static TokenDto of(String accessToken, String refreshToken, String tokenType, long expiresIn) {
|
|
||||||
return new TokenDto(accessToken, refreshToken, tokenType, expiresIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class UserChangePasswordResponse {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
public static UserChangePasswordResponse from(User user) {
|
|
||||||
return new UserChangePasswordResponse(user.getName(), user.getEmail());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package com.ticketing.server.user.application.response;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
|
||||||
public class UserDeleteResponse {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
public static UserDeleteResponse from(User user) {
|
|
||||||
return new UserDeleteResponse(user.getName(), user.getEmail());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package com.ticketing.server.user.domain;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.dto.repository.AbstractEntity;
|
|
||||||
import com.ticketing.server.global.exception.AlreadyDeletedException;
|
|
||||||
import com.ticketing.server.global.exception.PasswordMismatchException;
|
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
|
||||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
|
||||||
import com.ticketing.server.user.service.dto.PasswordMatches;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Getter
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class User extends AbstractEntity {
|
|
||||||
|
|
||||||
public User(String name, String email, String password, UserGrade grade, String phone) {
|
|
||||||
this.name = name;
|
|
||||||
this.email = email;
|
|
||||||
this.password = password;
|
|
||||||
this.grade = grade;
|
|
||||||
this.phone = phone;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Column(name = "name")
|
|
||||||
@NotEmpty(message = "{validation.not.empty.name}")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@Column(name = "email")
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@Column(name = "password")
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@Column(name = "grade")
|
|
||||||
@NotNull(message = "{validation.not.empty.grade}")
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
|
||||||
private UserGrade grade = UserGrade.GUEST;
|
|
||||||
|
|
||||||
@Column(name = "phone")
|
|
||||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
|
||||||
@Phone
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
private boolean isDeleted = false;
|
|
||||||
|
|
||||||
private LocalDateTime deletedAt;
|
|
||||||
|
|
||||||
public User delete(DeleteUserDTO deleteUser) {
|
|
||||||
if (isDeleted) {
|
|
||||||
throw new AlreadyDeletedException("이미 탈퇴된 회원 입니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
checkPassword(deleteUser);
|
|
||||||
|
|
||||||
isDeleted = true;
|
|
||||||
deletedAt = LocalDateTime.now();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User changePassword(ChangePasswordDTO changePassword) {
|
|
||||||
checkPassword(changePassword);
|
|
||||||
|
|
||||||
this.password = changePassword.getEncodePassword();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkPassword(PasswordMatches passwordMatches) {
|
|
||||||
if (!passwordMatches.passwordMatches(password)) {
|
|
||||||
throw new PasswordMismatchException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package com.ticketing.server.user.domain;
|
|
||||||
|
|
||||||
public enum UserGrade {
|
|
||||||
GUEST, STAFF
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.ticketing.server.user.domain.repository;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import java.util.Optional;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
|
||||||
|
|
||||||
Optional<User> findByEmail(String email);
|
|
||||||
|
|
||||||
Optional<User> findByEmailAndIsDeletedFalse(String email);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package com.ticketing.server.user.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.token.TokenNotFindException;
|
|
||||||
import com.ticketing.server.global.exception.token.TokenTypeException;
|
|
||||||
import com.ticketing.server.global.exception.token.UnavailableRefreshTokenException;
|
|
||||||
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.application.response.TokenDto;
|
|
||||||
import com.ticketing.server.user.service.interfaces.AuthenticationService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class AuthenticationServiceImpl implements AuthenticationService {
|
|
||||||
|
|
||||||
private final RefreshRedisRepository refreshRedisRepository;
|
|
||||||
|
|
||||||
private final JwtProvider jwtProvider;
|
|
||||||
private final JwtProperties jwtProperties;
|
|
||||||
private final AuthenticationManagerBuilder authenticationManagerBuilder;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public TokenDto login(UsernamePasswordAuthenticationToken authenticationToken) {
|
|
||||||
// 회원인증
|
|
||||||
Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
|
|
||||||
|
|
||||||
String email = authenticationToken.getName();
|
|
||||||
|
|
||||||
// 토큰 발급
|
|
||||||
TokenDto tokenDto = jwtProvider.generateTokenDto(authentication);
|
|
||||||
|
|
||||||
// refresh 토큰이 있으면 수정, 없으면 생성
|
|
||||||
refreshRedisRepository.findByEmail(email)
|
|
||||||
.ifPresentOrElse(
|
|
||||||
tokenEntity -> tokenEntity.changeToken(tokenDto.getRefreshToken()),
|
|
||||||
() -> refreshRedisRepository.save(new RefreshToken(email, tokenDto.getRefreshToken()))
|
|
||||||
);
|
|
||||||
|
|
||||||
return tokenDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public TokenDto reissueAccessToken(String bearerRefreshToken) {
|
|
||||||
String refreshToken = resolveToken(bearerRefreshToken);
|
|
||||||
|
|
||||||
// 토큰 검증
|
|
||||||
jwtProvider.validateToken(refreshToken);
|
|
||||||
|
|
||||||
Authentication authentication = jwtProvider.getAuthentication(refreshToken);
|
|
||||||
|
|
||||||
// Redis 에 토큰이 있는지 검증
|
|
||||||
RefreshToken findTokenEntity = refreshRedisRepository.findByEmail(authentication.getName())
|
|
||||||
.orElseThrow(TokenNotFindException::new);
|
|
||||||
|
|
||||||
// redis 토큰과 input 토큰이 일치한지 확인
|
|
||||||
if (!refreshToken.equals(findTokenEntity.getToken())) {
|
|
||||||
throw new UnavailableRefreshTokenException();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 토큰 발급
|
|
||||||
TokenDto tokenDto = jwtProvider.generateTokenDto(authentication);
|
|
||||||
|
|
||||||
// 토큰 최신화
|
|
||||||
findTokenEntity.changeToken(tokenDto.getRefreshToken());
|
|
||||||
refreshRedisRepository.save(findTokenEntity);
|
|
||||||
|
|
||||||
return tokenDto;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String resolveToken(String bearerToken) {
|
|
||||||
if (StringUtils.hasText(bearerToken) && jwtProperties.hasTokenStartsWith(bearerToken)) {
|
|
||||||
return bearerToken.substring(7);
|
|
||||||
}
|
|
||||||
throw new TokenTypeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.ticketing.server.user.service;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.exception.EmailNotFoundException;
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.domain.repository.UserRepository;
|
|
||||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
|
||||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
|
||||||
import com.ticketing.server.user.service.dto.SignUpDTO;
|
|
||||||
import com.ticketing.server.user.service.interfaces.UserService;
|
|
||||||
import java.util.Optional;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
@Validated
|
|
||||||
@Slf4j
|
|
||||||
public class UserServiceImpl implements UserService {
|
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public User register(@Valid SignUpDTO signUpDto) {
|
|
||||||
Optional<User> user = userRepository.findByEmail(signUpDto.getEmail());
|
|
||||||
if (user.isPresent()) {
|
|
||||||
log.error("이미 존재하는 이메일이기 때문에 신규 회원가입을 진행할 수 없습니다. :: {}", signUpDto);
|
|
||||||
throw new IllegalArgumentException("이미 존재하는 이메일이기 때문에 신규 회원가입을 진행할 수 없습니다.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return userRepository.save(signUpDto.toUser());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public User delete(@Valid DeleteUserDTO deleteUserDto) {
|
|
||||||
User user = userRepository.findByEmail(deleteUserDto.getEmail())
|
|
||||||
.orElseThrow(() -> {
|
|
||||||
log.error("존재하지 않는 이메일 입니다. :: {}", deleteUserDto.getEmail());
|
|
||||||
throw new EmailNotFoundException();
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return user.delete(deleteUserDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional
|
|
||||||
public User changePassword(@Valid ChangePasswordDTO changePasswordDto) {
|
|
||||||
User user = findNotDeletedUserByEmail(changePasswordDto.getEmail());
|
|
||||||
return user.changePassword(changePasswordDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
private User findNotDeletedUserByEmail(String email) {
|
|
||||||
return userRepository.findByEmailAndIsDeletedFalse(email)
|
|
||||||
.orElseThrow(() -> {
|
|
||||||
log.error("존재하지 않는 이메일 입니다. :: {}", email);
|
|
||||||
throw new EmailNotFoundException();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.dto;
|
|
||||||
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
public class ChangePasswordDTO implements PasswordMatches {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.oldpassword}")
|
|
||||||
private String oldPassword;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.newpassword}")
|
|
||||||
private String newPassword;
|
|
||||||
|
|
||||||
private PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
public ChangePasswordDTO(String email, String oldPassword, String newPassword, PasswordEncoder passwordEncoder) {
|
|
||||||
this.email = email;
|
|
||||||
this.oldPassword = oldPassword;
|
|
||||||
this.newPassword = newPassword;
|
|
||||||
this.passwordEncoder = passwordEncoder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean passwordMatches(String password) {
|
|
||||||
return passwordEncoder.matches(oldPassword, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEncodePassword() {
|
|
||||||
return passwordEncoder.encode(newPassword);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ChangePassword{" +
|
|
||||||
"email='" + email + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.dto;
|
|
||||||
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
public class DeleteUserDTO implements PasswordMatches {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String inputPassword;
|
|
||||||
|
|
||||||
private PasswordEncoder passwordEncoder;
|
|
||||||
|
|
||||||
public DeleteUserDTO(String email, String inputPassword, PasswordEncoder passwordEncoder) {
|
|
||||||
this.email = email;
|
|
||||||
this.inputPassword = inputPassword;
|
|
||||||
this.passwordEncoder = passwordEncoder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean passwordMatches(String password) {
|
|
||||||
return passwordEncoder.matches(this.inputPassword, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "DeleteUser{" +
|
|
||||||
"email='" + email + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.dto;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface PasswordMatches {
|
|
||||||
|
|
||||||
boolean passwordMatches(String password);
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.dto;
|
|
||||||
|
|
||||||
import com.ticketing.server.global.validator.constraints.Phone;
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.domain.UserGrade;
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class SignUpDTO {
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.name}")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.email}")
|
|
||||||
@Email(message = "{validation.email}")
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.password}")
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@NotEmpty(message = "{validation.not.empty.phone}")
|
|
||||||
@Phone
|
|
||||||
private String phone;
|
|
||||||
|
|
||||||
public SignUpDTO(String name, String email, String password, String phone) {
|
|
||||||
this.name = name;
|
|
||||||
this.email = email;
|
|
||||||
this.password = password;
|
|
||||||
this.phone = phone;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User toUser() {
|
|
||||||
return new User(this.name, this.email, password, UserGrade.GUEST, this.phone);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SignUp{" +
|
|
||||||
"name='" + name + '\'' +
|
|
||||||
", email='" + email + '\'' +
|
|
||||||
", phone='" + phone + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.interfaces;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.application.response.TokenDto;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
|
|
||||||
public interface AuthenticationService {
|
|
||||||
|
|
||||||
TokenDto login(UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken);
|
|
||||||
|
|
||||||
TokenDto reissueAccessToken(String bearerRefreshToken);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.ticketing.server.user.service.interfaces;
|
|
||||||
|
|
||||||
import com.ticketing.server.user.domain.User;
|
|
||||||
import com.ticketing.server.user.service.dto.ChangePasswordDTO;
|
|
||||||
import com.ticketing.server.user.service.dto.DeleteUserDTO;
|
|
||||||
import com.ticketing.server.user.service.dto.SignUpDTO;
|
|
||||||
import javax.validation.Valid;
|
|
||||||
|
|
||||||
public interface UserService {
|
|
||||||
|
|
||||||
User register(@Valid SignUpDTO signUpDto);
|
|
||||||
|
|
||||||
User delete(@Valid DeleteUserDTO deleteUserDto);
|
|
||||||
|
|
||||||
User changePassword(@Valid ChangePasswordDTO changePasswordDto);
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,9 +4,6 @@ server:
|
|||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
active: local
|
active: local
|
||||||
redis:
|
|
||||||
host: localhost
|
|
||||||
port: 6379
|
|
||||||
|
|
||||||
jpa:
|
jpa:
|
||||||
hibernate:
|
hibernate:
|
||||||
@@ -17,15 +14,18 @@ spring:
|
|||||||
connection-timeout: 30000 # default 30s
|
connection-timeout: 30000 # default 30s
|
||||||
maximum-pool-size: 10 # default 10
|
maximum-pool-size: 10 # default 10
|
||||||
max-lifetime: 1800000 # default 30 minutes
|
max-lifetime: 1800000 # default 30 minutes
|
||||||
|
data-source-properties:
|
||||||
|
cachePrepStmts: true
|
||||||
|
prepStmtCacheSize: 250
|
||||||
|
prepStmtCacheSqlLimit: 2048
|
||||||
|
useServerPrepStmts: true
|
||||||
|
useLocalSessionState: true
|
||||||
|
rewriteBatchedStatements: true
|
||||||
|
cacheResultSetMetadata: true
|
||||||
|
cacheServerConfiguration: true
|
||||||
|
elideSetAutoCommits: true
|
||||||
|
maintainTimeStats: false
|
||||||
|
|
||||||
jasypt:
|
jasypt:
|
||||||
encryptor:
|
encryptor:
|
||||||
bean: jasyptStringEncryptor
|
bean: jasyptStringEncryptor
|
||||||
|
|
||||||
jwt:
|
|
||||||
access-header: ACCESS_TOKEN
|
|
||||||
refresh-header: REFRESH_TOKEN
|
|
||||||
prefix: Bearer
|
|
||||||
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK
|
|
||||||
access-token-validity-in-seconds: 60 # 1분
|
|
||||||
refresh-token-validity-in-seconds: 259200 # 3일
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.oldpassword="\uD604\uC7AC \uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.newpassword="\uBCC0\uACBD\uD560 \uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
validation.not.empty.name="name is required."
|
|
||||||
validation.not.empty.email="email is required."
|
|
||||||
validation.not.empty.password="password is required."
|
|
||||||
validation.not.empty.oldpassword="Old Password is required."
|
|
||||||
validation.not.empty.newpassword="New Password is required."
|
|
||||||
validation.not.empty.grade="user grade is required."
|
|
||||||
validation.not.empty.phone="phone is required."
|
|
||||||
validation.email="email is not valid."
|
|
||||||
validation.phone="phone is not valid."
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
validation.not.empty.name="\uC774\uB984\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.email="\uC774\uBA54\uC77C\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.password="\uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.oldpassword="\uD604\uC7AC \uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.newpassword="\uBCC0\uACBD\uD560 \uD328\uC2A4\uC6CC\uB4DC\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.grade="\uC0AC\uC6A9\uC790 \uB4F1\uAE09\uC740 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.not.empty.phone="\uD734\uB300\uBC88\uD638\uB294 \uD544\uC218 \uC785\uB2C8\uB2E4."
|
|
||||||
validation.email="\uC774\uBA54\uC77C\uC774 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
validation.phone="\uD734\uB300\uBC88\uD638\uAC00 \uC62C\uBC14\uB974\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4."
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<Configuration status="INFO" monitorInterval="30">
|
|
||||||
|
|
||||||
<Properties>
|
|
||||||
<Property name="LOG_PATH">./logs/log</Property>
|
|
||||||
<Property name="LOG_PATTERN">%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Property>
|
|
||||||
</Properties>
|
|
||||||
|
|
||||||
<Appenders>
|
|
||||||
<Console name="ConsoleLog" target="SYSTEM_OUT">
|
|
||||||
<PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8"/>
|
|
||||||
</Console>
|
|
||||||
|
|
||||||
<RollingFile name="FileLog"
|
|
||||||
fileName="${LOG_PATH}.log"
|
|
||||||
filePattern="${LOG_PATH}-%d{yyyy-MM-dd}-%i.log">
|
|
||||||
<PatternLayout pattern="${LOG_PATTERN}" charset="UTF-8" />
|
|
||||||
|
|
||||||
<Policies>
|
|
||||||
<SizeBasedTriggeringPolicy size="15MB" />
|
|
||||||
<TimeBasedTriggeringPolicy modulate="true" interval="1" />
|
|
||||||
</Policies>
|
|
||||||
|
|
||||||
<DefaultRolloverStrategy>
|
|
||||||
<Delete basePath="${LOG_PATH}" maxDepth="1">
|
|
||||||
<IfLastModified age="30d"/>
|
|
||||||
</Delete>
|
|
||||||
</DefaultRolloverStrategy>
|
|
||||||
</RollingFile>
|
|
||||||
</Appenders>
|
|
||||||
|
|
||||||
<Loggers>
|
|
||||||
<Root level="info">
|
|
||||||
<AppenderRef ref="ConsoleLog" />
|
|
||||||
<AppenderRef ref="FileLog" />
|
|
||||||
</Root>
|
|
||||||
</Loggers>
|
|
||||||
</Configuration>
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
package com.ticketing.server.global.health;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
|
||||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
|
||||||
class L7checkControllerTest {
|
|
||||||
|
|
||||||
private static final String L7CHECK = "/l7check";
|
|
||||||
private static final String HEALTH = "/actuator/health";
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
TestRestTemplate restTemplate;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void downAndUp() throws InterruptedException {
|
|
||||||
// before
|
|
||||||
expectUrlStatus(L7CHECK, HttpStatus.OK);
|
|
||||||
expectUrlStatus(HEALTH, HttpStatus.OK);
|
|
||||||
|
|
||||||
// down
|
|
||||||
restTemplate.delete(L7CHECK);
|
|
||||||
|
|
||||||
// then down
|
|
||||||
TimeUnit.MILLISECONDS.sleep(1000);
|
|
||||||
expectUrlStatus(L7CHECK, HttpStatus.SERVICE_UNAVAILABLE);
|
|
||||||
expectUrlStatus(HEALTH, HttpStatus.SERVICE_UNAVAILABLE);
|
|
||||||
|
|
||||||
// up
|
|
||||||
restTemplate.postForEntity(L7CHECK, null, Object.class);
|
|
||||||
|
|
||||||
// then up
|
|
||||||
TimeUnit.MILLISECONDS.sleep(1000);
|
|
||||||
expectUrlStatus(L7CHECK, HttpStatus.OK);
|
|
||||||
expectUrlStatus(HEALTH, HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void expectUrlStatus(String url, HttpStatus status) {
|
|
||||||
ResponseEntity<Object> res = restTemplate.getForEntity(url, Object.class);
|
|
||||||
assertThat(res.getStatusCode()).isEqualTo(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user