-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Recipe-Project/feature/add_aop
Feature/add aop
- Loading branch information
Showing
12 changed files
with
196 additions
and
311 deletions.
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/recipe/app/src/common/aop/LoginCheck.java
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,12 @@ | ||
package com.recipe.app.src.common.aop; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
public @interface LoginCheck { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/recipe/app/src/common/aop/LoginCheckAspect.java
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,40 @@ | ||
package com.recipe.app.src.common.aop; | ||
|
||
import com.recipe.app.src.user.domain.SecurityUser; | ||
import com.recipe.app.src.user.domain.User; | ||
import com.recipe.app.src.user.exception.UserTokenNotExistException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Arrays; | ||
|
||
@Component | ||
@Slf4j | ||
@Aspect | ||
public class LoginCheckAspect { | ||
|
||
@Around("@annotation(com.recipe.app.src.common.aop.LoginCheck)") | ||
public Object loginCheck(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { | ||
|
||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
if (authentication == null) { | ||
throw new UserTokenNotExistException(); | ||
} | ||
|
||
User user = ((SecurityUser) authentication.getPrincipal()).getUser(); | ||
|
||
log.info("Login User Id : " + user.getUserId()); | ||
|
||
Object[] args = new Object[]{user}; | ||
|
||
System.out.println(Arrays.toString(args)); | ||
|
||
return proceedingJoinPoint.proceed(args); | ||
} | ||
} |
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.