-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ditor-aware Feat/#159 `WorkspaceMember`의 `id`를 기록하는 `WebRequestAuditorAware` 구현
- Loading branch information
Showing
20 changed files
with
174 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/com/tissue/api/common/entity/WorkspaceBaseEntity.java
This file contains 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,23 @@ | ||
package com.tissue.api.common.entity; | ||
|
||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.LastModifiedBy; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class WorkspaceBaseEntity extends BaseDateEntity { | ||
|
||
@CreatedBy | ||
@Column(updatable = false) | ||
private Long createdByMember; | ||
|
||
@LastModifiedBy | ||
private Long lastModifiedByWorkspaceMember; | ||
} |
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/com/tissue/api/common/entity/WorkspaceContextBaseEntity.java
This file contains 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,23 @@ | ||
package com.tissue.api.common.entity; | ||
|
||
import org.springframework.data.annotation.CreatedBy; | ||
import org.springframework.data.annotation.LastModifiedBy; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@MappedSuperclass | ||
@EntityListeners(AuditingEntityListener.class) | ||
public class WorkspaceContextBaseEntity extends BaseDateEntity { | ||
|
||
@CreatedBy | ||
@Column(updatable = false) | ||
private Long createdByWorkspaceMember; | ||
|
||
@LastModifiedBy | ||
private Long lastModifiedByWorkspaceMember; | ||
} |
23 changes: 0 additions & 23 deletions
23
backend/src/main/java/com/tissue/api/global/audit/SessionAuditorAware.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
backend/src/main/java/com/tissue/api/global/audit/WebRequestAuditorAware.java
This file contains 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,45 @@ | ||
package com.tissue.api.global.audit; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.tissue.api.security.authorization.interceptor.AuthorizationInterceptor; | ||
import com.tissue.api.security.session.SessionAttributes; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpSession; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class WebRequestAuditorAware implements AuditorAware<Long> { | ||
|
||
private static final String WORKSPACE_API_PREFIX = "/api/v1/workspaces"; | ||
|
||
private final HttpSession session; | ||
private final HttpServletRequest request; | ||
|
||
@Override | ||
public Optional<Long> getCurrentAuditor() { | ||
|
||
String requestUri = request.getRequestURI(); | ||
|
||
// workspace API인 경우 workspaceMemberId 반환, workspaceMemberId가 null이면 넘어가기 | ||
if (requestUri.startsWith(WORKSPACE_API_PREFIX)) { | ||
Long workspaceMemberId = (Long)request.getAttribute( | ||
AuthorizationInterceptor.CURRENT_WORKSPACE_MEMBER_ID | ||
); | ||
|
||
if (workspaceMemberId != null) { | ||
return Optional.of(workspaceMemberId); | ||
} | ||
} | ||
|
||
// 그 외의 경우 memberId 반환 | ||
return Optional.ofNullable( | ||
(Long)session.getAttribute(SessionAttributes.LOGIN_MEMBER_ID) | ||
); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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 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 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 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
Oops, something went wrong.