Skip to content

Commit

Permalink
[fix] resourceId 문제 해결 (#425)
Browse files Browse the repository at this point in the history
* fix: 클래스명 변경 및 @around 애노테이션 제거

* style: 코드 정리
  • Loading branch information
yonghwankim-dev authored Aug 10, 2024
1 parent 4ffd6c9 commit d6123e5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.stereotype.Component;

import codesquad.fineants.global.common.authorized.service.AuthorizedService;
import codesquad.fineants.global.common.resource.ResourceIdAspect;
import codesquad.fineants.global.common.resource.ResourceIdParser;
import codesquad.fineants.global.errors.errorcode.MemberErrorCode;
import codesquad.fineants.global.errors.exception.FineAntsException;
import codesquad.fineants.global.errors.exception.ForBiddenException;
Expand All @@ -30,7 +30,7 @@ public class AuthorizationAspect {

private final ApplicationContext applicationContext;

private final ResourceIdAspect resourceIdAspect;
private final ResourceIdParser resourceIdParser;

@Before(value = "@annotation(authorized) && args(..)")
public void validatePortfolioAuthorization(JoinPoint joinPoint, Authorized authorized) {
Expand All @@ -51,7 +51,7 @@ public void validatePortfolioAuthorization(JoinPoint joinPoint, Authorized autho

private List<Long> getResourceId(ProceedingJoinPoint joinPoint) {
try {
return resourceIdAspect.around(joinPoint);
return resourceIdParser.getResourceList(joinPoint);
} catch (Throwable e) {
log.error(e.getMessage());
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
import java.util.List;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Aspect
@Component
@Slf4j
public class ResourceIdAspect {
@Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public List<Long> around(ProceedingJoinPoint joinPoint) throws Throwable {
public class ResourceIdParser {
public List<Long> getResourceList(ProceedingJoinPoint joinPoint) {
MethodSignature methodSignature = (MethodSignature)joinPoint.getSignature();
Annotation[][] parameterAnnotations = methodSignature.getMethod().getParameterAnnotations();
Object[] args = joinPoint.getArgs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException {
log.error("requestUrl : {}", request.getRequestURL());
log.error("AuthenticationEntryPoint : {}", exception.getMessage());
exception.printStackTrace(System.out);
MemberErrorCode errorCode = MemberErrorCode.UNAUTHORIZED_MEMBER;
ApiResponse<String> body = ApiResponse.error(errorCode);
response.setStatus(errorCode.getHttpStatus().value());
Expand Down

0 comments on commit d6123e5

Please sign in to comment.