From eec0925c7017f3e6b3d7ddc433e5bda0f1a708ff Mon Sep 17 00:00:00 2001 From: 2097 Date: Tue, 27 Aug 2024 03:24:46 +0900 Subject: [PATCH] feat:dddd --- .../controller/AuthController.java | 49 -------- .../dto/req/ReProvideTokenReq.java | 4 - .../auth/presentation/dto/req/SignInReq.java | 7 -- .../auth/presentation/dto/req/SignUpReq.java | 16 --- .../presentation/dto/req/UserSignUpReq.java | 12 -- .../auth/presentation/dto/res/TokenRes.java | 10 -- .../domain/auth/service/AuthService.java | 113 ------------------ .../sodam/domain/user/entity/BuyerEntity.java | 35 ------ .../domain/user/entity/SellerEntity.java | 50 -------- .../sodam/domain/user/entity/UserEntity.java | 44 ------- .../sodam/domain/user/enums/UserCategory.java | 5 - .../sodam/domain/user/enums/UserState.java | 12 -- .../controller/UserController.java | 16 --- .../user/repository/BuyerRepository.java | 10 -- .../user/repository/SellerRepository.java | 10 -- .../user/repository/UserRepository.java | 14 --- .../common/dto/res/JsonWebTokenResponse.java | 15 --- .../global/common/entity/BaseTimeEntity.java | 28 ----- .../global/config/security/BCryptConfig.java | 13 -- .../config/security/SecurityConfig.java | 79 ------------ .../global/config/storage/StorageConfig.java | 5 - .../global/config/swagger/swaggerConfig.java | 34 ------ .../sodam/global/error/ErrorResponse.java | 38 ------ .../global/error/GlobalExceptionFilter.java | 44 ------- .../global/error/GlobalExceptionHandler.java | 47 -------- .../error/custom/auth/EncryptException.java | 12 -- .../custom/auth/ExpiredTokenException.java | 13 -- .../custom/auth/InvalidTokenException.java | 14 --- .../custom/auth/RefreshTokenException.java | 14 --- .../auth/UnableToSendEmailException.java | 12 -- .../auth/WithdrawalMemberException.java | 14 --- .../custom/auth/WrongPasswordException.java | 15 --- .../custom/auth/WrongTokenTypeException.java | 12 -- .../error/custom/board/BoardNotFound.java | 12 -- .../error/custom/contest/ContestNotFound.java | 12 -- .../custom/email/CodeIsWrongException.java | 12 -- .../email/EmailAlreadyExistsException.java | 12 -- .../email/UnableToSendEmailException.java | 12 -- .../error/custom/enroll/ENROLL_NOT_FOUND.java | 13 -- .../member/IdAlreadyExistException.java | 12 -- .../custom/member/InvalidRoleException.java | 12 -- .../member/MemberNotCoincideException.java | 10 -- .../member/MemberNotExistException.java | 12 -- .../member/MemberNotFoundException.java | 12 -- .../error/custom/member/NeedAuthCode.java | 12 -- .../member/PermissionDeniedException.java | 13 -- .../error/exception/BusinessException.java | 10 -- .../global/error/exception/StatusEnum.java | 64 ---------- .../global/infra/jwt/JwtExceptionFilter.java | 57 --------- .../sodam/global/infra/jwt/JwtFilter.java | 43 ------- .../sodam/global/infra/jwt/JwtHelper.java | 44 ------- .../sodam/global/infra/jwt/JwtProvider.java | 53 -------- .../sodam/global/infra/jwt/JwtType.java | 5 - .../sodam/global/infra/jwt/ParseToken.java | 42 ------- .../security/CustomAccessDeniedHandler.java | 19 --- .../infra/security/CustomMemberDetails.java | 52 -------- .../infra/security/GetCurrentMember.java | 16 --- .../infra/security/MemberDetailsService.java | 21 ---- .../global/properties/JwtProperties.java | 16 --- .../sodam/global/response/Response.java | 9 -- .../sodam/global/response/ResponseData.java | 13 -- 61 files changed, 1436 deletions(-) delete mode 100644 src/main/java/hackers/ground/sodam/domain/auth/presentation/controller/AuthController.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/ReProvideTokenReq.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignInReq.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignUpReq.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/UserSignUpReq.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/res/TokenRes.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/auth/service/AuthService.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/entity/BuyerEntity.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/entity/SellerEntity.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/entity/UserEntity.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/enums/UserCategory.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/enums/UserState.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/presentation/controller/UserController.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/repository/BuyerRepository.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/repository/SellerRepository.java delete mode 100644 src/main/java/hackers/ground/sodam/domain/user/repository/UserRepository.java delete mode 100644 src/main/java/hackers/ground/sodam/global/common/dto/res/JsonWebTokenResponse.java delete mode 100644 src/main/java/hackers/ground/sodam/global/common/entity/BaseTimeEntity.java delete mode 100644 src/main/java/hackers/ground/sodam/global/config/security/BCryptConfig.java delete mode 100644 src/main/java/hackers/ground/sodam/global/config/security/SecurityConfig.java delete mode 100644 src/main/java/hackers/ground/sodam/global/config/storage/StorageConfig.java delete mode 100644 src/main/java/hackers/ground/sodam/global/config/swagger/swaggerConfig.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/ErrorResponse.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/GlobalExceptionFilter.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/GlobalExceptionHandler.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/EncryptException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/ExpiredTokenException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/InvalidTokenException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/RefreshTokenException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/UnableToSendEmailException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/WithdrawalMemberException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongPasswordException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongTokenTypeException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/board/BoardNotFound.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/contest/ContestNotFound.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/email/CodeIsWrongException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/email/EmailAlreadyExistsException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/email/UnableToSendEmailException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/enroll/ENROLL_NOT_FOUND.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/member/IdAlreadyExistException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/member/InvalidRoleException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotCoincideException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotExistException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotFoundException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/member/NeedAuthCode.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/custom/member/PermissionDeniedException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/exception/BusinessException.java delete mode 100644 src/main/java/hackers/ground/sodam/global/error/exception/StatusEnum.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/jwt/JwtExceptionFilter.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/jwt/JwtFilter.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/jwt/JwtHelper.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/jwt/JwtProvider.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/jwt/JwtType.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/jwt/ParseToken.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/security/CustomAccessDeniedHandler.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/security/CustomMemberDetails.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/security/GetCurrentMember.java delete mode 100644 src/main/java/hackers/ground/sodam/global/infra/security/MemberDetailsService.java delete mode 100644 src/main/java/hackers/ground/sodam/global/properties/JwtProperties.java delete mode 100644 src/main/java/hackers/ground/sodam/global/response/Response.java delete mode 100644 src/main/java/hackers/ground/sodam/global/response/ResponseData.java diff --git a/src/main/java/hackers/ground/sodam/domain/auth/presentation/controller/AuthController.java b/src/main/java/hackers/ground/sodam/domain/auth/presentation/controller/AuthController.java deleted file mode 100644 index ba7cc90..0000000 --- a/src/main/java/hackers/ground/sodam/domain/auth/presentation/controller/AuthController.java +++ /dev/null @@ -1,49 +0,0 @@ -package hackers.ground.sodam.domain.auth.presentation.controller; - -import hackers.ground.sodam.domain.auth.presentation.dto.req.UserSignUpReq; -import hackers.ground.sodam.global.response.Response; -import hackers.ground.sodam.global.response.ResponseData; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import hackers.ground.sodam.domain.auth.presentation.dto.req.SignInReq; -import hackers.ground.sodam.domain.auth.presentation.dto.req.SignUpReq; -import hackers.ground.sodam.domain.auth.presentation.dto.res.TokenRes; -import hackers.ground.sodam.domain.auth.service.AuthService; - -@Tag(name = "Auth", description = "Auth Api") -@RestController -@RequestMapping(value = "/auth") -@RequiredArgsConstructor -public class AuthController { - private final AuthService authService; - - @Operation(description = "회원가입") - @PostMapping("/sign_up") - public Response signUp( - @RequestBody @Valid UserSignUpReq userSignUpReq - ){ - return authService.signUp(userSignUpReq); - } - - @Operation(description = "장사") - @PostMapping("/sign_up/seller") - public Response signUpSeller( - @RequestBody @Valid SignUpReq signUpReq - ){ - return authService.signUpSeller(signUpReq); - } - - @Operation(description = "로그인") - @PostMapping("/sign_in") - public ResponseData signIn( - @RequestBody @Valid SignInReq signInReq - ){ - return authService.signIn(signInReq); - } -} diff --git a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/ReProvideTokenReq.java b/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/ReProvideTokenReq.java deleted file mode 100644 index f22128c..0000000 --- a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/ReProvideTokenReq.java +++ /dev/null @@ -1,4 +0,0 @@ -package hackers.ground.sodam.domain.auth.presentation.dto.req; - -public record ReProvideTokenReq(String refreshToken) { -} diff --git a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignInReq.java b/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignInReq.java deleted file mode 100644 index d35487e..0000000 --- a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignInReq.java +++ /dev/null @@ -1,7 +0,0 @@ -package hackers.ground.sodam.domain.auth.presentation.dto.req; - -public record SignInReq( - String memberId, - String memberPassword -) { -} diff --git a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignUpReq.java b/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignUpReq.java deleted file mode 100644 index 0594c9a..0000000 --- a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/SignUpReq.java +++ /dev/null @@ -1,16 +0,0 @@ -package hackers.ground.sodam.domain.auth.presentation.dto.req; - -public record SignUpReq( - String memberId, - String memberName, - String memberPassword, - String memberEmail, - String openDate, - String sellerNum, - String phoneNum, - String farmName, - String farmAdress, - String account, - String num -) { -} diff --git a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/UserSignUpReq.java b/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/UserSignUpReq.java deleted file mode 100644 index 73e1cab..0000000 --- a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/req/UserSignUpReq.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.domain.auth.presentation.dto.req; - -public record UserSignUpReq( - String memberId, - String memberPassword, - String memberEmail, - String memberName, - String memberPhoneNum, - String memberAuthCode, - String memberAddress -) { -} diff --git a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/res/TokenRes.java b/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/res/TokenRes.java deleted file mode 100644 index 20bd0bf..0000000 --- a/src/main/java/hackers/ground/sodam/domain/auth/presentation/dto/res/TokenRes.java +++ /dev/null @@ -1,10 +0,0 @@ -package hackers.ground.sodam.domain.auth.presentation.dto.res; - -import lombok.Builder; - -@Builder -public record TokenRes( - String accessToken, - String refreshToken -) { -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/domain/auth/service/AuthService.java b/src/main/java/hackers/ground/sodam/domain/auth/service/AuthService.java deleted file mode 100644 index 40398a6..0000000 --- a/src/main/java/hackers/ground/sodam/domain/auth/service/AuthService.java +++ /dev/null @@ -1,113 +0,0 @@ -package hackers.ground.sodam.domain.auth.service; - -import hackers.ground.sodam.domain.auth.presentation.dto.req.UserSignUpReq; -import hackers.ground.sodam.domain.user.entity.BuyerEntity; -import hackers.ground.sodam.domain.user.entity.SellerEntity; -import hackers.ground.sodam.domain.user.repository.BuyerRepository; -import hackers.ground.sodam.domain.user.repository.SellerRepository; -import hackers.ground.sodam.global.error.custom.auth.WrongPasswordException; -import hackers.ground.sodam.global.error.custom.email.EmailAlreadyExistsException; -import hackers.ground.sodam.global.error.custom.member.IdAlreadyExistException; -import hackers.ground.sodam.global.error.custom.member.MemberNotFoundException; -import hackers.ground.sodam.global.infra.jwt.JwtProvider; -import hackers.ground.sodam.global.response.Response; -import hackers.ground.sodam.global.response.ResponseData; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import hackers.ground.sodam.domain.auth.presentation.dto.req.SignInReq; -import hackers.ground.sodam.domain.auth.presentation.dto.req.SignUpReq; -import hackers.ground.sodam.domain.auth.presentation.dto.res.TokenRes; -import hackers.ground.sodam.domain.user.entity.UserEntity; -import hackers.ground.sodam.domain.user.enums.UserCategory; -import hackers.ground.sodam.domain.user.enums.UserState; -import hackers.ground.sodam.domain.user.repository.UserRepository; - -@Component -@RequiredArgsConstructor -public class AuthService { - private final JwtProvider jwtProvider; - private final UserRepository userRepository; - private final SellerRepository sellerRepository; - private final BuyerRepository buyerRepository; - - @Transactional(rollbackFor = Exception.class) - public Response signUp(UserSignUpReq userSignUpReq) { - if (userRepository.existsByUserEmail(userSignUpReq.memberEmail())){ - throw EmailAlreadyExistsException.EXCEPTION; - } - - if (userRepository.existsByUserId(userSignUpReq.memberId())) - throw IdAlreadyExistException.EXCEPTION; - - UserEntity userEntity = userRepository.save(UserEntity - .builder() - .userId(userSignUpReq.memberId()) - .userName(userSignUpReq.memberName()) - .userEmail(userSignUpReq.memberEmail()) - .userPassword(new BCryptPasswordEncoder().encode(userSignUpReq.memberPassword())) - .userCategory(UserCategory.BUYER) - .userState(UserState.ACTIVE) - .build()); - - buyerRepository.save(BuyerEntity - .builder() - .userEntity(userEntity) - .phoneNum(userSignUpReq.memberPhoneNum()) - .address(userSignUpReq.memberAddress()) - .build()); - - return Response.of(HttpStatus.OK, "회원가입 성공"); - } - - @Transactional(rollbackFor = Exception.class) - public Response signUpSeller(SignUpReq signUpReq) { - if (userRepository.existsByUserEmail(signUpReq.memberEmail())){ - throw EmailAlreadyExistsException.EXCEPTION; - } - - if (userRepository.existsByUserId(signUpReq.memberId())) - throw IdAlreadyExistException.EXCEPTION; - - UserEntity userEntity = userRepository.save(UserEntity - .builder() - .userId(signUpReq.memberId()) - .userName(signUpReq.memberName()) - .userEmail(signUpReq.memberEmail()) - .userPassword(new BCryptPasswordEncoder().encode(signUpReq.memberPassword())) - .userCategory(UserCategory.SELLER) - .userState(UserState.ACTIVE) - .build()); - - sellerRepository.save(SellerEntity - .builder() - .userEntity(userEntity) - .openDate(signUpReq.openDate()) - .sellerNum(signUpReq.sellerNum()) - .phoneNum(signUpReq.phoneNum()) - .farmName(signUpReq.farmName()) - .farmAdress(signUpReq.farmAdress()) - .account(signUpReq.account()) - .num(signUpReq.num()) - .build()); - return Response.of(HttpStatus.OK, "회원가입 성공"); - } - - @Transactional(rollbackFor = Exception.class) - public ResponseData signIn(SignInReq signInReq){ - UserEntity user = userRepository.findByUserId(signInReq.memberId()); - - if(user == null || user.getUserState().equals(UserState.DELETED)) { - throw MemberNotFoundException.EXCEPTION; - } - - BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); - if (!encoder.matches(signInReq.memberPassword(), user.getUserPassword())) { - throw WrongPasswordException.EXCEPTION; - } - - return ResponseData.of(HttpStatus.OK, "로그인 성공", jwtProvider.generateToken(signInReq.memberId(), user.getUserState())); - } -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/entity/BuyerEntity.java b/src/main/java/hackers/ground/sodam/domain/user/entity/BuyerEntity.java deleted file mode 100644 index 6590689..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/entity/BuyerEntity.java +++ /dev/null @@ -1,35 +0,0 @@ -package hackers.ground.sodam.domain.user.entity; - -import hackers.ground.sodam.global.common.entity.BaseTimeEntity; -import jakarta.persistence.*; -import lombok.*; -import lombok.experimental.SuperBuilder; -import org.hibernate.annotations.DynamicUpdate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -@Entity -@Getter -@Setter -@SuperBuilder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@EntityListeners(AuditingEntityListener.class) -@Table(name = "tb_buyer") -@DynamicUpdate -@AllArgsConstructor -public class BuyerEntity extends BaseTimeEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @OneToOne(fetch = FetchType.LAZY, orphanRemoval = true) - @JoinColumn(name = "user_id") - private UserEntity userEntity; - - @Column(name = "user_phone_num") - private String phoneNum; - - @Column(name = "user_address") - private String address; - -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/entity/SellerEntity.java b/src/main/java/hackers/ground/sodam/domain/user/entity/SellerEntity.java deleted file mode 100644 index f64f4ba..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/entity/SellerEntity.java +++ /dev/null @@ -1,50 +0,0 @@ -package hackers.ground.sodam.domain.user.entity; - -import hackers.ground.sodam.global.common.entity.BaseTimeEntity; -import jakarta.persistence.*; -import lombok.*; -import lombok.experimental.SuperBuilder; -import org.hibernate.annotations.DynamicUpdate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.springframework.format.annotation.DateTimeFormat; - -@Entity -@Getter -@Setter -@SuperBuilder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@EntityListeners(AuditingEntityListener.class) -@Table(name = "tb_seller") -@DynamicUpdate -@AllArgsConstructor -public class SellerEntity extends BaseTimeEntity { - @Id - private Long id; - - @OneToOne(fetch = FetchType.LAZY, orphanRemoval = true) - @JoinColumn(name = "user_id") - private UserEntity userEntity; - - @Column(name = "seller_open_date") - @DateTimeFormat - private String openDate; - - @Column(name = "seller_seller_num") - private String sellerNum; - - @Column(name = "seller_phone_num") - private String phoneNum; - - @Column(name = "farm_name") - private String farmName; - - @Column(name = "farm_adress") - private String farmAdress; - - @Column(name = "account") - private String account; - - @Column(name = "num") - private String num; - -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/entity/UserEntity.java b/src/main/java/hackers/ground/sodam/domain/user/entity/UserEntity.java deleted file mode 100644 index 9818dc2..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/entity/UserEntity.java +++ /dev/null @@ -1,44 +0,0 @@ -package hackers.ground.sodam.domain.user.entity; - -import hackers.ground.sodam.global.common.entity.BaseTimeEntity; -import jakarta.persistence.*; -import lombok.*; -import lombok.experimental.SuperBuilder; -import org.hibernate.annotations.DynamicUpdate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import hackers.ground.sodam.domain.user.enums.UserCategory; -import hackers.ground.sodam.domain.user.enums.UserState; - -@Entity -@Getter -@Setter -@SuperBuilder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@EntityListeners(AuditingEntityListener.class) -@Table(name = "tb_user") -@DynamicUpdate -@AllArgsConstructor -public class UserEntity extends BaseTimeEntity { - - @Id - @Column(name = "user_id") - private String userId; - - @Column(name = "user_name") - private String userName; - - @Column(name = "user_email") - private String userEmail; - - @Column(name = "user_password") - private String userPassword; - - @Column(name = "user_category") - @Enumerated(EnumType.STRING) - private UserCategory userCategory; - - @Builder.Default - @Enumerated(EnumType.STRING) - private UserState userState = UserState.ACTIVE; - -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/enums/UserCategory.java b/src/main/java/hackers/ground/sodam/domain/user/enums/UserCategory.java deleted file mode 100644 index 74148cf..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/enums/UserCategory.java +++ /dev/null @@ -1,5 +0,0 @@ -package hackers.ground.sodam.domain.user.enums; - -public enum UserCategory { - SELLER, BUYER -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/enums/UserState.java b/src/main/java/hackers/ground/sodam/domain/user/enums/UserState.java deleted file mode 100644 index fd105ea..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/enums/UserState.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.domain.user.enums; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum UserState { - ACTIVE("ROLE_ACTIVE"), - DELETED("ROLE_DELETED"); - private final String key; -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/presentation/controller/UserController.java b/src/main/java/hackers/ground/sodam/domain/user/presentation/controller/UserController.java deleted file mode 100644 index 4b118b1..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/presentation/controller/UserController.java +++ /dev/null @@ -1,16 +0,0 @@ -package hackers.ground.sodam.domain.user.presentation.controller; - -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@Tag(name = "User", description = "User Api") -@RestController -@RequestMapping(value = "/user") -@RequiredArgsConstructor -public class UserController { - - - -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/repository/BuyerRepository.java b/src/main/java/hackers/ground/sodam/domain/user/repository/BuyerRepository.java deleted file mode 100644 index d0f237a..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/repository/BuyerRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package hackers.ground.sodam.domain.user.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; -import hackers.ground.sodam.domain.user.entity.BuyerEntity; - -@Repository -public interface BuyerRepository extends JpaRepository { - -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/repository/SellerRepository.java b/src/main/java/hackers/ground/sodam/domain/user/repository/SellerRepository.java deleted file mode 100644 index d932b12..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/repository/SellerRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package hackers.ground.sodam.domain.user.repository; - -import hackers.ground.sodam.domain.user.entity.SellerEntity; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface SellerRepository extends JpaRepository { - -} diff --git a/src/main/java/hackers/ground/sodam/domain/user/repository/UserRepository.java b/src/main/java/hackers/ground/sodam/domain/user/repository/UserRepository.java deleted file mode 100644 index cb606e6..0000000 --- a/src/main/java/hackers/ground/sodam/domain/user/repository/UserRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package hackers.ground.sodam.domain.user.repository; - -import hackers.ground.sodam.domain.user.entity.UserEntity; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface UserRepository extends JpaRepository { - - UserEntity findByUserId(String memberId); - boolean existsByUserEmail(String email); - boolean existsByUserId(String memberId); - -} diff --git a/src/main/java/hackers/ground/sodam/global/common/dto/res/JsonWebTokenResponse.java b/src/main/java/hackers/ground/sodam/global/common/dto/res/JsonWebTokenResponse.java deleted file mode 100644 index 8fb32f8..0000000 --- a/src/main/java/hackers/ground/sodam/global/common/dto/res/JsonWebTokenResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package hackers.ground.sodam.global.common.dto.res; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Builder; -import lombok.Getter; -import lombok.Setter; - -@Setter -@Getter -@Builder -@JsonInclude(JsonInclude.Include.NON_EMPTY) -public class JsonWebTokenResponse { - private String accessToken; - private String refreshToken; -} diff --git a/src/main/java/hackers/ground/sodam/global/common/entity/BaseTimeEntity.java b/src/main/java/hackers/ground/sodam/global/common/entity/BaseTimeEntity.java deleted file mode 100644 index 63474fb..0000000 --- a/src/main/java/hackers/ground/sodam/global/common/entity/BaseTimeEntity.java +++ /dev/null @@ -1,28 +0,0 @@ -package hackers.ground.sodam.global.common.entity; - -import jakarta.persistence.EntityListeners; -import jakarta.persistence.MappedSuperclass; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.experimental.SuperBuilder; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import java.time.LocalDateTime; - -@Getter -@SuperBuilder -@MappedSuperclass -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@EntityListeners(AuditingEntityListener.class) -public abstract class BaseTimeEntity { - - @CreatedDate - private LocalDateTime createdAt; - - @LastModifiedDate - private LocalDateTime modifiedAt; - -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/config/security/BCryptConfig.java b/src/main/java/hackers/ground/sodam/global/config/security/BCryptConfig.java deleted file mode 100644 index 9a3b34c..0000000 --- a/src/main/java/hackers/ground/sodam/global/config/security/BCryptConfig.java +++ /dev/null @@ -1,13 +0,0 @@ -package hackers.ground.sodam.global.config.security; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; - -@Configuration -public class BCryptConfig { - @Bean - public BCryptPasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/config/security/SecurityConfig.java b/src/main/java/hackers/ground/sodam/global/config/security/SecurityConfig.java deleted file mode 100644 index fb8a746..0000000 --- a/src/main/java/hackers/ground/sodam/global/config/security/SecurityConfig.java +++ /dev/null @@ -1,79 +0,0 @@ -package hackers.ground.sodam.global.config.security; - -import hackers.ground.sodam.global.error.ErrorResponse; -import hackers.ground.sodam.global.error.exception.StatusEnum; -import hackers.ground.sodam.global.infra.jwt.JwtExceptionFilter; -import hackers.ground.sodam.global.infra.jwt.JwtFilter; -import lombok.RequiredArgsConstructor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -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.configurers.AbstractHttpConfigurer; -import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.web.SecurityFilterChain; -import org.springframework.security.web.access.AccessDeniedHandler; -import org.springframework.security.web.authentication.HttpStatusEntryPoint; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.CorsConfigurationSource; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; - -@Configuration -@EnableWebSecurity -@RequiredArgsConstructor -public class SecurityConfig { - private final JwtFilter jwtFilter; - private final JwtExceptionFilter jwtExceptionFilter; - private final AccessDeniedHandler accessDeniedHandler; - - @Bean - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http - .httpBasic().disable() - .cors() - .and() - .csrf().disable() - .cors(cors -> cors.configurationSource(corsConfigurationSource())) - .csrf(AbstractHttpConfigurer::disable) - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) - .and() - .addFilterAfter(jwtFilter, UsernamePasswordAuthenticationFilter.class) - .addFilterBefore(jwtExceptionFilter, JwtFilter.class) - .authorizeHttpRequests() - .requestMatchers("/v3/api-docs/**", "/swagger-ui/**").permitAll() - .requestMatchers("/auth/**").permitAll() - .requestMatchers("/email/**").permitAll() - .requestMatchers("/re_provide/**").permitAll() - .requestMatchers("/file/**").hasRole("ACTIVE") - .requestMatchers("/member/**").hasRole("ACTIVE") - .requestMatchers("/contest/**").hasRole("ACTIVE") - .requestMatchers("/like/**").hasRole("ACTIVE") - .requestMatchers("/profile/**").hasRole("ACTIVE") - .anyRequest().authenticated() - .and() - .formLogin().disable() - .exceptionHandling() - .accessDeniedHandler((req, res, e) -> jwtExceptionFilter.responseToClient(res, ErrorResponse.of(StatusEnum.INVALID_ROLE, "권한이 없습니다"))) - .authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.FORBIDDEN)) - .accessDeniedHandler(accessDeniedHandler); - - return http.build(); - } - - @Bean - public CorsConfigurationSource corsConfigurationSource() { - CorsConfiguration configuration = new CorsConfiguration(); - configuration.addAllowedOriginPattern("*"); - configuration.addAllowedHeader("*"); - configuration.addAllowedMethod("*"); - configuration.setAllowCredentials(true); - - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", configuration); - - return source; - } -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/config/storage/StorageConfig.java b/src/main/java/hackers/ground/sodam/global/config/storage/StorageConfig.java deleted file mode 100644 index dc3b394..0000000 --- a/src/main/java/hackers/ground/sodam/global/config/storage/StorageConfig.java +++ /dev/null @@ -1,5 +0,0 @@ -package hackers.ground.sodam.global.config.storage; - -public class StorageConfig { - -} diff --git a/src/main/java/hackers/ground/sodam/global/config/swagger/swaggerConfig.java b/src/main/java/hackers/ground/sodam/global/config/swagger/swaggerConfig.java deleted file mode 100644 index 1a028d7..0000000 --- a/src/main/java/hackers/ground/sodam/global/config/swagger/swaggerConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -package hackers.ground.sodam.global.config.swagger; - -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.info.Info; -import io.swagger.v3.oas.models.security.SecurityRequirement; -import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class swaggerConfig { - @Bean - public OpenAPI openAPI() { - SecurityScheme securityScheme = new SecurityScheme() - .name("Authorization") - .type(SecurityScheme.Type.HTTP) - .in(SecurityScheme.In.HEADER) - .bearerFormat("JWT") - .scheme("bearer"); - OpenAPI openAPI = new OpenAPI().addSecurityItem(new SecurityRequirement().addList("JWT Token")) - .components(new Components()) - .info(apiInfo()); - openAPI.getComponents().addSecuritySchemes("JWT Token", securityScheme); - return openAPI; - } - - private Info apiInfo() { - return new Info() - .title("hackers/ground/sodam") - .description("Java API") - .version("0.0.1"); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/ErrorResponse.java b/src/main/java/hackers/ground/sodam/global/error/ErrorResponse.java deleted file mode 100644 index a088f9e..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/ErrorResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -package hackers.ground.sodam.global.error; - -import hackers.ground.sodam.global.error.exception.StatusEnum; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.time.LocalDateTime; - -@Builder -@Getter -@AllArgsConstructor -@NoArgsConstructor -public class ErrorResponse { - private String message; - private Integer status; - private LocalDateTime timestamp; - private String description; - - public static ErrorResponse of(StatusEnum errorCode, String description) { - return ErrorResponse.builder() - .message(errorCode.getMessage()) - .status(errorCode.getStatusCode()) - .timestamp(LocalDateTime.now()) - .description(description) - .build(); - } - - public static ErrorResponse of(int statusCode, String description) { - return ErrorResponse.builder() - .message(description) - .status(statusCode) - .timestamp(LocalDateTime.now()) - .description(description) - .build(); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/GlobalExceptionFilter.java b/src/main/java/hackers/ground/sodam/global/error/GlobalExceptionFilter.java deleted file mode 100644 index c6bada4..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/GlobalExceptionFilter.java +++ /dev/null @@ -1,44 +0,0 @@ -package hackers.ground.sodam.global.error; - -import com.fasterxml.jackson.databind.ObjectMapper; -import hackers.ground.sodam.global.error.exception.StatusEnum; -import jakarta.servlet.FilterChain; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.http.MediaType; -import org.springframework.web.filter.OncePerRequestFilter; -import hackers.ground.sodam.global.error.exception.BusinessException; - -import java.io.IOException; - -@RequiredArgsConstructor -public class GlobalExceptionFilter extends OncePerRequestFilter { - - private final ObjectMapper objectMapper; - - @Override - protected void doFilterInternal( - HttpServletRequest request, - HttpServletResponse response, - FilterChain filterChain - )throws IOException { - - try { - filterChain.doFilter(request,response); - } catch (BusinessException e){ - StatusEnum errorCode = e.getErrorCode(); - writerErrorResponse(response, ErrorResponse.of(errorCode, errorCode.getMessage())); - } catch (Exception e){ - writerErrorResponse(response, ErrorResponse.of(response.getStatus(),e.getMessage())); - } - } - - private void writerErrorResponse(HttpServletResponse response, ErrorResponse errorResponse) throws IOException{ - response.setStatus(errorResponse.getStatus()); - response.setContentType(MediaType.APPLICATION_JSON_VALUE); - response.setCharacterEncoding("UTF-8"); - objectMapper.writeValue(response.getWriter(), errorResponse); - } - -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/error/GlobalExceptionHandler.java b/src/main/java/hackers/ground/sodam/global/error/GlobalExceptionHandler.java deleted file mode 100644 index 9317537..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/GlobalExceptionHandler.java +++ /dev/null @@ -1,47 +0,0 @@ -package hackers.ground.sodam.global.error; - -import hackers.ground.sodam.global.error.exception.StatusEnum; -import lombok.extern.slf4j.Slf4j; -import org.hibernate.exception.ConstraintViolationException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import hackers.ground.sodam.global.error.exception.BusinessException; - -@Slf4j -@RestControllerAdvice -public class GlobalExceptionHandler { - - @ExceptionHandler(BusinessException.class) - public ResponseEntity handleBusinessException(BusinessException e) { - log.error("CustomException message : {}", e.getMessage()); - - StatusEnum errorCode = e.getErrorCode(); - ErrorResponse response = ErrorResponse.of(errorCode, errorCode.getMessage()); - e.printStackTrace(); - - return new ResponseEntity<>(response, HttpStatus.valueOf(errorCode.getStatusCode())); - } - - @ExceptionHandler(ConstraintViolationException.class) - public ResponseEntity handleConstraintViolationException(ConstraintViolationException e) { - - StatusEnum errorCode = StatusEnum.BAD_REQUEST; - ErrorResponse response = ErrorResponse.of(errorCode, errorCode.getMessage()); - e.printStackTrace(); - - return new ResponseEntity<>(response, HttpStatus.valueOf(errorCode.getStatusCode())); - } - - @ExceptionHandler(Exception.class) - public ResponseEntity handleException(Exception e) { - log.error("에러", e); - - StatusEnum errorCode = StatusEnum.INTERNAL_SERVER_ERROR; - ErrorResponse response = ErrorResponse.of(errorCode, e.getMessage()); - - return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); - } - -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/EncryptException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/EncryptException.java deleted file mode 100644 index e66844b..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/EncryptException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class EncryptException extends BusinessException { - public static final BusinessException EXCEPTION = new EncryptException(); - - public EncryptException() { - super(StatusEnum.INTERNAL_SERVER_ERROR); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/ExpiredTokenException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/ExpiredTokenException.java deleted file mode 100644 index ae01755..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/ExpiredTokenException.java +++ /dev/null @@ -1,13 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class ExpiredTokenException extends BusinessException { - - public static final BusinessException EXCEPTION = new ExpiredTokenException(); - - public ExpiredTokenException() { - super(StatusEnum.EXPIRED_TOKEN); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/InvalidTokenException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/InvalidTokenException.java deleted file mode 100644 index b3b219e..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/InvalidTokenException.java +++ /dev/null @@ -1,14 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class InvalidTokenException extends BusinessException { - - public static final BusinessException EXCEPTION = new InvalidTokenException(); - - public InvalidTokenException(){ - super(StatusEnum.INVALID_TOKEN); - } - -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/RefreshTokenException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/RefreshTokenException.java deleted file mode 100644 index 9ee8e62..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/RefreshTokenException.java +++ /dev/null @@ -1,14 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class RefreshTokenException extends BusinessException { - - public static final BusinessException EXCEPTION = new RefreshTokenException(); - - public RefreshTokenException(){ - super(StatusEnum.REFRESH_TOKEN_NOT_FOUND); - } - -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/UnableToSendEmailException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/UnableToSendEmailException.java deleted file mode 100644 index f2a577b..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/UnableToSendEmailException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class UnableToSendEmailException extends BusinessException { - public static final BusinessException EXCEPTION = new UnableToSendEmailException(); - - public UnableToSendEmailException(){ - super(StatusEnum.UNABLE_TO_SEND_EMAIL); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/WithdrawalMemberException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/WithdrawalMemberException.java deleted file mode 100644 index fca39fd..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/WithdrawalMemberException.java +++ /dev/null @@ -1,14 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class WithdrawalMemberException extends BusinessException { - - public static final BusinessException EXCEPTION = new WithdrawalMemberException(); - - public WithdrawalMemberException(){ - super(StatusEnum.WITHDRAWAL_MEMBER); - } - -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongPasswordException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongPasswordException.java deleted file mode 100644 index 8aed956..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongPasswordException.java +++ /dev/null @@ -1,15 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class WrongPasswordException extends BusinessException { - - public static final BusinessException EXCEPTION = new WrongPasswordException(); - - public WrongPasswordException(){ - super(StatusEnum.WRONG_PASSWORD); - } - -} - diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongTokenTypeException.java b/src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongTokenTypeException.java deleted file mode 100644 index 37a5714..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/auth/WrongTokenTypeException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.auth; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class WrongTokenTypeException extends BusinessException { - static final BusinessException EXCEPTION = new WrongTokenTypeException(); - - private WrongTokenTypeException() { - super(StatusEnum.WRONG_TOKEN_TYPE); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/board/BoardNotFound.java b/src/main/java/hackers/ground/sodam/global/error/custom/board/BoardNotFound.java deleted file mode 100644 index dc944fd..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/board/BoardNotFound.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.board; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class BoardNotFound extends BusinessException { - public static final BusinessException EXCEPTION = new BoardNotFound(); - - public BoardNotFound(){ - super(StatusEnum.BOARD_NOT_FOUND); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/contest/ContestNotFound.java b/src/main/java/hackers/ground/sodam/global/error/custom/contest/ContestNotFound.java deleted file mode 100644 index 7c4aa1a..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/contest/ContestNotFound.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.contest; - -import hackers.ground.sodam.global.error.exception.StatusEnum; -import hackers.ground.sodam.global.error.exception.BusinessException; - -public class ContestNotFound extends BusinessException { - public static final BusinessException EXCEPTION = new ContestNotFound(); - - public ContestNotFound(){ - super(StatusEnum.CONTEST_NOT_FOUND); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/email/CodeIsWrongException.java b/src/main/java/hackers/ground/sodam/global/error/custom/email/CodeIsWrongException.java deleted file mode 100644 index 1159b97..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/email/CodeIsWrongException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.email; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class CodeIsWrongException extends BusinessException { - public static final BusinessException EXCEPTION = new CodeIsWrongException(); - - public CodeIsWrongException() { - super(StatusEnum.INVALID_AUTH_CODE); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/email/EmailAlreadyExistsException.java b/src/main/java/hackers/ground/sodam/global/error/custom/email/EmailAlreadyExistsException.java deleted file mode 100644 index f06fe77..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/email/EmailAlreadyExistsException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.email; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class EmailAlreadyExistsException extends BusinessException { - public static final BusinessException EXCEPTION = new EmailAlreadyExistsException(); - - public EmailAlreadyExistsException() { - super(StatusEnum.EMAIL_ALREADY_EXISTS); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/email/UnableToSendEmailException.java b/src/main/java/hackers/ground/sodam/global/error/custom/email/UnableToSendEmailException.java deleted file mode 100644 index a676ead..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/email/UnableToSendEmailException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.email; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class UnableToSendEmailException extends BusinessException { - public static final BusinessException EXCEPTION = new UnableToSendEmailException(); - - public UnableToSendEmailException() { - super(StatusEnum.UNABLE_TO_SEND_EMAIL); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/enroll/ENROLL_NOT_FOUND.java b/src/main/java/hackers/ground/sodam/global/error/custom/enroll/ENROLL_NOT_FOUND.java deleted file mode 100644 index e8165f3..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/enroll/ENROLL_NOT_FOUND.java +++ /dev/null @@ -1,13 +0,0 @@ -package hackers.ground.sodam.global.error.custom.enroll; - - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class ENROLL_NOT_FOUND extends BusinessException { - public static final BusinessException EXCEPTION = new ENROLL_NOT_FOUND(); - - public ENROLL_NOT_FOUND() { - super(StatusEnum.ENROLL_NOT_FOUND);} - -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/member/IdAlreadyExistException.java b/src/main/java/hackers/ground/sodam/global/error/custom/member/IdAlreadyExistException.java deleted file mode 100644 index 4f3213a..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/member/IdAlreadyExistException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.member; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class IdAlreadyExistException extends BusinessException { - public static final BusinessException EXCEPTION = new IdAlreadyExistException(); - - public IdAlreadyExistException() { - super(StatusEnum.ID_ALREADY_EXIST); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/member/InvalidRoleException.java b/src/main/java/hackers/ground/sodam/global/error/custom/member/InvalidRoleException.java deleted file mode 100644 index fdfd3dd..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/member/InvalidRoleException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.member; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class InvalidRoleException extends BusinessException { - public static final BusinessException EXCEPTION = new InvalidRoleException(); - - public InvalidRoleException() { - super(StatusEnum.ID_ALREADY_EXIST); - } -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotCoincideException.java b/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotCoincideException.java deleted file mode 100644 index 27686c6..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotCoincideException.java +++ /dev/null @@ -1,10 +0,0 @@ -package hackers.ground.sodam.global.error.custom.member; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class MemberNotCoincideException extends BusinessException { - public static final BusinessException EXCEPTION = new MemberNotCoincideException(); - - public MemberNotCoincideException() {super(StatusEnum.MEMBER_NOT_COINCIDE);} -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotExistException.java b/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotExistException.java deleted file mode 100644 index 1f34e90..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotExistException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.member; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class MemberNotExistException extends BusinessException { - public static final BusinessException EXCEPTION = new MemberNotExistException(); - - public MemberNotExistException() { - super(StatusEnum.MEMBER_NOT_EXISTS); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotFoundException.java b/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotFoundException.java deleted file mode 100644 index 50c303c..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/member/MemberNotFoundException.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.member; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class MemberNotFoundException extends BusinessException { - public static final BusinessException EXCEPTION = new MemberNotFoundException(); - - public MemberNotFoundException() { - super(StatusEnum.MEMBER_NOT_FOUND); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/member/NeedAuthCode.java b/src/main/java/hackers/ground/sodam/global/error/custom/member/NeedAuthCode.java deleted file mode 100644 index 475b3ad..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/member/NeedAuthCode.java +++ /dev/null @@ -1,12 +0,0 @@ -package hackers.ground.sodam.global.error.custom.member; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class NeedAuthCode extends BusinessException { - public static final BusinessException EXCEPTION = new NeedAuthCode(); - - public NeedAuthCode() { - super(StatusEnum.MISSING_AUTH_CODE); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/error/custom/member/PermissionDeniedException.java b/src/main/java/hackers/ground/sodam/global/error/custom/member/PermissionDeniedException.java deleted file mode 100644 index 4492a69..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/custom/member/PermissionDeniedException.java +++ /dev/null @@ -1,13 +0,0 @@ -package hackers.ground.sodam.global.error.custom.member; - -import hackers.ground.sodam.global.error.exception.BusinessException; -import hackers.ground.sodam.global.error.exception.StatusEnum; - -public class PermissionDeniedException extends BusinessException { - public static final BusinessException EXCEPTION = new PermissionDeniedException(); - - public PermissionDeniedException() { - super(StatusEnum.PERMISSION_DENIED); - } -} - diff --git a/src/main/java/hackers/ground/sodam/global/error/exception/BusinessException.java b/src/main/java/hackers/ground/sodam/global/error/exception/BusinessException.java deleted file mode 100644 index b92e777..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/exception/BusinessException.java +++ /dev/null @@ -1,10 +0,0 @@ -package hackers.ground.sodam.global.error.exception; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -public class BusinessException extends RuntimeException { - private final StatusEnum errorCode; -} diff --git a/src/main/java/hackers/ground/sodam/global/error/exception/StatusEnum.java b/src/main/java/hackers/ground/sodam/global/error/exception/StatusEnum.java deleted file mode 100644 index 8f720ff..0000000 --- a/src/main/java/hackers/ground/sodam/global/error/exception/StatusEnum.java +++ /dev/null @@ -1,64 +0,0 @@ -package hackers.ground.sodam.global.error.exception; - -import com.fasterxml.jackson.annotation.JsonFormat; -import lombok.AllArgsConstructor; -import lombok.Getter; - -@Getter -@AllArgsConstructor -@JsonFormat(shape = JsonFormat.Shape.OBJECT) -public enum StatusEnum { - //smtp - NOT_DUPLICATED_AUTH_CODE(400, "인증코드가 일치하지 않습니다."), - EXPIRED_TOKEN(401, "만료된 토큰입니다."), - INVALID_TOKEN(401, "유효하지 않은 토큰입니다."), - REFRESH_TOKEN_NOT_FOUND(401, "리프레시 토큰을 찾을 수 없습니다."), - MALFORMED_JWT(400, "변형된 토큰입니다."), - ILLEGAL_ARGUMENT(400, "요청이 잘못되었습니다."), - UNSUPPORTED_JWT(400, "지원되지 않습니다."), - WRONG_TOKEN_TYPE(400, "토큰타입이 옳지 않습니다."), - - // general - OK(200, "OK"), - CREATED(201, "Created"), - BAD_REQUEST(400, "Bad request"), - INTERNAL_SERVER_ERROR(500, "Internal server error"), - - //member - MEMBER_NOT_EXISTS(403, "멤버가 존재하지 않습니다."), - MEMBER_NOT_COINCIDE(401, "멤버가 일치하지 않습니다."), - MEMBER_NOT_FOUND(404, "멤버를 찾을수 없습니다."), - NOT_AUTHENTICATED(401, "인증되지 않았습니다."), - PERMISSION_DENIED(403, "권한이 없습니다."), - WITHDRAWAL_MEMBER(400, "탈퇴된 멤버입니다."), - INVALID_ROLE(403, "유효하지 않은 권한"), - WRONG_PASSWORD(403, "비밀번호가 옳지 않습니다"), - ID_ALREADY_EXIST(404, "아이디가 이미 존재합니다."), - - //file - FILE_NOT_FOUND(404, "파일을 찾을 수 없습니다."), - FILE_EXISTS(403, "파일이 이미 존재합니다."), - - //email - UNABLE_TO_SEND_EMAIL(500, "이메일 전송에 실패했습니다."), - EMAIL_ALREADY_EXISTS(409, "이메일 주소가 이미 사용 중입니다."), - INVALID_AUTH_CODE(400, "유효하지 않은 인증 코드입니다."), - MISSING_AUTH_CODE(400, "인증 코드가 제공되지 않았습니다."), - //fcm - MESSAGE_SEND_FAILED(403, "메세지 전송에 실패했습니다."), - TOKEN_NOT_PROVIDED(400, "권한이 없습니다."), - - CLOUD_EXCEPTION(500, "클라우드 에러"), - - // board - BOARD_NOT_FOUND(404, "게시물을 찾을 수 없습니다."), - - // contest - CONTEST_NOT_FOUND(404, "대회를 찾을 수 없습니다"), - - // enroll - ENROLL_NOT_FOUND(404, "신청을 찾을 수 없습니다"); - - private final int statusCode; - private final String message; -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtExceptionFilter.java b/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtExceptionFilter.java deleted file mode 100644 index f815094..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtExceptionFilter.java +++ /dev/null @@ -1,57 +0,0 @@ -package hackers.ground.sodam.global.infra.jwt; - -import com.fasterxml.jackson.databind.ObjectMapper; -import hackers.ground.sodam.global.error.ErrorResponse; -import hackers.ground.sodam.global.error.exception.StatusEnum; -import io.jsonwebtoken.ExpiredJwtException; -import io.jsonwebtoken.MalformedJwtException; -import io.jsonwebtoken.UnsupportedJwtException; -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; -import org.springframework.web.filter.OncePerRequestFilter; - -import java.io.IOException; - -@Component -@RequiredArgsConstructor -public class JwtExceptionFilter extends OncePerRequestFilter { - - private final ObjectMapper objectMapper; - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) - throws ServletException, IOException { - try { - filterChain.doFilter(request, response); - } catch (ExpiredJwtException e) { - setErrorResponse(response, StatusEnum.EXPIRED_TOKEN); - } catch (MalformedJwtException e) { - setErrorResponse(response, StatusEnum.MALFORMED_JWT); - } catch (UnsupportedJwtException e) { - setErrorResponse(response, StatusEnum.UNSUPPORTED_JWT); - } catch (IllegalArgumentException e) { - setErrorResponse(response, StatusEnum.ILLEGAL_ARGUMENT); - } - } - - private void setErrorResponse(HttpServletResponse response, StatusEnum error) { - try { - responseToClient(response, ErrorResponse.of(error, error.getMessage())); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void responseToClient(HttpServletResponse response, ErrorResponse errorResponse) throws IOException { - response.setStatus(errorResponse.getStatus()); - response.setContentType(MediaType.APPLICATION_JSON_VALUE); - response.setCharacterEncoding("UTF-8"); - response.getWriter().write(objectMapper.writeValueAsString(errorResponse)); - } - -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtFilter.java b/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtFilter.java deleted file mode 100644 index 2b36b8e..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtFilter.java +++ /dev/null @@ -1,43 +0,0 @@ -package hackers.ground.sodam.global.infra.jwt; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.HttpHeaders; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Component; -import org.springframework.web.filter.OncePerRequestFilter; - -import java.io.IOException; - -@Component -@RequiredArgsConstructor -@Slf4j -public class JwtFilter extends OncePerRequestFilter { - - private final JwtHelper jwtHelper; - - @Override - protected void doFilterInternal( - HttpServletRequest request, - HttpServletResponse response, - FilterChain filterChain - ) throws IOException, ServletException { - final String token = extractTokenFromRequest(request); - - if(token != null) { - Authentication authentication = jwtHelper.getAuthentication(token); - SecurityContextHolder.getContext().setAuthentication(authentication); - } - filterChain.doFilter(request, response); - } - - public String extractTokenFromRequest(HttpServletRequest request) { - return jwtHelper.extractToken(request.getHeader(HttpHeaders.AUTHORIZATION)); - } - -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtHelper.java b/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtHelper.java deleted file mode 100644 index 05f3598..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -package hackers.ground.sodam.global.infra.jwt; - -import hackers.ground.sodam.global.infra.security.CustomMemberDetails; -import hackers.ground.sodam.global.properties.JwtProperties; -import hackers.ground.sodam.domain.user.entity.UserEntity; -import hackers.ground.sodam.domain.user.repository.UserRepository; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.Jwts; -import lombok.RequiredArgsConstructor; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.StringUtils; - -@Component -@RequiredArgsConstructor -public class JwtHelper { - - private final UserRepository userRepository; - private final JwtProperties jwtProperties; - - @Transactional - public Authentication getAuthentication(String accessToken) { - Claims claims = getClaims(accessToken); - UserEntity user = userRepository.findByUserId(claims.getSubject()); - - CustomMemberDetails details = new CustomMemberDetails(user); - - return new UsernamePasswordAuthenticationToken(details, null, details.getAuthorities()); - } - - public Claims getClaims(String token) { - return Jwts.parserBuilder().setSigningKey(jwtProperties.getSecretKey()).build().parseClaimsJws(token).getBody(); - } - - public String extractToken(final String token) { - if (StringUtils.hasText(token) && token.startsWith("Bearer ")) { - return token.substring(7); - } - return token; - } - -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtProvider.java b/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtProvider.java deleted file mode 100644 index bbd8de2..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -package hackers.ground.sodam.global.infra.jwt; - -import hackers.ground.sodam.global.properties.JwtProperties; -import hackers.ground.sodam.domain.auth.presentation.dto.res.TokenRes; -import hackers.ground.sodam.domain.user.enums.UserState; -import hackers.ground.sodam.domain.user.repository.UserRepository; -import io.jsonwebtoken.Header; -import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; -import hackers.ground.sodam.global.error.custom.auth.WithdrawalMemberException; - -import java.util.Date; - -@Component -@RequiredArgsConstructor -public class JwtProvider { - private final JwtProperties jwtProperties; - private final UserRepository userRepository; - - public TokenRes generateToken(String id, final UserState userState) { - if(userRepository.findByUserId(id).getUserState()== UserState.DELETED){ - throw WithdrawalMemberException.EXCEPTION; - } - return new TokenRes( - generateAccessToken(id, userState), - generateRefreshToken(id, userState)); - } - - - public String generateAccessToken(String id, final UserState userState) { - return Jwts.builder() - .setHeaderParam(Header.JWT_TYPE, JwtType.ACCESS) - .setSubject(id) - .claim("Authorization", userState) - .setIssuedAt(new Date()) - .setExpiration(new Date(System.currentTimeMillis() + jwtProperties.getAccessExpiration())) - .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecretKey()) - .compact(); - } - - public String generateRefreshToken(String id, final UserState userState) { - return Jwts.builder() - .setHeaderParam(Header.JWT_TYPE, JwtType.REFRESH) - .claim("Authorization", userState) - .setSubject(id.toString()) - .setIssuedAt(new Date()) - .setExpiration(new Date(System.currentTimeMillis() + jwtProperties.getRefreshExpiration())) - .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecretKey()) - .compact(); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtType.java b/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtType.java deleted file mode 100644 index c601fe0..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/jwt/JwtType.java +++ /dev/null @@ -1,5 +0,0 @@ -package hackers.ground.sodam.global.infra.jwt; - -public enum JwtType { - REFRESH, ACCESS -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/jwt/ParseToken.java b/src/main/java/hackers/ground/sodam/global/infra/jwt/ParseToken.java deleted file mode 100644 index 039885f..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/jwt/ParseToken.java +++ /dev/null @@ -1,42 +0,0 @@ -package hackers.ground.sodam.global.infra.jwt; - -import hackers.ground.sodam.global.properties.JwtProperties; -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.Header; -import io.jsonwebtoken.Jws; -import io.jsonwebtoken.Jwts; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; - -import java.lang.invoke.WrongMethodTypeException; - -@Component -@RequiredArgsConstructor -public class ParseToken { - private final JwtProperties jwtProperties; - private final JwtHelper jwtHelper; - - public String getSubjectFromRefreshToken(final String refreshToken) { - return getSubject(refreshToken, JwtType.REFRESH); - } - - public String getSubjectFromAccessToken(final String accessToken) { - return getSubject(accessToken, JwtType.ACCESS); - } - - private String getSubject(final String token, final JwtType jwtType) { - final String key = jwtProperties.getSecretKey(); - - final Jws jwsClaims = Jwts.parser().setSigningKey(key).parseClaimsJws(jwtHelper.extractToken(token)); - - this.isWrongType(jwsClaims, jwtType); - - return jwsClaims.getBody().getSubject(); - } - - private void isWrongType(final Jws claims, final JwtType jwtType) { - if(!(claims.getHeader().get(Header.JWT_TYPE).equals(jwtType.toString()))) { - throw new WrongMethodTypeException(); - } - } -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/security/CustomAccessDeniedHandler.java b/src/main/java/hackers/ground/sodam/global/infra/security/CustomAccessDeniedHandler.java deleted file mode 100644 index cfc0182..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/security/CustomAccessDeniedHandler.java +++ /dev/null @@ -1,19 +0,0 @@ -package hackers.ground.sodam.global.infra.security; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.springframework.security.access.AccessDeniedException; -import org.springframework.security.web.access.AccessDeniedHandler; -import org.springframework.stereotype.Component; -import hackers.ground.sodam.global.error.custom.auth.ExpiredTokenException; - -@Component -public class CustomAccessDeniedHandler implements AccessDeniedHandler { - - @Override - public void handle(HttpServletRequest request, - HttpServletResponse response, - AccessDeniedException accessDeniedException){ - throw ExpiredTokenException.EXCEPTION; - } -} \ No newline at end of file diff --git a/src/main/java/hackers/ground/sodam/global/infra/security/CustomMemberDetails.java b/src/main/java/hackers/ground/sodam/global/infra/security/CustomMemberDetails.java deleted file mode 100644 index 519e740..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/security/CustomMemberDetails.java +++ /dev/null @@ -1,52 +0,0 @@ -package hackers.ground.sodam.global.infra.security; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; -import hackers.ground.sodam.domain.user.entity.UserEntity; - -import java.util.ArrayList; -import java.util.Collection; - -public record CustomMemberDetails(UserEntity user) implements UserDetails { - - @Override - public Collection getAuthorities() { - Collection collections = new ArrayList<>(); - collections.add(() -> user.getUserState().getKey()); - return collections; - } - - public static CustomMemberDetails of(UserEntity userEntity) { - return new CustomMemberDetails(userEntity); - } - - @Override - public String getPassword() { - return user.getUserPassword(); - } - - @Override - public String getUsername() { - return user.getUserName(); - } - - @Override - public boolean isAccountNonExpired() { - return true; - } - - @Override - public boolean isAccountNonLocked() { - return true; - } - - @Override - public boolean isCredentialsNonExpired() { - return true; - } - - @Override - public boolean isEnabled() { - return true; - } -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/security/GetCurrentMember.java b/src/main/java/hackers/ground/sodam/global/infra/security/GetCurrentMember.java deleted file mode 100644 index 93b038d..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/security/GetCurrentMember.java +++ /dev/null @@ -1,16 +0,0 @@ -package hackers.ground.sodam.global.infra.security; - -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Component; -import hackers.ground.sodam.domain.user.entity.UserEntity; - -@Component -public class GetCurrentMember { - public UserEntity current() { - return getMemberDetails().user(); - } - - private CustomMemberDetails getMemberDetails() { - return ((CustomMemberDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/infra/security/MemberDetailsService.java b/src/main/java/hackers/ground/sodam/global/infra/security/MemberDetailsService.java deleted file mode 100644 index 8c192bd..0000000 --- a/src/main/java/hackers/ground/sodam/global/infra/security/MemberDetailsService.java +++ /dev/null @@ -1,21 +0,0 @@ -package hackers.ground.sodam.global.infra.security; - -import hackers.ground.sodam.domain.auth.presentation.dto.res.TokenRes; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; -import hackers.ground.sodam.domain.user.entity.UserEntity; -import hackers.ground.sodam.domain.user.repository.UserRepository; -import hackers.ground.sodam.global.infra.jwt.JwtProvider; - -@Component -@RequiredArgsConstructor -public class MemberDetailsService { - - private final UserRepository userRepository; - private final JwtProvider jwtProvider; - - public TokenRes loadUserByUsername(String id) { - UserEntity memberEntity = userRepository.findByUserId(id); - return jwtProvider.generateToken(id, memberEntity.getUserState()); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/properties/JwtProperties.java b/src/main/java/hackers/ground/sodam/global/properties/JwtProperties.java deleted file mode 100644 index d49dfe4..0000000 --- a/src/main/java/hackers/ground/sodam/global/properties/JwtProperties.java +++ /dev/null @@ -1,16 +0,0 @@ -package hackers.ground.sodam.global.properties; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Getter -@Setter -@Configuration -@ConfigurationProperties("application.jwt") -public class JwtProperties { - private String secretKey; - private Long accessExpiration; - private Long refreshExpiration; -} diff --git a/src/main/java/hackers/ground/sodam/global/response/Response.java b/src/main/java/hackers/ground/sodam/global/response/Response.java deleted file mode 100644 index 33146c8..0000000 --- a/src/main/java/hackers/ground/sodam/global/response/Response.java +++ /dev/null @@ -1,9 +0,0 @@ -package hackers.ground.sodam.global.response; - -import org.springframework.http.HttpStatus; - -public record Response(int status, String message) { - public static Response of(HttpStatus status, String message) { - return new Response(status.value(), message); - } -} diff --git a/src/main/java/hackers/ground/sodam/global/response/ResponseData.java b/src/main/java/hackers/ground/sodam/global/response/ResponseData.java deleted file mode 100644 index 8e54502..0000000 --- a/src/main/java/hackers/ground/sodam/global/response/ResponseData.java +++ /dev/null @@ -1,13 +0,0 @@ -package hackers.ground.sodam.global.response; - -import org.springframework.http.HttpStatus; - -public record ResponseData( - int status, - String message, - T data -) { - public static ResponseData of(HttpStatus status, String message, T data) { - return new ResponseData<>(status.value(), message, data); - } -}