-
Notifications
You must be signed in to change notification settings - Fork 1
[Release] 수정 사항 반영 후 운영 서버 릴리즈 #169
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
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
33b16b8
[Refactor] #158 관리자용 리프레시토큰 발급 메서드 생성
JJUYAAA 879fe81
[Feat] #158 관리자용 로그인 응답 DTO 생성
JJUYAAA 91c6b73
[Feat] #158 관리자용 토큰 발급 서비스 코드 생성
JJUYAAA d6ca881
[Refactor] #158 관리자용 토큰 발급 관련 환경변수 추가
JJUYAAA b719b48
[Refactor] #158 관리자용 토큰 발급 서비스 - AuthServiceFacade에 추가
JJUYAAA 6415657
[Refactor] #158 Redis에 관리자용 토큰 저장하는 로직 추가
JJUYAAA 848cc4c
[Refactor] #158 관리자용 토큰 발급 API - Controller에 추가
JJUYAAA 243f444
[Test] #158 application-test.yml에 관리자용 토큰 발급 관련 환경변수 추가
JJUYAAA cb8d305
[Test] #158 TestInitializer에 특정한 ID의 유저 생성하는 메서드 추가
JJUYAAA dca8923
[Test] #158 관리자용 토큰 발급 서비스 테스트코드 작성
JJUYAAA ca4909e
[Test] #158 AuthControllerTest에 관리자용 토큰 발급 API 테스트 추가
JJUYAAA ecf97e3
[Test] #158 AuthControllerTest 보강 - 401 반환 테스트
JJUYAAA 274e51a
[Refactor] #158 Role-ADMIN 추가
JJUYAAA 284159f
[Refactor] #158 관리자용 refreshToken 생성 메서드 삭제, 관리자용 accessToken 생성 메서드 추가
JJUYAAA 51f4224
[Refactor] #158 관리자용 로그인 ResponseDTO 수정
JJUYAAA 53d27a8
[Refactor] #158 관리자용 로그인 서비스 코드 수정 - refreshToken 제거
JJUYAAA 7f4d66a
[Refactor] #158 RedisRefreshTokenRepository 수정 - refreshToken 제거
JJUYAAA a8f2b1c
[Refactor] #158 AdminAllowlistFilter 추가
JJUYAAA 40de914
[Test] #158 AdminLoginServiceImplTest 수정
JJUYAAA 3b12825
[Test] #158 AuthControllerTest 수정
JJUYAAA 64b4e4b
[Refactor] #158 Image 업로드 API - PreAuthorize 수정
JJUYAAA c25b0f4
[Refactor] #158 ExceptionTranslationFilter 뒤에 AdminAllowListFilter를 추가
JJUYAAA f8ef5cb
Merge pull request #161 from FindYou-Kuit/refactor/#158-admin-login
JJUYAAA 7dc1e6c
[Fix] #166 breed 필드의 길이를 20 -> 50으로 증가
ksg1227 10d7475
[Fix] #166 품종 필드 칼럼 길이 수정 스크립트 작성
ksg1227 0d3a81b
Merge pull request #167 from FindYou-Kuit/fix/#166-extend-breed-length
ksg1227 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 hidden or 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/kuit/findyou/domain/auth/dto/response/AdminLoginResponse.java
This file contains hidden or 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.kuit.findyou.domain.auth.dto.response; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @Schema(description = "관리자 로그인 응답 DTO") | ||
| public record AdminLoginResponse( | ||
| @Schema(description = "관리자 유저 식별자") | ||
| Long userId, | ||
| @Schema(description = "엑세스 토큰") | ||
| String accessToken | ||
| ) { | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
src/main/java/com/kuit/findyou/domain/auth/service/AdminLoginService.java
This file contains hidden or 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,7 @@ | ||
| package com.kuit.findyou.domain.auth.service; | ||
|
|
||
| import com.kuit.findyou.domain.auth.dto.response.AdminLoginResponse; | ||
|
|
||
| public interface AdminLoginService { | ||
| AdminLoginResponse adminLogin(); | ||
| } |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/kuit/findyou/domain/auth/service/AdminLoginServiceImpl.java
This file contains hidden or 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,36 @@ | ||
| package com.kuit.findyou.domain.auth.service; | ||
|
|
||
| import com.kuit.findyou.domain.auth.dto.response.AdminLoginResponse; | ||
| import com.kuit.findyou.domain.user.model.Role; | ||
| import com.kuit.findyou.domain.user.model.User; | ||
| import com.kuit.findyou.domain.user.repository.UserRepository; | ||
| import com.kuit.findyou.global.common.exception.CustomException; | ||
| import com.kuit.findyou.global.jwt.util.JwtUtil; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import static com.kuit.findyou.global.common.response.status.BaseExceptionResponseStatus.USER_NOT_FOUND; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class AdminLoginServiceImpl implements AdminLoginService{ | ||
| private final JwtUtil jwtUtil; | ||
| private final UserRepository userRepository; | ||
|
|
||
| @Value("${admin.admin-user-id}") | ||
| private Long adminUserId; | ||
|
|
||
| @Value("${admin.access-ttl-ms}") | ||
| private Long adminAccessTtlMs; | ||
|
|
||
| @Override | ||
| public AdminLoginResponse adminLogin() { | ||
| User user = userRepository.findById(adminUserId) | ||
| .orElseThrow(() -> new CustomException(USER_NOT_FOUND)); | ||
|
|
||
| String accessToken = jwtUtil.createAccessJwt(user.getId(), Role.ADMIN, adminAccessTtlMs); | ||
|
|
||
| return new AdminLoginResponse(user.getId(), accessToken); | ||
ksg1227 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
src/main/java/com/kuit/findyou/global/jwt/filter/AdminAllowlistFilter.java
This file contains hidden or 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,70 @@ | ||
| package com.kuit.findyou.global.jwt.filter; | ||
|
|
||
| import jakarta.servlet.FilterChain; | ||
| import jakarta.servlet.ServletException; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpMethod; | ||
| import org.springframework.security.access.AccessDeniedException; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.AntPathMatcher; | ||
| import org.springframework.web.filter.OncePerRequestFilter; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class AdminAllowlistFilter extends OncePerRequestFilter { | ||
|
|
||
| private final AntPathMatcher matcher = new AntPathMatcher(); | ||
|
|
||
| // ADMIN에게 허용되는 API | ||
| private static final List<Allow> ADMIN_ALLOWLIST = List.of( | ||
| new Allow(HttpMethod.GET.name(), "/api/v2/reports/protecting-reports/random-s3"), | ||
| new Allow(HttpMethod.GET.name(), "/api/v2/reports/missing-reports/random-s3"), | ||
| new Allow(HttpMethod.POST.name(), "/api/v2/images/upload") | ||
| ); | ||
|
|
||
| @Override | ||
| protected void doFilterInternal( | ||
| HttpServletRequest request, | ||
| HttpServletResponse response, | ||
| FilterChain filterChain | ||
| ) throws ServletException, IOException { | ||
|
|
||
| Authentication auth = SecurityContextHolder.getContext().getAuthentication(); | ||
|
|
||
| if (auth != null && auth.isAuthenticated()) { | ||
| boolean isAdmin = auth.getAuthorities().stream() | ||
| .anyMatch(a -> a.getAuthority().equals("ROLE_ADMIN")); | ||
|
|
||
| if (isAdmin) { | ||
| String method = request.getMethod(); | ||
| String path = request.getRequestURI(); | ||
|
|
||
| boolean allowed = ADMIN_ALLOWLIST.stream() | ||
| .anyMatch(a -> a.method.equals(method) && matcher.match(a.pathPattern, path)); | ||
|
|
||
| if (!allowed) { | ||
| throw new AccessDeniedException("ADMIN은 허용된 API만 호출할 수 있습니다."); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| filterChain.doFilter(request, response); | ||
| } | ||
|
|
||
| private static class Allow { | ||
| final String method; | ||
| final String pathPattern; | ||
|
|
||
| private Allow(String method, String pathPattern) { | ||
| this.method = method; | ||
| this.pathPattern = pathPattern; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
4 changes: 4 additions & 0 deletions
4
src/main/resources/db/migration/V9__alter_reports_breed_column.sql
This file contains hidden or 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,4 @@ | ||
| -- V9__alter_reports_breed_column.sql | ||
| -- reports 테이블의 breed 컬럼 길이를 20에서 50으로 변경 | ||
|
|
||
| ALTER TABLE reports MODIFY COLUMN breed VARCHAR(50) NOT NULL; |
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.
Uh oh!
There was an error while loading. Please reload this page.