This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
[#67] 라이더 회원 정보 서비스 #68
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +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; | ||
|
@@ -27,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 { | ||
|
@@ -49,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"); | ||
|
@@ -78,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 { | ||
|
@@ -93,4 +119,54 @@ 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") {}; | ||
} | ||
} | ||
|
||
/** | ||
* 공통 로그인 체크 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())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. switch-case문을 사용하면 더 깔끔할것 같네요~ |
||
memberLoginCheck(jp); | ||
} | ||
|
||
if (LoginCheck.UserType.OWNER.equals(loginCheck.type())) { | ||
ownerLoginCheck(jp); | ||
} | ||
|
||
if (LoginCheck.UserType.RIDER.equals(loginCheck.type())) { | ||
riderLoginCheck(jp); | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/** | ||
* <b>매장 id가 첫 번째 파라미터로 와야한다.</b> | ||
* <b>매장 id를 파라미터로 주어야 한다.</b> | ||
* 접속한 사장님이 해당 매장의 주인인지 확인한다. | ||
* @author yyy99 | ||
* | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface OwnerShopCheck { | ||
|
||
/** | ||
* 해당 변수의 이름. | ||
* @return | ||
*/ | ||
String value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.delfood.aop; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
public @interface RiderLoginCheck { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만약
@LoginCheck
어노테이션에 userLevel 같은 옵션을 하나 만들어두면 어노테이션을 하나만 사용할 수 있지 않을까요?