-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/63 봉사자 조회, 상세 조회, 검증 #95
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
Changes from all commits
b941d08
9fa8b39
72a0f3e
05cb0ff
df033e2
b3bfdbb
72b2cfa
7130dbc
9a0e2f6
c737e85
793e279
2c89fe0
9510c4b
8b9c593
849b0d0
499668d
90dd88e
aa4694c
4d66f16
5402867
2734cdc
542dc36
5baca67
84d7b87
bde83d4
2919f35
a3d5cec
943ce64
25d0cd3
5fac32a
b1da776
d2af443
a7c176c
931a6fe
81c2373
37e7922
8689d38
c1370be
b653e38
cb637fa
20b4fb3
fb54ab3
339de3e
e79d56b
fd3c5ab
d3f37a4
7036367
daac8ef
be87e25
7009cf1
29a621b
20ca50d
6f425ef
bef0ddb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,30 @@ | ||
| package com.somemore.auth.jwt.domain; | ||
|
|
||
| public enum UserRole { | ||
| VOLUNTEER, | ||
| CENTER, | ||
| ADMIN | ||
| import com.somemore.auth.jwt.exception.JwtException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.core.GrantedAuthority; | ||
|
|
||
| import static com.somemore.auth.jwt.exception.JwtErrorType.UNKNOWN_ERROR; | ||
|
|
||
| @RequiredArgsConstructor | ||
| public enum UserRole implements GrantedAuthority { | ||
| VOLUNTEER("ROLE_VOLUNTEER"), | ||
| CENTER("ROLE_CENTER"), | ||
| ADMIN("ROLE_ADMIN"); | ||
|
|
||
| private final String authority; | ||
|
|
||
| @Override | ||
| public String getAuthority() { | ||
| return this.authority; | ||
| } | ||
|
|
||
| public static UserRole from(String role) { | ||
| for (UserRole userRole : values()) { | ||
| if (userRole.name().equals(role)) { | ||
| return userRole; | ||
| } | ||
| } | ||
| throw new JwtException(UNKNOWN_ERROR); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,6 @@ | |
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.security.core.Authentication; | ||
|
|
@@ -19,6 +17,9 @@ | |
| import org.springframework.stereotype.Component; | ||
| import org.springframework.web.filter.OncePerRequestFilter; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Slf4j | ||
| @Component | ||
|
|
@@ -34,7 +35,7 @@ protected boolean shouldNotFilter(HttpServletRequest request) { | |
|
|
||
| @Override | ||
| protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, | ||
| FilterChain filterChain) throws ServletException, IOException { | ||
| FilterChain filterChain) throws ServletException, IOException { | ||
| EncodedToken accessToken = getAccessToken(request); | ||
| jwtUseCase.processAccessToken(accessToken, response); | ||
|
|
||
|
|
@@ -47,24 +48,24 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse | |
|
|
||
| private EncodedToken getAccessToken(HttpServletRequest request) { | ||
| String accessToken = request.getHeader("Authorization"); | ||
| if (!accessToken.startsWith("Bearer ")) { | ||
| throw new JwtException(JwtErrorType.MISSING_TOKEN); | ||
| } | ||
|
|
||
| accessToken = accessToken.substring(7); | ||
| String tokenPrefix = "Bearer "; | ||
| if (accessToken.startsWith(tokenPrefix)) { | ||
| return new EncodedToken(accessToken.substring(tokenPrefix.length())); | ||
| } | ||
|
|
||
| return new EncodedToken(accessToken); | ||
| throw new JwtException(JwtErrorType.MISSING_TOKEN); | ||
| } | ||
|
Collaborator
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. 얼리 리턴 굳입니당
Collaborator
Author
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. 감사합니다 ㅎㅎ |
||
|
|
||
| private JwtAuthenticationToken createAuthenticationToken(Claims claims, | ||
| EncodedToken accessToken) { | ||
| EncodedToken accessToken) { | ||
| String userId = claims.get("id", String.class); | ||
| UserRole role = UserRole.valueOf(claims.get("role", String.class)); | ||
| String role = claims.get("role", String.class); | ||
|
|
||
| return new JwtAuthenticationToken( | ||
| userId, | ||
| accessToken, | ||
| List.of(new SimpleGrantedAuthority(role.name())) | ||
| List.of(new SimpleGrantedAuthority(role)) | ||
| ); | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.somemore.facade.validator; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public interface VolunteerDetailAccessValidator { | ||
|
|
||
| void validateByCenterId(UUID centerId, UUID targetVolunteerId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.somemore.facade.validator; | ||
|
|
||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.recruitboard.usecase.query.RecruitBoardQueryUseCase; | ||
| import com.somemore.volunteerapply.usecase.VolunteerApplyQueryUseCase; | ||
|
Collaborator
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. 대문자 수정은 왜 하게 되신건가용?
Collaborator
Author
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. 아하 소나가 짚어주기도 했고, 패키지는 소문자로 이뤄져야하는데 제가 실수 했습니다 |
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.UNAUTHORIZED_VOLUNTEER_DETAIL; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class VolunteerDetailAccessValidatorImpl implements VolunteerDetailAccessValidator { | ||
|
|
||
| private final RecruitBoardQueryUseCase recruitBoardQueryUseCase; | ||
| private final VolunteerApplyQueryUseCase volunteerApplyQueryUseCase; | ||
|
|
||
| /** | ||
| * 기관 ID를 기반으로 완료되지 않은 모집글들의 ID를 조회하고, | ||
| * 해당 모집글들에 연관된 봉사자들의 ID 목록에 타겟 봉사자 ID가 포함되어 있는지 검증. | ||
| */ | ||
| public void validateByCenterId(UUID centerId, UUID targetVolunteerId) { | ||
| List<Long> notCompletedIdsByCenterIds = recruitBoardQueryUseCase.getNotCompletedIdsByCenterIds(centerId); | ||
|
|
||
| List<UUID> volunteerIdsByRecruitIds = volunteerApplyQueryUseCase.getVolunteerIdsByRecruitIds(notCompletedIdsByCenterIds); | ||
|
|
||
| if (volunteerIdsByRecruitIds.stream() | ||
| .anyMatch(volunteerId -> volunteerId.equals(targetVolunteerId))) { | ||
| return; | ||
| } | ||
|
|
||
| throw new BadRequestException(UNAUTHORIZED_VOLUNTEER_DETAIL); | ||
| } | ||
|
Collaborator
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. 조인없이 객체로 잘 풀어내신 것 같아요.
Collaborator
Author
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. 감사합니다! |
||
| } | ||
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.
깔끔하네요
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.
네, 컨트롤러 테스트 만들면서 겸사겸사 수정해봤습니다~