Compare commits

...

5 Commits

Author SHA1 Message Date
dongHyo
99715d0d14 refactor: user delete test code refactoring 2022-06-18 22:32:55 +09:00
dongHyo
ffa6b3f623 refactor: findByEmail 중복코드 제거 2022-06-18 22:29:00 +09:00
dongHyo
9fa7446487 refactor: 재정렬 2022-06-18 22:21:57 +09:00
dongHyo
33c485b691 refactor: access token header key naming change 2022-06-18 22:20:44 +09:00
dongHyo
88fe7ca6c5 feat: 토큰 email 상세 정보 조회 2022-06-18 22:19:14 +09:00
9 changed files with 85 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
plugins {
java
id("org.springframework.boot") version "2.6.7"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
java
id("org.springframework.boot") version "2.6.7"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
}
group = "com.ticketing"
@@ -9,18 +9,18 @@ version = "0.0.1-SNAPSHOT"
val javaVersion = JavaVersion.VERSION_11
java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
configurations {
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
compileOnly {
extendsFrom(configurations.annotationProcessor.get())
}
}
repositories {
mavenCentral()
mavenCentral()
}
@@ -33,36 +33,36 @@ dependencies {
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-boot-starter:3.0.0")
implementation("io.springfox:springfox-boot-starter:3.0.0")
implementation("io.springfox:springfox-swagger-ui:3.0.0")
implementation("com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.4")
implementation("com.lmax:disruptor:3.4.2")
implementation("io.jsonwebtoken:jjwt-api:0.11.2")
implementation("com.googlecode.json-simple:json-simple:1.1.1")
implementation("com.googlecode.json-simple:json-simple:1.1.1")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
modules {
module("org.springframework.boot:spring-boot-starter-logging") {
replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
}
}
modules {
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")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
compileOnly("org.projectlombok:lombok")
runtimeOnly("mysql:mysql-connector-java")
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")
compileOnly("org.projectlombok:lombok")
runtimeOnly("mysql:mysql-connector-java")
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")
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> {
useJUnitPlatform()
useJUnitPlatform()
}

View File

@@ -9,6 +9,7 @@ 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.application.response.UserDetailResponse;
import com.ticketing.server.user.domain.User;
import com.ticketing.server.user.service.UserServiceImpl;
import com.ticketing.server.user.service.interfaces.AuthenticationService;
@@ -19,8 +20,11 @@ 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.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.password.PasswordEncoder;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -45,6 +49,13 @@ public class UserController {
return ResponseEntity.status(HttpStatus.CREATED).body(SignUpResponse.from(user));
}
@GetMapping("/info")
@Secured("ROLE_GUEST")
public ResponseEntity<UserDetailResponse> myInfo(@AuthenticationPrincipal UserDetails userRequest) {
User user = userService.findByEmail(userRequest.getUsername());
return ResponseEntity.status(HttpStatus.OK).body(UserDetailResponse.from(user));
}
@DeleteMapping
@Secured("ROLE_GUEST")
public ResponseEntity<UserDeleteResponse> deleteUser(@RequestBody @Valid UserDeleteRequest request) {

View File

@@ -0,0 +1,21 @@
package com.ticketing.server.user.application.response;
import com.ticketing.server.user.domain.User;
import com.ticketing.server.user.domain.UserGrade;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class UserDetailResponse {
private String name;
private String email;
private UserGrade grade;
private String phone;
public static UserDetailResponse from(User user) {
return new UserDetailResponse(user.getName(), user.getEmail(), user.getGrade(), user.getPhone());
}
}

View File

@@ -39,13 +39,7 @@ public class UserServiceImpl implements UserService {
@Override
@Transactional
public User delete(@Valid DeleteUserDTO deleteUserDto) {
User user = userRepository.findByEmail(deleteUserDto.getEmail())
.orElseThrow(() -> {
log.error("존재하지 않는 이메일 입니다. :: {}", deleteUserDto.getEmail());
throw new EmailNotFoundException();
}
);
User user = findByEmail(deleteUserDto.getEmail());
return user.delete(deleteUserDto);
}
@@ -56,6 +50,16 @@ public class UserServiceImpl implements UserService {
return user.changePassword(changePasswordDto);
}
@Override
public User findByEmail(String email) {
return userRepository.findByEmail(email)
.orElseThrow(() -> {
log.error("존재하지 않는 이메일 입니다. :: {}", email);
throw new EmailNotFoundException();
}
);
}
private User findNotDeletedUserByEmail(String email) {
return userRepository.findByEmailAndIsDeletedFalse(email)
.orElseThrow(() -> {

View File

@@ -14,4 +14,5 @@ public interface UserService {
User changePassword(@Valid ChangePasswordDTO changePasswordDto);
User findByEmail(String email);
}

View File

@@ -27,7 +27,7 @@ jasypt:
bean: jasyptStringEncryptor
jwt:
access-header: ACCESS_TOKEN
access-header: Authorization
refresh-header: REFRESH_TOKEN
prefix: Bearer
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK

View File

@@ -27,7 +27,7 @@ class JwtPropertiesTest {
// when
// then
assertAll(
() -> assertThat(jwtProperties.getAccessHeader()).isEqualTo("ACCESS_TOKEN")
() -> assertThat(jwtProperties.getAccessHeader()).isEqualTo("Authorization")
, () -> assertThat(jwtProperties.getRefreshHeader()).isEqualTo("REFRESH_TOKEN")
, () -> assertThat(jwtProperties.getPrefix()).isEqualTo("Bearer")
, () -> assertThat(jwtProperties.getAccessTokenValidityInSeconds()).isEqualTo(60)

View File

@@ -2,6 +2,7 @@ package com.ticketing.server.user.service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@@ -92,7 +93,10 @@ class UserServiceImplTest {
User user = userService.delete(deleteUserDto);
// then
assertThat(user).isNotNull();
assertAll(
() -> assertThat(user.isDeleted()).isTrue(),
() -> assertThat(user.getDeletedAt()).isNotNull()
);
}
@Test

View File

@@ -16,12 +16,16 @@ spring:
hibernate:
ddl-auto: create
mvc:
pathmatch:
matching-strategy: ant_path_matcher
jasypt:
encryptor:
bean: jasyptStringEncryptor
jwt:
access-header: ACCESS_TOKEN
access-header: Authorization
refresh-header: REFRESH_TOKEN
prefix: Bearer
secret-key: Zi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXktZi1sYWItdGlja2V0aW5nLXByb2plY3Qtc3ByaW5nLWJvb3Qtc2VjdXJpdHktand0LXNlY3JldC1rZXkK