-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 관리자 role 추가 #192
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
Merged
feat: 관리자 role 추가 #192
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c58f732
feat: Role에 ADMIN 추가 및 Spring Security 권한 처리 추가
Gyuhyeok99 9d3f5e7
feat: 사용자 권한 처리 및 ADMIN 경로 보호 추가
Gyuhyeok99 5e5fda9
refactor: Security 필터 체인 실행 순서 조정
Gyuhyeok99 ed584a3
feat: 인증 안된 사용자 및 권한 없는 사용자 예외 처리 추가
Gyuhyeok99 1ac57ff
test: ExceptionHandlerFilter 관련 테스트 코드 추가
Gyuhyeok99 5ced9e3
chore: ADMIN Role 추가 마이그레이션 파일 추가
Gyuhyeok99 f698ada
fix: JWT 인증 시 권한 정보 누락 문제 해결
Gyuhyeok99 dbca920
fix: 만료된 토큰에 대한 인증 처리 시 예외 발생 문제 해결
Gyuhyeok99 df11c1d
refactor: customException를 활용하여 코드 간결화
Gyuhyeok99 a1b98d1
refactor: 불필요한 중복 코드 제거
Gyuhyeok99 b0b78cc
refactor: 삼항 연산자로 예외 처리 코드 간결화
Gyuhyeok99 cf2c2d6
style: 형 변환 시 공백 추가
Gyuhyeok99 b04de5f
refactor: Role enum을 순수 도메인 객체로 변경
Gyuhyeok99 719762e
test: 테스트 코드 추가
Gyuhyeok99 c7bc0fd
refactor: 매퍼 security.userdetails 패키지로 이동
Gyuhyeok99 34970ce
test: SiteUserDetailsTest 추가 및 권한 테스트 이동
Gyuhyeok99 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
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
18 changes: 18 additions & 0 deletions
18
...main/java/com/example/solidconnection/custom/security/userdetails/SecurityRoleMapper.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,18 @@ | ||
| package com.example.solidconnection.custom.security.userdetails; | ||
|
|
||
| import com.example.solidconnection.type.Role; | ||
| import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class SecurityRoleMapper { | ||
|
|
||
| private static final String ROLE_PREFIX = "ROLE_"; | ||
|
|
||
| private SecurityRoleMapper() { | ||
| } | ||
|
|
||
| public static List<SimpleGrantedAuthority> mapRoleToAuthorities(Role role) { | ||
| return List.of(new SimpleGrantedAuthority(ROLE_PREFIX + role.name())); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| package com.example.solidconnection.type; | ||
|
|
||
| public enum Role { | ||
|
|
||
| ADMIN, | ||
| MENTOR, | ||
| MENTEE | ||
| MENTEE; | ||
| } |
2 changes: 2 additions & 0 deletions
2
src/main/resources/db/migration/V6__add_admin_to_role_enum.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,2 @@ | ||
| ALTER TABLE site_user | ||
| modify ROLE enum ('MENTEE', 'MENTOR', 'ADMIN') NOT NULL; |
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
51 changes: 51 additions & 0 deletions
51
...est/java/com/example/solidconnection/custom/security/userdetails/SiteUserDetailsTest.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,51 @@ | ||
| package com.example.solidconnection.custom.security.userdetails; | ||
|
|
||
| import com.example.solidconnection.siteuser.domain.SiteUser; | ||
| import com.example.solidconnection.siteuser.repository.SiteUserRepository; | ||
| import com.example.solidconnection.support.TestContainerSpringBootTest; | ||
| import com.example.solidconnection.type.Gender; | ||
| import com.example.solidconnection.type.PreparationStatus; | ||
| import com.example.solidconnection.type.Role; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.security.core.GrantedAuthority; | ||
|
|
||
| import java.util.Collection; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| @DisplayName("사용자 인증 정보 테스트") | ||
| @TestContainerSpringBootTest | ||
| class SiteUserDetailsTest { | ||
|
|
||
| @Autowired | ||
| private SiteUserRepository siteUserRepository; | ||
|
|
||
| @Test | ||
| void 사용자_권한을_정상적으로_반환한다() { | ||
| // given | ||
| SiteUser siteUser = siteUserRepository.save(createSiteUser()); | ||
| SiteUserDetails siteUserDetails = new SiteUserDetails(siteUser); | ||
|
|
||
| // when | ||
| Collection<? extends GrantedAuthority> authorities = siteUserDetails.getAuthorities(); | ||
|
|
||
| // then | ||
| assertThat(authorities) | ||
| .extracting("authority") | ||
| .containsExactly("ROLE_" + siteUser.getRole().name()); | ||
| } | ||
|
|
||
| private SiteUser createSiteUser() { | ||
| return new SiteUser( | ||
| "[email protected]", | ||
| "nickname", | ||
| "profileImageUrl", | ||
| "1999-01-01", | ||
| PreparationStatus.CONSIDERING, | ||
| Role.MENTEE, | ||
| Gender.MALE | ||
| ); | ||
| } | ||
| } |
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.
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.
다시 보니
customCommence(),generalCommence()이 함수들 접근제한자도 private 이 되는게 좋겠네요🥹