From 317ca343e61d8e102f3129b599746d20f1d23112 Mon Sep 17 00:00:00 2001 From: yyy9942 Date: Sun, 12 Jan 2020 13:58:07 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=EB=9D=BC=EC=9D=B4=EB=8D=94=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B0=9C=EB=B0=9C=20?= =?UTF-8?q?-=20=ED=9A=8C=EC=9B=90=20=EA=B0=80=EC=9E=85=20-=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20-=20=EB=A1=9C=EA=B7=B8=EC=95=84=EC=9B=83?= =?UTF-8?q?=20-=20=EC=95=84=EC=9D=B4=EB=94=94=EC=99=80=20=EB=B9=84?= =?UTF-8?q?=EB=B0=80=EB=B2=88=ED=98=B8=EB=A1=9C=20=EC=9C=A0=ED=9A=A8?= =?UTF-8?q?=EC=84=B1=20=EA=B2=80=EC=82=AC=20-=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EB=B3=80=EA=B2=BD=20-=20=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/delfood/aop/AuthCheckAspect.java | 21 +++ .../java/com/delfood/aop/RiderLoginCheck.java | 9 + .../delfood/controller/RiderController.java | 162 ++++++++++++++++++ .../java/com/delfood/dto/rider/RiderDTO.java | 106 ++++++++++++ .../com/delfood/error/ErrorController.java | 7 + .../error/exception/IdDeletedException.java | 7 + .../com/delfood/mapper/RiderInfoMapper.java | 24 +++ .../service/rider/RiderInfoService.java | 147 ++++++++++++++++ .../java/com/delfood/utils/SessionUtil.java | 20 +++ src/main/resources/mybatis/mapper/rider.xml | 50 ++++++ 10 files changed, 553 insertions(+) create mode 100644 src/main/java/com/delfood/aop/RiderLoginCheck.java create mode 100644 src/main/java/com/delfood/controller/RiderController.java create mode 100644 src/main/java/com/delfood/dto/rider/RiderDTO.java create mode 100644 src/main/java/com/delfood/error/exception/IdDeletedException.java create mode 100644 src/main/java/com/delfood/mapper/RiderInfoMapper.java create mode 100644 src/main/java/com/delfood/service/rider/RiderInfoService.java create mode 100644 src/main/resources/mybatis/mapper/rider.xml diff --git a/src/main/java/com/delfood/aop/AuthCheckAspect.java b/src/main/java/com/delfood/aop/AuthCheckAspect.java index 4bd00b7..990280f 100644 --- a/src/main/java/com/delfood/aop/AuthCheckAspect.java +++ b/src/main/java/com/delfood/aop/AuthCheckAspect.java @@ -1,5 +1,6 @@ package com.delfood.aop; +import java.util.Objects; import javax.servlet.http.HttpSession; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.Aspect; @@ -93,4 +94,24 @@ public void memberLoginCheck(JoinPoint jp) throws Throwable { throw new HttpStatusCodeException(HttpStatus.UNAUTHORIZED, "NO_LOGIN") {}; } } + + /** + * 라이더 로그인을 체크한다. + * @author jun + * @param jp 조인포인트 + * @throws Throwable 발생 가능한 예외 설정 + */ + @Before("@annotation(com.delfood.aop.RiderLoginCheck)") + public void riderLoginCheck(JoinPoint jp) throws Throwable { + log.debug("AOP - Rider Login Check Started"); + + HttpSession session = + ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest() + .getSession(); + String riderId = SessionUtil.getLoginRiderId(session); + + if (Objects.isNull(riderId)) { + throw new HttpStatusCodeException(HttpStatus.UNAUTHORIZED, "RIDER_NO_LOGIN") {}; + } + } } diff --git a/src/main/java/com/delfood/aop/RiderLoginCheck.java b/src/main/java/com/delfood/aop/RiderLoginCheck.java new file mode 100644 index 0000000..a7e0fb4 --- /dev/null +++ b/src/main/java/com/delfood/aop/RiderLoginCheck.java @@ -0,0 +1,9 @@ +package com.delfood.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target(ElementType.METHOD) +public @interface RiderLoginCheck { + +} diff --git a/src/main/java/com/delfood/controller/RiderController.java b/src/main/java/com/delfood/controller/RiderController.java new file mode 100644 index 0000000..cdc5c9b --- /dev/null +++ b/src/main/java/com/delfood/controller/RiderController.java @@ -0,0 +1,162 @@ +package com.delfood.controller; + +import com.delfood.aop.RiderLoginCheck; +import com.delfood.dto.rider.RiderDTO; +import com.delfood.service.rider.RiderInfoService; +import com.delfood.utils.SessionUtil; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.Objects; +import javax.servlet.http.HttpSession; +import lombok.Getter; +import lombok.NonNull; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +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.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +@Log4j2 +@RestController +@RequestMapping("/riders/") +public class RiderController { + + @Autowired + private RiderInfoService riderInfoService; + + @Autowired + private ObjectMapper objectMapper; + + /** + * 아이디 중복 체크. + * @author jun + * @param riderId 중복체크할 아이디 + * @return 중복된 아이디라면 true + */ + @GetMapping("duplicated/id/{riderId}") + public boolean isDuplicatedId(@PathVariable(name = "riderId") String riderId) { + return riderInfoService.isDuplicatedId(riderId); + } + + /** + * 라이더 회원가입. + * @author jun + * @param riderInfo 회원가입할 아이디 정보 + * @throws JsonProcessingException 로그를 기록할 때 직렬화중 생길 수 있는 예외 + */ + @PostMapping("signUp") + @ResponseStatus(code = HttpStatus.CREATED) + public void signUp(@RequestBody RiderDTO riderInfo) throws JsonProcessingException { + if (riderInfo.hasNullData()) { + log.info("회원가입 필수 데이터 누락. 요청 정보 : {}", objectMapper.writeValueAsString(riderInfo)); + throw new NullPointerException("라이더 회원가입에 필수 데이터가 누락되었습니다."); + } + + RiderDTO encryptRiderInfo = RiderDTO.encryptDTO(riderInfo); + riderInfoService.signUp(encryptRiderInfo); + } + + /** + * 라이더 로그인을 진행한다. + * + * @author jun + * @param request id, password 정보 + * @param session 현재 세션 + * @return + */ + @PostMapping("login") + public RiderDTO signIn(@RequestBody SignInRequest request, HttpSession session) { + if (Objects.isNull(SessionUtil.getLoginRiderId(session)) == false) { + logout(session); + } + + RiderDTO riderInfo = riderInfoService.signIn(request.getId(), request.getPassword()); + SessionUtil.setLoginRiderId(session, riderInfo.getId()); + return riderInfo; + } + + + /** + * 라이더 로그아웃을 진행한다. + * @author jun + * @param session 사용자의 세션 + */ + @GetMapping("logout") + public void logout(HttpSession session) { + SessionUtil.logoutRider(session); + } + + /** + * 라이더의 비밀번호를 변경한다. + * @param session 사용자의 세션 + * @param request 변경전 비밀번호, 변경할 비밀번호 정보 + */ + @PatchMapping("update/password") + @RiderLoginCheck + public void updatePassword(HttpSession session, @RequestBody UpdatePasswordRequest request) { + String id = SessionUtil.getLoginRiderId(session); + riderInfoService.changePassword(id, request.getPasswordBeforechange(), + request.getPasswordAfterChange()); + } + + /** + * 라이더의 계정을 삭제한다. + * 삭제가 완료된다면 로그아웃된다. + * @param session 현제 사용자의 세션 + * @param password 유효성 검사를 위한 계정 비밀번호 + */ + @DeleteMapping + @RiderLoginCheck + public void deleteRiderAccount(HttpSession session, String password) { + String id = SessionUtil.getLoginRiderId(session); + riderInfoService.deleteAccount(id, password); + SessionUtil.logoutRider(session); + } + + @PatchMapping("update/mail") + public void updateMail(HttpSession session, @RequestBody UpdateMailRequest request) { + String id = SessionUtil.getLoginRiderId(session); + riderInfoService.changeMail(id, request.getPassword(), request.getUpdateMail()); + } + + + + // Request + @Getter + private static class SignInRequest { + @NonNull + private String id; + + @NonNull + private String password; + } + + @Getter + private static class UpdatePasswordRequest { + @NonNull + private String passwordBeforechange; + + @NonNull + private String passwordAfterChange; + } + + @Getter + private static class UpdateMailRequest { + @NonNull + private String password; + + @NonNull + private String updateMail; + } + + + +} diff --git a/src/main/java/com/delfood/dto/rider/RiderDTO.java b/src/main/java/com/delfood/dto/rider/RiderDTO.java new file mode 100644 index 0000000..3899931 --- /dev/null +++ b/src/main/java/com/delfood/dto/rider/RiderDTO.java @@ -0,0 +1,106 @@ +package com.delfood.dto.rider; + +import java.time.LocalDateTime; +import java.util.Objects; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.codehaus.commons.nullanalysis.Nullable; +import org.codehaus.jackson.annotate.JsonIgnore; +import com.delfood.utils.SHA256Util; + +@Getter +@NoArgsConstructor +public class RiderDTO { + @NonNull + private String id; + + @NonNull + private String password; + + @NonNull + private String name; + + @NonNull + private String tel; + + @NonNull + private String mail; + + @Nullable + private Status status = Status.DEFAULT; + + @Nullable + private LocalDateTime createdAt; + + @Nullable + private LocalDateTime updatedAt; + + + public enum Status { + DEFAULT, DELETED + } + + /** + * RiderDTO Class Builder. + * @param id 아이디 + * @param password 비밀번호 + * @param name 이름 + * @param tel 휴대전화 번호 + * @param mail 메일 + * @param status 계정 상태 + * @param createdAt 회원가입일 + * @param updatedAt 회원정보 수정일 + */ + @Builder + public RiderDTO(String id, String password, String name, String tel, String mail, Status status, + LocalDateTime createdAt, LocalDateTime updatedAt) { + this.id = id; + this.password = password; + this.name = name; + this.tel = tel; + this.mail = mail; + this.status = status == null ? Status.DEFAULT : status; + this.createdAt = createdAt == null ? LocalDateTime.now() : createdAt; + this.updatedAt = updatedAt == null ? LocalDateTime.now() : updatedAt; + } + + /** + * null이 허용되지 않는 필드에 null값이 있는지 확인한다. + * @author jun + * @return + */ + public boolean hasNullData() { + return Objects.isNull(this.id) + || Objects.isNull(this.password) + || Objects.isNull(this.name) + || Objects.isNull(this.tel) + || Objects.isNull(this.mail); + } + + /** + * 객체를 복사하여 패스워드를 암호화한 객체를 생성하여 리턴한다. + * @author jun + * @param riderInfo 암호화할 회원 정보 + * @return + */ + public static RiderDTO encryptDTO(RiderDTO riderInfo) { + String encryptPassword = SHA256Util.encryptSHA256(riderInfo.getPassword()); + return RiderDTO.builder() + .id(riderInfo.getId()) + .password(encryptPassword) + .name(riderInfo.getName()) + .tel(riderInfo.getTel()) + .mail(riderInfo.getMail()) + .status(riderInfo.getStatus()) + .createdAt(riderInfo.getCreatedAt()) + .updatedAt(riderInfo.getUpdatedAt()) + .build(); + } + + @JsonIgnore + public String getPassword() { + return this.password; + } +} diff --git a/src/main/java/com/delfood/error/ErrorController.java b/src/main/java/com/delfood/error/ErrorController.java index a377970..2429380 100644 --- a/src/main/java/com/delfood/error/ErrorController.java +++ b/src/main/java/com/delfood/error/ErrorController.java @@ -1,6 +1,7 @@ package com.delfood.error; import com.delfood.error.exception.DuplicateIdException; +import com.delfood.error.exception.IdDeletedException; import com.delfood.error.exception.cart.DuplicateItemException; import com.delfood.error.exception.coupon.IssuedCouponExistException; import com.delfood.error.exception.menuGroup.InvalidMenuGroupCountException; @@ -93,4 +94,10 @@ public ErrorMsg handleDuplicatedItemException(DuplicateItemException e) { public ErrorMsg handleMockPayException(MockPayException e) { return new ErrorMsg(e.getLocalizedMessage(), getSimpleName(e)); } + + @ResponseStatus(HttpStatus.UNAUTHORIZED) + @ExceptionHandler(IdDeletedException.class) + public ErrorMsg handleIdDeletedException(IdDeletedException e) { + return new ErrorMsg(e.getLocalizedMessage(), getSimpleName(e)); + } } diff --git a/src/main/java/com/delfood/error/exception/IdDeletedException.java b/src/main/java/com/delfood/error/exception/IdDeletedException.java new file mode 100644 index 0000000..a34248b --- /dev/null +++ b/src/main/java/com/delfood/error/exception/IdDeletedException.java @@ -0,0 +1,7 @@ +package com.delfood.error.exception; + +public class IdDeletedException extends IllegalArgumentException { + public IdDeletedException(String msg) { + super(msg); + } +} diff --git a/src/main/java/com/delfood/mapper/RiderInfoMapper.java b/src/main/java/com/delfood/mapper/RiderInfoMapper.java new file mode 100644 index 0000000..8df7aea --- /dev/null +++ b/src/main/java/com/delfood/mapper/RiderInfoMapper.java @@ -0,0 +1,24 @@ +package com.delfood.mapper; + +import com.delfood.dto.rider.RiderDTO; +import lombok.NonNull; +import org.springframework.stereotype.Repository; + +@Repository +public interface RiderInfoMapper { + + public boolean isExistById(@NonNull String id); + + public void insertRider(@NonNull RiderDTO riderInfo); + + public RiderDTO findByIdAndPassword(@NonNull String id, @NonNull String password); + + public long updatePassword(@NonNull String id, @NonNull String password); + + public long updateStatusAsDeleted(@NonNull String id); + + public boolean isExistAndEffectiveByIdAndPassword(@NonNull String id, + @NonNull String password); + + public long updateMail(@NonNull String id, @NonNull String mail); +} diff --git a/src/main/java/com/delfood/service/rider/RiderInfoService.java b/src/main/java/com/delfood/service/rider/RiderInfoService.java new file mode 100644 index 0000000..7478520 --- /dev/null +++ b/src/main/java/com/delfood/service/rider/RiderInfoService.java @@ -0,0 +1,147 @@ +package com.delfood.service.rider; + +import com.delfood.dto.rider.RiderDTO; +import com.delfood.error.exception.DuplicateException; +import com.delfood.error.exception.IdDeletedException; +import com.delfood.mapper.RiderInfoMapper; +import com.delfood.utils.SHA256Util; +import java.util.Objects; +import lombok.NonNull; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Log4j2 +public class RiderInfoService { + + @Autowired + private RiderInfoMapper riderInfoMapper; + + private static final IllegalArgumentException passwordMismatchException = + new IllegalArgumentException("비밀번호가 일치하지 않습니다."); + + /** + * 해당 아이디가 중복된 아이디인지 확인한다. + * + * @author jun + * @param riderId 중복인지 검사할 아이디 + * @return + */ + public boolean isDuplicatedId(@NonNull String riderId) { + return riderInfoMapper.isExistById(riderId); + } + + /** + * 라이더 회원가입을 진행한다. + * @param riderInfo 회원 가입 정보 + */ + @Transactional + public void signUp(@NonNull RiderDTO riderInfo) { + if (isDuplicatedId(riderInfo.getId())) { + throw new DuplicateException("아이디 \"" + riderInfo.getId() + "\" 는 이미 가입한 아이디입니다."); + } + + riderInfoMapper.insertRider(riderInfo); + } + + /** + * 라이더 로그인을 진행한다. + * @param id 아이디 + * @param password 암호화 전 비밀번호 + * @return + */ + public RiderDTO signIn(@NonNull String id, @NonNull String password) { + String encryptedPassword = SHA256Util.encryptSHA256(password); + RiderDTO riderInfo = getRiderInfo(id, encryptedPassword); + + if (RiderDTO.Status.DELETED.equals(riderInfo.getStatus())) { + log.info("signIn - 삭제 회원 로그인 시도. id : {}, password : {}", id, encryptedPassword); + throw new IdDeletedException("Rider의 계정이 삭제 상태입니다. 로그인할 수 없습니다."); + } + + + + return riderInfo; + } + + /** + * 라이더의 비밀번호를 변경한다. + * @param id 라이더 아이디 + * @param passwordBeforeChange 변경 전 비밀번호 + * @param passwordAfterChange 변경할 비밀번호 + */ + @Transactional + public void changePassword(@NonNull String id, @NonNull String passwordBeforeChange, + String passwordAfterChange) { + if (isEffective(id, passwordBeforeChange) == false) { + throw passwordMismatchException; + } + + String encryptedPasswordAfter = SHA256Util.encryptSHA256(passwordAfterChange); + riderInfoMapper.updatePassword(id, encryptedPasswordAfter); + } + + /** + * 라이더 계정 정보를 조회한다. + * 일치하는 계정이 없을 시 예외를 발생시킨다. + * @author jun + * @param id 조회할 라이더 계정 아이디 + * @param encryptedPassword 암호화를 진행한 비밀번호 + * @return + */ + public RiderDTO getRiderInfo(@NonNull String id, @NonNull String encryptedPassword) { + RiderDTO riderInfo = riderInfoMapper.findByIdAndPassword(id, encryptedPassword); + + if (Objects.isNull(riderInfo)) { + log.info("회원 정보 없음. id : {}, password : {}", id, encryptedPassword); + throw new IllegalArgumentException("id 또는 password가 일치하는 회원 정보가 없습니다."); + } + + return riderInfo; + } + + /** + * 라이더 계정을 삭제상태로 만든다. + * @param id 삭제할 라이더 아이디 + * @param password 삭제하기 전 유효성 검사를 위한 비밀번호 + */ + @Transactional + public void deleteAccount(@NonNull String id, @NonNull String password) { + if (isEffective(id, password) == false) { + log.info("회원 삭제를 시도하였지만 실패하였습니다. 원인 : 비밀번호 불일치. id : {}", id); + throw passwordMismatchException; + } + + riderInfoMapper.updateStatusAsDeleted(id); + } + + /** + * 아이디와 비밀번호를 기반으로 유효한 아이디인지, 아이디와 비밀번호가 일치하는지 검사한다. + * @author jun + * @param id 검사할 아이디 + * @param password 검사할 비밀번ㄹ호 + * @return + */ + public boolean isEffective(@NonNull String id, @NonNull String password) { + String encryptedPassword = SHA256Util.encryptSHA256(password); + return riderInfoMapper.isExistAndEffectiveByIdAndPassword(id, encryptedPassword); + } + + /** + * 라이더의 메일 주소를 변경한다. + * @author jun + * @param id 메일을 변경할 아이디 + * @param password 유효성 검사를 위한 비밀번호 + * @param mail 변경할 메일 주소 + */ + @Transactional + public void changeMail(@NonNull String id, @NonNull String password, @NonNull String mail) { + if (isEffective(id, password) == false) { + throw passwordMismatchException; + } + + riderInfoMapper.updateMail(id, mail); + } +} diff --git a/src/main/java/com/delfood/utils/SessionUtil.java b/src/main/java/com/delfood/utils/SessionUtil.java index a689943..02e57a4 100644 --- a/src/main/java/com/delfood/utils/SessionUtil.java +++ b/src/main/java/com/delfood/utils/SessionUtil.java @@ -1,11 +1,13 @@ package com.delfood.utils; import javax.servlet.http.HttpSession; +import lombok.NonNull; public class SessionUtil { private static final String LOGIN_MEMBER_ID = "LOGIN_MEMBER_ID"; private static final String LOGIN_OWNER_ID = "LOGIN_OWNER_ID"; + private static final String LOGIN_RIDER_ID = "LOGIN_RIDER_ID"; // 인스턴스화 방지 private SessionUtil() {} @@ -81,6 +83,24 @@ public static void logoutMember(HttpSession session) { public static void logoutOwner(HttpSession session) { session.removeAttribute(LOGIN_OWNER_ID); } + + /** + * 로그인한 라이더의 id를 세션에 저장한다. + * @author jun + * @param session 사용자의 세션 + * @param id 저장할 라이더 아이디 + */ + public static void setLoginRiderId(HttpSession session, @NonNull String id) { + session.setAttribute(LOGIN_RIDER_ID, id); + } + + public static String getLoginRiderId(HttpSession session) { + return (String) session.getAttribute(LOGIN_RIDER_ID); + } + + public static void logoutRider(HttpSession session) { + session.removeAttribute(LOGIN_RIDER_ID); + } diff --git a/src/main/resources/mybatis/mapper/rider.xml b/src/main/resources/mybatis/mapper/rider.xml new file mode 100644 index 0000000..7b54cf9 --- /dev/null +++ b/src/main/resources/mybatis/mapper/rider.xml @@ -0,0 +1,50 @@ + + + + + + + INSERT INTO RIDER(id, password, name, tel, mail) + VALUES (#{id}, #{password}, #{name}, #{tel}, #{mail}) + + + + + + UPDATE RIDER + SET password = #{password}, + updated_at = NOW() + WHERE id = #{id} + + + + UPDATE RIDER + SET status = 'DELETED', + updated_at = NOW() + WHERE id = #{id} + + + + + + UPDATE RIDER + SET mail = #{mail}, + updated_at = NOW() + WHERE id = #{id} + + \ No newline at end of file From 0ef437ab1109555e6860f1cb913ee51041bb309d Mon Sep 17 00:00:00 2001 From: yyy9942 Date: Tue, 14 Jan 2020 12:38:05 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81=20-?= =?UTF-8?q?=20=EC=96=B4=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0=20-=20=EB=A6=AC=ED=94=8C=EB=9E=99=EC=85=98=EC=9D=84?= =?UTF-8?q?=20=ED=99=9C=EC=9A=A9=ED=95=98=EC=97=AC=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EB=82=B4=EB=B6=80=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/delfood/aop/AuthCheckAspect.java | 85 +++++++++++++++---- src/main/java/com/delfood/aop/LoginCheck.java | 28 ++++++ .../java/com/delfood/aop/OwnerShopCheck.java | 11 ++- .../delfood/controller/CartControllelr.java | 12 +-- .../controller/CouponIssueController.java | 6 +- .../controller/LocationController.java | 6 +- .../delfood/controller/MemberController.java | 14 +-- .../delfood/controller/OrderController.java | 18 ++-- .../delfood/controller/OwnerController.java | 12 +-- .../delfood/controller/RiderController.java | 10 ++- .../delfood/controller/ShopController.java | 18 ++-- .../controller/ShopSearchController.java | 4 +- 12 files changed, 165 insertions(+), 59 deletions(-) create mode 100644 src/main/java/com/delfood/aop/LoginCheck.java diff --git a/src/main/java/com/delfood/aop/AuthCheckAspect.java b/src/main/java/com/delfood/aop/AuthCheckAspect.java index 990280f..3784c68 100644 --- a/src/main/java/com/delfood/aop/AuthCheckAspect.java +++ b/src/main/java/com/delfood/aop/AuthCheckAspect.java @@ -1,10 +1,16 @@ package com.delfood.aop; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import java.util.Objects; import javax.servlet.http.HttpSession; +import org.apache.commons.codec.binary.StringUtils; import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.reflect.MethodSignature; +import org.codehaus.commons.compiler.util.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; @@ -28,9 +34,8 @@ public class AuthCheckAspect { * 로그인되어있지 않을 시 해당 메서드 로직을 중지시킨 후 리턴한다. * @OwnerLoginCheck 해당 어노테이션이 적용된 메서드를 검사한다. * @author jun - * @param pjp - * @return 로그인시 SUCCESS, 비로그인시 NO_LOGIN - * @throws Throwable + * @param jp 조인포인트 + * @throws Throwable 발생 가능한 예외 */ @Before("@annotation(com.delfood.aop.OwnerLoginCheck)") public void ownerLoginCheck(JoinPoint jp) throws Throwable { @@ -50,25 +55,46 @@ public void ownerLoginCheck(JoinPoint jp) throws Throwable { * 세션에서 사장님 로그인을 체크 한다. * 그 후 입력받은 파라미터 값 중 매장 id를 검색하여 해당 매장이 접속한 사장님의 것인지 검사한다. * @author jun - * @param pjp - * @return 비로그인시 NO_LOGIN, 해당 매장의 사장이 아닐 시 UNAUTHORIZED, 권한이 있을 시 SUCCESS - * @throws Throwable + * @param jp 조인포인트 + * @throws Throwable 발새 가능한 예외 */ - @Before("@annotation(com.delfood.aop.OwnerShopCheck)") - public void ownerShopCheck(JoinPoint jp) throws Throwable { + @Before("@annotation(com.delfood.aop.OwnerShopCheck) && @annotation(ownerShopCheck)") + public void ownerShopCheck(JoinPoint jp, OwnerShopCheck ownerShopCheck) throws Throwable { log.debug("AOP - Owner Shop Check Started"); - HttpSession session = ((ServletRequestAttributes)(RequestContextHolder.currentRequestAttributes())).getRequest().getSession(); + HttpSession session = + ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest() + .getSession(); String ownerId = SessionUtil.getLoginOwnerId(session); - - if(ownerId == null) { + + if (ownerId == null) { log.debug("AOP - Owner Shop Check Result - NO_LOGIN"); throw new HttpStatusCodeException(HttpStatus.UNAUTHORIZED, "NO_LOGIN") {}; } Object[] args = jp.getArgs(); - Long shopId = (Long) args[0]; + + // 메소드 파라미터 추출 + MethodSignature signature = (MethodSignature) jp.getSignature(); + Method method = signature.getMethod(); + Parameter[] parameters = method.getParameters(); + + Long shopId = null; + + // 파라미터의 이름과 어노테이션의 value를 비교하여 검사 + for (int i = 0; i < parameters.length; i++) { + String parameterName = parameters[i].getName(); + if (StringUtils.equals(ownerShopCheck.value(), parameterName)) { + shopId = (Long) args[i]; + } + } + + // 어노테이션 value로 설정된 값과 같은 변수 이름이 없을 경우 예외처리 + if (Objects.isNull(shopId)) { + throw new IllegalArgumentException("OwnerShopCheck 어노테이션 설정이 잘못되었습니다. value와 변수 명을 일치시켜주세요."); + } + if (!shopService.isShopOwner(shopId, ownerId)) { log.debug("AOP - Owner Shop Check Result - UNAUTHORIZED"); @@ -79,9 +105,8 @@ public void ownerShopCheck(JoinPoint jp) throws Throwable { /** * 고객의 로그인을 체크한다. * @author jun - * @param pjp - * @return - * @throws Throwable + * @param jp 조인포인튼 + * @throws Throwable 발생 가능한 예외 */ @Before("@annotation(com.delfood.aop.MemberLoginCheck)") public void memberLoginCheck(JoinPoint jp) throws Throwable { @@ -114,4 +139,34 @@ public void riderLoginCheck(JoinPoint jp) throws Throwable { throw new HttpStatusCodeException(HttpStatus.UNAUTHORIZED, "RIDER_NO_LOGIN") {}; } } + + /** + * 공통 로그인 체크 AOP. + * 고객, 사장님, 라이더의 로그인 체크 기능을 하나로 모아두었다. + * @param jp 조인포인트 + * @throws Throwable 발생 가능한 예외 + */ + @Before("@annotation(com.delfood.aop.LoginCheck) && @ annotation(loginCheck)") + public void loginCheck(JoinPoint jp, LoginCheck loginCheck) throws Throwable { + log.debug("AOP - Login Check Started"); + + HttpSession session = + ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest() + .getSession(); + + if (LoginCheck.UserType.MEMBER.equals(loginCheck.type())) { + memberLoginCheck(jp); + } + + if (LoginCheck.UserType.OWNER.equals(loginCheck.type())) { + ownerLoginCheck(jp); + } + + if (LoginCheck.UserType.RIDER.equals(loginCheck.type())) { + riderLoginCheck(jp); + } + + + } + } diff --git a/src/main/java/com/delfood/aop/LoginCheck.java b/src/main/java/com/delfood/aop/LoginCheck.java new file mode 100644 index 0000000..3aa4d32 --- /dev/null +++ b/src/main/java/com/delfood/aop/LoginCheck.java @@ -0,0 +1,28 @@ +package com.delfood.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 로그인의 상태를 확인한다. + * 회원, 사장님, 라이더의 로그인 상태를 확인하여 로그인 되지 않았다면 예외를 발생시킨다. + * @author jun + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface LoginCheck { + + /** + * 로그인을 체크하고 싶은 유저의 로그인 타입. + * 회원(MEMBER), 사장님(OWNER), 라이더(RIDER)중 선택할 수 있다. + * @return + */ + UserType type(); + + public static enum UserType { + MEMBER, OWNER, RIDER + } +} diff --git a/src/main/java/com/delfood/aop/OwnerShopCheck.java b/src/main/java/com/delfood/aop/OwnerShopCheck.java index 0034c2a..1908239 100644 --- a/src/main/java/com/delfood/aop/OwnerShopCheck.java +++ b/src/main/java/com/delfood/aop/OwnerShopCheck.java @@ -1,15 +1,22 @@ package com.delfood.aop; import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * 매장 id가 첫 번째 파라미터로 와야한다. + * 매장 id를 파라미터로 주어야 한다. * 접속한 사장님이 해당 매장의 주인인지 확인한다. * @author yyy99 * */ @Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) public @interface OwnerShopCheck { - + /** + * 해당 변수의 이름. + * @return + */ + String value(); } diff --git a/src/main/java/com/delfood/controller/CartControllelr.java b/src/main/java/com/delfood/controller/CartControllelr.java index c2010f2..69bdc96 100644 --- a/src/main/java/com/delfood/controller/CartControllelr.java +++ b/src/main/java/com/delfood/controller/CartControllelr.java @@ -1,5 +1,7 @@ package com.delfood.controller; +import com.delfood.aop.LoginCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.aop.MemberLoginCheck; import com.delfood.dto.ItemDTO; import com.delfood.service.CartService; @@ -23,31 +25,31 @@ public class CartControllelr { private CartService cartService; @PostMapping("/members/cart/menus") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void addMenu(@RequestBody ItemDTO item, HttpSession session) { cartService.addOrdersItem(item, SessionUtil.getLoginMemberId(session)); } @GetMapping("/members/cart/menus") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public List getCart(HttpSession session) { return cartService.getItems(SessionUtil.getLoginMemberId(session)); } @DeleteMapping("/members/cart/menus") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void clearCart(HttpSession session) { cartService.claer(SessionUtil.getLoginMemberId(session)); } @DeleteMapping("/members/cart/menus/{index}") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void deleteCartMenu(HttpSession session, @PathVariable long index) { cartService.deleteCartMenu(SessionUtil.getLoginMemberId(session), index); } @GetMapping("/members/cart/price") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public CartPriceResponse cartPrice(HttpSession session) { String memberId = SessionUtil.getLoginMemberId(session); return new CartPriceResponse(cartService.getItems(memberId), cartService.allPrice(memberId)); diff --git a/src/main/java/com/delfood/controller/CouponIssueController.java b/src/main/java/com/delfood/controller/CouponIssueController.java index a4cf6f9..d1dcccb 100644 --- a/src/main/java/com/delfood/controller/CouponIssueController.java +++ b/src/main/java/com/delfood/controller/CouponIssueController.java @@ -1,5 +1,7 @@ package com.delfood.controller; +import com.delfood.aop.LoginCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.aop.MemberLoginCheck; import com.delfood.dto.CouponIssueDTO; import com.delfood.service.CouponIssueService; @@ -31,7 +33,7 @@ public class CouponIssueController { */ @PostMapping @ResponseStatus(HttpStatus.CREATED) - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void addCouponIssue(HttpSession session, @RequestBody Long couponId) { couponIssueService.createCouponIssue(SessionUtil.getLoginMemberId(session), couponId); @@ -43,7 +45,7 @@ public void addCouponIssue(HttpSession session, @RequestBody Long couponId) { * @return */ @GetMapping - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public List getCouponIssues(HttpSession session) { return couponIssueService.getCouponIssues(SessionUtil.getLoginMemberId(session)); } diff --git a/src/main/java/com/delfood/controller/LocationController.java b/src/main/java/com/delfood/controller/LocationController.java index 23c0dcb..d9657bb 100644 --- a/src/main/java/com/delfood/controller/LocationController.java +++ b/src/main/java/com/delfood/controller/LocationController.java @@ -43,7 +43,7 @@ public class LocationController { * @return */ @PostMapping("deliveries/{shopId}/possibles") - @OwnerShopCheck + @OwnerShopCheck("shopId") @ResponseStatus(HttpStatus.CREATED) public void addDeliveryLocation( @PathVariable(name = "shopId") Long shopId, @@ -60,7 +60,7 @@ public void addDeliveryLocation( * @return */ @GetMapping("deliveries/{shopId}/possibles") - @OwnerShopCheck + @OwnerShopCheck("shopId") public List getDeliveryLocations( @PathVariable(name = "shopId") Long shopId) { return shopService.getDeliveryLocations(shopId); @@ -76,7 +76,7 @@ public List getDeliveryLocations( * @return */ @DeleteMapping("deliveries/{shopId}/possibles/{deliveryLocationId}") - @OwnerShopCheck + @OwnerShopCheck("shopId") public void deleteDeliveryLocation( @PathVariable(value = "shopId") Long shopId, @PathVariable(value = "deliveryLocationId") Long deliveryLocationId, diff --git a/src/main/java/com/delfood/controller/MemberController.java b/src/main/java/com/delfood/controller/MemberController.java index eb75318..82935ec 100644 --- a/src/main/java/com/delfood/controller/MemberController.java +++ b/src/main/java/com/delfood/controller/MemberController.java @@ -1,5 +1,7 @@ package com.delfood.controller; +import com.delfood.aop.LoginCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.aop.MemberLoginCheck; import com.delfood.dto.MemberDTO; import com.delfood.error.exception.DuplicateIdException; @@ -69,7 +71,7 @@ public class MemberController { * @return MemberDTO */ @GetMapping("myInfo") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public MemberInfoResponse memberInfo(HttpSession session) { String id = SessionUtil.getLoginMemberId(session); MemberDTO memberInfo = memberService.getMemberInfo(id); @@ -149,7 +151,7 @@ public ResponseEntity login(@RequestBody @NonNull MemberLoginRequ * @return 로그인 하지 않았을 시 401코드를 반환하고 result:NO_LOGIN 반환 로그아웃 성공시 200 코드를 반환 */ @GetMapping("logout") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void logout(HttpSession session) { SessionUtil.logoutMember(session); } @@ -162,7 +164,7 @@ public void logout(HttpSession session) { * @return */ @PatchMapping("password") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void updateMemberInfo(HttpSession session, @RequestBody @NotNull UpdateMemberPasswordRequest passwordRequest) { String passwordBeforeChange = passwordRequest.getPasswordBeforeChange(); @@ -183,7 +185,7 @@ public void updateMemberInfo(HttpSession session, * @return */ @DeleteMapping("myInfo") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void deleteMemberInfo(HttpSession session) { String id = SessionUtil.getLoginMemberId(session); memberService.deleteMember(id); @@ -198,7 +200,7 @@ public void deleteMemberInfo(HttpSession session) { * @param session 현재 로그인한 고객의 세션 */ @PatchMapping("address") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public ResponseEntity updateMemberAddress( @RequestBody @NotNull UpdateMemberAddressRequest memberInfo, HttpSession session) { ResponseEntity responseEntity = null; @@ -225,7 +227,7 @@ public ResponseEntity updateMemberAddress( } @PostMapping("token") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public void addToken(HttpSession session, String token) { String memberId = SessionUtil.getLoginMemberId(session); pushService.addMemberToken(memberId, token); diff --git a/src/main/java/com/delfood/controller/OrderController.java b/src/main/java/com/delfood/controller/OrderController.java index 6dd8920..2720bfe 100644 --- a/src/main/java/com/delfood/controller/OrderController.java +++ b/src/main/java/com/delfood/controller/OrderController.java @@ -1,5 +1,7 @@ package com.delfood.controller; +import com.delfood.aop.LoginCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.aop.MemberLoginCheck; import com.delfood.aop.OwnerLoginCheck; import com.delfood.controller.response.OrderResponse; @@ -56,7 +58,7 @@ public class OrderController { * @return */ @GetMapping("price") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public ItemsBillResponse getItemsBill(HttpSession session, @RequestBody List items) { long itemsPrice = orderService.totalPrice(SessionUtil.getLoginMemberId(session), items); @@ -70,7 +72,7 @@ public ItemsBillResponse getItemsBill(HttpSession session, * @return */ @GetMapping("{orderId}/bill") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public OrderBillDTO orderInfo(@PathVariable("orderId") Long orderId) { return orderService.getPreOrderBill(orderId); } @@ -83,7 +85,7 @@ public OrderBillDTO orderInfo(@PathVariable("orderId") Long orderId) { * @return */ @PostMapping - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public OrderResponse order(HttpSession session, @RequestBody OrderRequest request) { if (request.getItems().isEmpty()) { // items가 null일때도 NullpointerException이 발생한다 @@ -129,7 +131,7 @@ public OrderResponse order(HttpSession session, @RequestBody OrderRequest reques * @return */ @GetMapping("bill") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public ItemsBillDTO getBill(HttpSession session, @RequestBody BillRequest billRequest) { if (couponIssueService.isUsed(billRequest.getCouponIssueId())) { log.info("이미 사용한 쿠폰 사용 시도. 요청 발행 쿠폰 아이디 : {}", billRequest.getCouponIssueId()); @@ -147,7 +149,7 @@ public ItemsBillDTO getBill(HttpSession session, @RequestBody BillRequest billRe * @return */ @GetMapping - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public List myOrders(HttpSession session, @Nullable Long lastViewedOrderId) { return orderService.getMemberOrder(SessionUtil.getLoginMemberId(session), lastViewedOrderId); } @@ -160,7 +162,7 @@ public List myOrders(HttpSession session, @Nullable Long lastViewedOrd * @return */ @GetMapping("{orderId}") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public OrderDTO getOrder(HttpSession session, @PathVariable Long orderId) { OrderDTO orderInfo = orderService.getOrder(orderId); if (orderInfo == null) { @@ -186,7 +188,7 @@ public OrderDTO getOrder(HttpSession session, @PathVariable Long orderId) { * @return */ @GetMapping("owner") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public List getRequestedOrders(HttpSession session) { String ownerId = SessionUtil.getLoginOwnerId(session); List shopOrders = orderService.getOwnerOrderRequest(ownerId); @@ -201,7 +203,7 @@ public List getRequestedOrders(HttpSession session) { * @param session 사장님 세션 */ @PatchMapping("{orderId}/approve") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public void orderApprove(@PathVariable(name = "orderId") Long orderId, @RequestBody OrderApproveRequest request, HttpSession session) { diff --git a/src/main/java/com/delfood/controller/OwnerController.java b/src/main/java/com/delfood/controller/OwnerController.java index efe1ceb..fec58da 100644 --- a/src/main/java/com/delfood/controller/OwnerController.java +++ b/src/main/java/com/delfood/controller/OwnerController.java @@ -1,5 +1,7 @@ package com.delfood.controller; +import com.delfood.aop.LoginCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.aop.MemberLoginCheck; import com.delfood.aop.OwnerLoginCheck; import com.delfood.dto.OwnerDTO; @@ -107,7 +109,7 @@ public ResponseEntity login(@RequestBody OwnerLoginRequest l * @return */ @GetMapping("logout") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public void logout(HttpSession session) { SessionUtil.logoutOwner(session); } @@ -120,7 +122,7 @@ public void logout(HttpSession session) { * @return */ @GetMapping("myInfo") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public OwnerInfoResponse ownerInfo(HttpSession session) { String id = SessionUtil.getLoginOwnerId(session); OwnerDTO ownerInfo = ownerService.getOwner(id); @@ -135,7 +137,7 @@ public OwnerInfoResponse ownerInfo(HttpSession session) { * @return */ @PatchMapping - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public void updateOwnerInfo( @RequestBody UpdateOwnerMailAndTelRequest updateRequest, HttpSession session) { @@ -159,7 +161,7 @@ public void updateOwnerInfo( * @return */ @PatchMapping("password") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public void updatePassword( @RequestBody UpdateOwnerPasswordRequest passwordResquest, HttpSession session) { String id = SessionUtil.getLoginOwnerId(session); @@ -173,7 +175,7 @@ public void updatePassword( } @PostMapping("token") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public void addToken(HttpSession session, String token) { String ownerId = SessionUtil.getLoginOwnerId(session); pushService.addOwnerToken(ownerId, token); diff --git a/src/main/java/com/delfood/controller/RiderController.java b/src/main/java/com/delfood/controller/RiderController.java index cdc5c9b..6164206 100644 --- a/src/main/java/com/delfood/controller/RiderController.java +++ b/src/main/java/com/delfood/controller/RiderController.java @@ -1,5 +1,7 @@ package com.delfood.controller; +import com.delfood.aop.LoginCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.aop.RiderLoginCheck; import com.delfood.dto.rider.RiderDTO; import com.delfood.service.rider.RiderInfoService; @@ -99,8 +101,8 @@ public void logout(HttpSession session) { * @param session 사용자의 세션 * @param request 변경전 비밀번호, 변경할 비밀번호 정보 */ - @PatchMapping("update/password") - @RiderLoginCheck + @PatchMapping("password") + @LoginCheck(type = UserType.RIDER) public void updatePassword(HttpSession session, @RequestBody UpdatePasswordRequest request) { String id = SessionUtil.getLoginRiderId(session); riderInfoService.changePassword(id, request.getPasswordBeforechange(), @@ -114,14 +116,14 @@ public void updatePassword(HttpSession session, @RequestBody UpdatePasswordReque * @param password 유효성 검사를 위한 계정 비밀번호 */ @DeleteMapping - @RiderLoginCheck + @LoginCheck(type = UserType.RIDER) public void deleteRiderAccount(HttpSession session, String password) { String id = SessionUtil.getLoginRiderId(session); riderInfoService.deleteAccount(id, password); SessionUtil.logoutRider(session); } - @PatchMapping("update/mail") + @PatchMapping("mail") public void updateMail(HttpSession session, @RequestBody UpdateMailRequest request) { String id = SessionUtil.getLoginRiderId(session); riderInfoService.changeMail(id, request.getPassword(), request.getUpdateMail()); diff --git a/src/main/java/com/delfood/controller/ShopController.java b/src/main/java/com/delfood/controller/ShopController.java index a7bd6f1..aad5125 100644 --- a/src/main/java/com/delfood/controller/ShopController.java +++ b/src/main/java/com/delfood/controller/ShopController.java @@ -15,8 +15,10 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import com.delfood.aop.LoginCheck; import com.delfood.aop.OwnerLoginCheck; import com.delfood.aop.OwnerShopCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.dto.AddressDTO; import com.delfood.dto.DeliveryLocationDTO; import com.delfood.dto.OwnerDTO; @@ -48,7 +50,7 @@ public class ShopController { * @return */ @PostMapping - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public ResponseEntity addShop(HttpSession session, @RequestBody ShopDTO shopInfo) { String ownerId = SessionUtil.getLoginOwnerId(session); @@ -71,7 +73,7 @@ public ResponseEntity addShop(HttpSession session, * @return 페이지에 따른 사장님 매장, 총 매장 개수 */ @GetMapping - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public MyShopsResponse myShops(MyShopsRequest myShopsRequest, HttpSession session) { String id = SessionUtil.getLoginOwnerId(session); @@ -90,7 +92,7 @@ public MyShopsResponse myShops(MyShopsRequest myShopsRequest, * @return */ @PatchMapping("{id}") - @OwnerShopCheck + @OwnerShopCheck("id") public void updateShop(@PathVariable Long id, @RequestBody(required = true) final ShopUpdateDTO updateInfo, HttpSession session) { final ShopUpdateDTO copyData = ShopUpdateDTO.copyWithId(updateInfo, id); @@ -107,7 +109,7 @@ public void updateShop(@PathVariable Long id, * @return */ @PatchMapping("open/{id}") - @OwnerShopCheck + @OwnerShopCheck("id") public ShopDTO openShop( @PathVariable(value = "id", required = true) Long id, HttpSession session) { shopService.openShop(id); @@ -123,7 +125,7 @@ public ShopDTO openShop( * @return 오픈한 매장의 id, 이름 */ @PatchMapping("open/") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public List openAllShops(HttpSession session) { String ownerId = SessionUtil.getLoginOwnerId(session); List openShops = shopService.openAllShops(ownerId); @@ -140,7 +142,7 @@ public List openAllShops(HttpSession session) { * @return */ @PatchMapping("close/{id}") - @OwnerShopCheck + @OwnerShopCheck("id") public ShopDTO closeShop( @PathVariable(value = "id", required = true) Long id, HttpSession session) { shopService.closeShop(id); @@ -156,7 +158,7 @@ public ShopDTO closeShop( * @return 운영 종료를 진행한 매장의 id, 이름 */ @PatchMapping("close/") - @OwnerLoginCheck + @LoginCheck(type = UserType.OWNER) public List closeAllShops(HttpSession session) { String ownerId = SessionUtil.getLoginOwnerId(session); return shopService.closeAllShops(ownerId); @@ -170,7 +172,7 @@ public List closeAllShops(HttpSession session) { * @return */ @GetMapping("{shopId}") - @OwnerShopCheck + @OwnerShopCheck("shopId") public ShopInfoResponse shopInfo( @PathVariable(value = "shopId", required = true) Long shopId, HttpSession session) { ShopDTO shopInfo = shopService.getShop(shopId); diff --git a/src/main/java/com/delfood/controller/ShopSearchController.java b/src/main/java/com/delfood/controller/ShopSearchController.java index 64ab6d7..f76ade3 100644 --- a/src/main/java/com/delfood/controller/ShopSearchController.java +++ b/src/main/java/com/delfood/controller/ShopSearchController.java @@ -1,5 +1,7 @@ package com.delfood.controller; +import com.delfood.aop.LoginCheck; +import com.delfood.aop.LoginCheck.UserType; import com.delfood.aop.MemberLoginCheck; import com.delfood.dto.ShopCategoryDTO; import com.delfood.dto.ShopDTO; @@ -52,7 +54,7 @@ public GetShopCategoriesResponse getShopCategories() { * @return */ @GetMapping("/available/shops") - @MemberLoginCheck + @LoginCheck(type = UserType.MEMBER) public GetShopByCategoryIdAndTownCodeResponse getShopsByCategoryIdAndTownCode( @RequestParam(required = true) Long categoryId, HttpSession session) { String memberId = SessionUtil.getLoginMemberId(session);