-
Notifications
You must be signed in to change notification settings - Fork 1
feat: principal 감사와 배너 poster URL 지원 #687
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
9 changes: 9 additions & 0 deletions
9
bottlenote-mono/src/main/java/app/bottlenote/common/constant/AuditPrincipalType.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,9 @@ | ||
| package app.bottlenote.common.constant; | ||
|
|
||
| public enum AuditPrincipalType { | ||
| USER, | ||
| ADMIN, | ||
| AGENT, | ||
| SYSTEM, | ||
| ANONYMOUS | ||
| } |
28 changes: 28 additions & 0 deletions
28
bottlenote-mono/src/main/java/app/bottlenote/common/domain/AuditPrincipal.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,28 @@ | ||
| package app.bottlenote.common.domain; | ||
|
|
||
| import app.bottlenote.common.constant.AuditPrincipalType; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Embeddable; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.Enumerated; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Embeddable | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class AuditPrincipal { | ||
|
|
||
| @Column(name = "principal_id") | ||
| private Long id; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "principal_type", length = 30) | ||
| private AuditPrincipalType type; | ||
|
|
||
| @Column(name = "principal_email") | ||
| private String email; | ||
| } |
24 changes: 2 additions & 22 deletions
24
bottlenote-mono/src/main/java/app/bottlenote/common/domain/BaseEntity.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 |
|---|---|---|
| @@ -1,27 +1,7 @@ | ||
| package app.bottlenote.common.domain; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.EntityListeners; | ||
| import jakarta.persistence.MappedSuperclass; | ||
| import lombok.Getter; | ||
| import org.hibernate.annotations.Comment; | ||
| import org.springframework.data.annotation.CreatedBy; | ||
| import org.springframework.data.annotation.LastModifiedBy; | ||
| import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
|
||
| /** 생성자 , 수정자 정보가 존재하는 entity의 경우 사용 */ | ||
| @Getter | ||
| /** 생성자와 수정자 정보가 존재하는 기존 entity의 호환용 공통 클래스 */ | ||
| @MappedSuperclass | ||
| @EntityListeners(AuditingEntityListener.class) | ||
| public class BaseEntity extends BaseTimeEntity { | ||
|
|
||
| @Comment("최초 생성자") | ||
| @CreatedBy | ||
| @Column(updatable = false, name = "create_by") | ||
| private String createBy; | ||
|
|
||
| @Comment("최종 수정자") | ||
| @LastModifiedBy | ||
| @Column(name = "last_modify_by") | ||
| private String lastModifyBy; | ||
| } | ||
| public class BaseEntity extends BaseTimeEntity {} |
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
31 changes: 19 additions & 12 deletions
31
bottlenote-mono/src/main/java/app/bottlenote/global/config/jpa/AuditorAwareImpl.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 |
|---|---|---|
| @@ -1,26 +1,33 @@ | ||
| package app.bottlenote.global.config.jpa; | ||
|
|
||
| import app.bottlenote.common.constant.AuditPrincipalType; | ||
| import app.bottlenote.common.domain.AuditPrincipal; | ||
| import app.bottlenote.global.security.CustomAdminUserContext; | ||
| import app.bottlenote.global.security.CustomUserContext; | ||
| import java.util.Optional; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.data.domain.AuditorAware; | ||
| import org.springframework.security.core.Authentication; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| import org.springframework.security.core.userdetails.UserDetails; | ||
|
|
||
| @Slf4j | ||
| public class AuditorAwareImpl implements AuditorAware<String> { | ||
| public class AuditorAwareImpl implements AuditorAware<AuditPrincipal> { | ||
|
|
||
| @Override | ||
| public Optional<String> getCurrentAuditor() { | ||
|
|
||
| public Optional<AuditPrincipal> getCurrentAuditor() { | ||
| Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
| if (authentication == null || !authentication.isAuthenticated()) { | ||
| return Optional.empty(); | ||
|
Contributor
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.
|
||
| } | ||
|
|
||
| if (authentication != null && authentication.isAuthenticated()) { | ||
| if ("[ROLE_ANONYMOUS]".equals(authentication.getAuthorities().toString())) { | ||
| return Optional.of("anonymousUser"); | ||
| } | ||
| UserDetails userDetails = (UserDetails) authentication.getPrincipal(); | ||
| return Optional.ofNullable(userDetails.getUsername()); | ||
| Object principal = authentication.getPrincipal(); | ||
| if (principal instanceof CustomAdminUserContext admin) { | ||
| return Optional.of( | ||
| new AuditPrincipal(admin.getId(), AuditPrincipalType.ADMIN, admin.getUsername())); | ||
| } | ||
| if (principal instanceof CustomUserContext user) { | ||
| AuditPrincipalType type = | ||
| user.getId().equals(-4L) ? AuditPrincipalType.ANONYMOUS : AuditPrincipalType.USER; | ||
| Long id = type == AuditPrincipalType.ANONYMOUS ? null : user.getId(); | ||
| return Optional.of(new AuditPrincipal(id, type, user.getUsername())); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
Oops, something went wrong.
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.
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.
배포 호환성 확인이 필요합니다. V5가
last_modify_by를 즉시 rename하지만 표준 backend release는 Product/Admin 이미지만 갱신하고 batch 이미지는 함께 배포하지 않습니다. 따라서 migration 적용 후 기존 batch가 구 컬럼으로 실행되어 실패하며, 기본 RollingUpdate 중인 기존 Product/Admin pod도 같은 영향을 받을 수 있습니다. V5에서는 신규 principal 컬럼을 추가하되 구 컬럼을 유지하고, Product/Admin/Batch 전환 후 후속 migration에서 구 컬럼을 제거하는 expand-contract 방식을 권장합니다.