Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(host) : 호스트 권한 검증 aop #250

Merged
merged 4 commits into from
Feb 1, 2023
Merged

Conversation

ImNM
Copy link
Member

@ImNM ImNM commented Jan 31, 2023

개요

작업사항

  • 호스트의 권한을 검증할 수 있는 aop 를 개발 했습니다.
  • 중복된소스를 줄이고, 명시적으로 선언하는게 눈에도 더 잘보일것 같아서 만들었습니다.

제일 중요한 부분은 아래 부분입니다,

// HostQualification
    MASTER((userId, host) -> host.validateMasterHostUser(userId)),
    MANAGER((userId, host) -> host.validateSuperHostUser(userId)),
    GUEST((userId, host) -> host.validateActiveHostUser(userId));

// biConsumer로 실행시킬 함수 선언
private final BiConsumer<Long, Host> consumer;

사용방법

  • before
    @Transactional
    public EventResponse execute(Long eventId, UpdateEventDetailRequest updateEventDetailRequest) {
        final User user = userUtils.getCurrentUser();
        final Long userId = user.getId();
        final Event event = eventAdaptor.findById(eventId);
        hostService.validateSuperHostUser(event.getHostId(), userId);
  • after
@HostRolesAllowed("MANAGER")
public EventResponse execute(Long eventId, UpdateEventDetailRequest updateEventDetailRequest) {

위 세가지 값을 명시적으로 적어주시면 됩니다.

  • 트랜잭션 내부에서 캐시하는 효과를 볼수 있도록
  • HostRoleTransaction 통해서 aop 안에 한 뎁스 더 들어가서 repository에서 값을 불러왔습니다.

변경로직

  • 내용을 적어주세요.

@ImNM ImNM requested a review from sanbonai06 as a code owner January 31, 2023 15:07
@ImNM ImNM self-assigned this Jan 31, 2023
@ImNM ImNM changed the title feature(host) : 호스트 권한 검증 aop feat(host) : 호스트 권한 검증 aop Jan 31, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 263 Code Smells

16.3% 16.3% Coverage
0.0% 0.0% Duplication

Copy link
Member

@gengminy gengminy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AOP 구현 잘봤습니다

Comment on lines +50 to +58
public Long getEventId(String[] parameterNames, Object[] args, String paramName) {
for (int i = 0; i < parameterNames.length; i++) {
if (parameterNames[i].equals(paramName)) {
// 롱타입이라 가정. 안되면 classCastException 터트림
return (Long) args[i];
}
}
throw new IllegalArgumentException();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메소드 파라미터에 eventId 가 없는 경우에도 검증이 되나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네넹 IllegalArgumentException 입니당

Comment on lines +25 to +33
@Transactional(readOnly = true)
public Object proceed(Long eventId, HostQualification role, final ProceedingJoinPoint joinPoint)
throws Throwable {
Long currentUserId = userUtils.getCurrentUserId();
Event event = eventAdaptor.findById(eventId);
Host host = hostAdaptor.findById(event.getHostId());
role.validQualification(currentUserId, host);
return joinPoint.proceed();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요기서 되는건가

Copy link
Member

@kim-wonjin kim-wonjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘써먹겠습니다 굿굿😸

Copy link
Member

@sanbonai06 sanbonai06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋네요 적용해서 리팩 하겠습니다

@ImNM ImNM merged commit 633adf2 into dev Feb 1, 2023
@ImNM ImNM deleted the feature/249-host-validation-aop branch February 1, 2023 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🚀 [feature] 호스트 검증 aop
4 participants