Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
proxy-manager-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aolda
proxy-manager-backend
Merge requests
!15
Feat/certificate
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Feat/certificate
feat/certificate
into
main
Overview
0
Commits
50
Pipelines
0
Changes
53
Merged
천 진강
requested to merge
feat/certificate
into
main
1 month ago
Overview
0
Commits
50
Pipelines
0
Changes
53
변경 사항
인증서 검색 조건 추가
필드명 수정 등 사소한 변경
PR 유형
어떤 변경 사항이 있나요?
새로운 기능 추가
버그 수정
코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
코드 리팩토링
주석 추가 및 수정
문서 수정
테스트 추가, 테스트 리팩토링
빌드 부분 혹은 패키지 매니저 수정
파일 , 폴더명 , 파일 경로 수정
파일 혹은 폴더 삭제
반영 브랜치
feat/certificate-> dev
기타
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
7a143ba4
50 commits,
1 month ago
53 files
+
3553
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
53
src/main/java/com/aolda/itda/aspect/CertificateLogAspect.java
0 → 100644
+
152
−
0
View file @ 7a143ba4
Edit in single-file editor
Open in Web IDE
package
com.aolda.itda.aspect
;
import
com.aolda.itda.dto.certificate.CertificateDTO
;
import
com.aolda.itda.entity.certificate.Certificate
;
import
com.aolda.itda.entity.log.Action
;
import
com.aolda.itda.entity.log.Log
;
import
com.aolda.itda.entity.log.ObjectType
;
import
com.aolda.itda.entity.user.User
;
import
com.aolda.itda.exception.CustomException
;
import
com.aolda.itda.exception.ErrorCode
;
import
com.aolda.itda.repository.certificate.CertificateRepository
;
import
com.aolda.itda.repository.log.LogRepository
;
import
com.aolda.itda.repository.user.UserRepository
;
import
jakarta.persistence.EntityManager
;
import
jakarta.servlet.http.HttpServletRequest
;
import
lombok.RequiredArgsConstructor
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Map
;
import
java.util.Objects
;
@Aspect
@Component
@RequiredArgsConstructor
public
class
CertificateLogAspect
{
private
final
CertificateRepository
certificateRepository
;
private
final
UserRepository
userRepository
;
private
final
LogRepository
logRepository
;
private
final
EntityManager
entityManager
;
private
static
final
DateTimeFormatter
LOG_DATE_FORMATTER
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
);
/* Create 로깅 */
@AfterReturning
(
pointcut
=
"execution(* com.aolda.itda.service.certificate.*Service.*create*(..))"
,
returning
=
"result"
)
public
void
createLogging
(
JoinPoint
joinPoint
,
CertificateDTO
result
)
{
/* 사용자 조회 */
HttpServletRequest
request
=
((
ServletRequestAttributes
)
Objects
.
requireNonNull
(
RequestContextHolder
.
getRequestAttributes
())).
getRequest
();
Map
<
String
,
String
>
tmp
=
(
Map
<
String
,
String
>)
request
.
getAttribute
(
"user"
);
User
user
=
userRepository
.
findByKeystoneId
(
tmp
.
get
(
"id"
)).
orElseThrow
(
()
->
new
CustomException
(
ErrorCode
.
NOT_FOUND_USER
)
);
/* 생성된 엔티티 조회 */
Certificate
certificate
=
certificateRepository
.
findByCertificateIdAndIsDeleted
(
result
.
getId
(),
false
).
orElse
(
null
);
/* 로그 메세지 작성 */
String
description
=
"domain: "
+
certificate
.
getDomain
()
+
"\n"
+
"email: "
+
certificate
.
getEmail
()
+
"\n"
+
"challenge: "
+
certificate
.
getChallenge
()
+
"\n"
+
"expiresAt: "
+
(
certificate
.
getExpiresAt
()
!=
null
?
certificate
.
getExpiresAt
().
format
(
LOG_DATE_FORMATTER
)
:
"null"
);
/* 로그 엔티티 저장 */
logRepository
.
save
(
Log
.
builder
()
.
user
(
user
)
.
objectType
(
ObjectType
.
CERTIFICATE
)
.
objectId
(
certificate
.
getCertificateId
())
.
action
(
Action
.
CREATE
)
.
projectId
(
certificate
.
getProjectId
())
.
description
(
description
)
.
build
());
}
/* Delete 로깅 */
@AfterReturning
(
pointcut
=
"execution(* com.aolda.itda.service.certificate.*Service.*delete*(..))"
)
public
void
deleteLogging
(
JoinPoint
joinPoint
)
{
/* 사용자 조회 */
HttpServletRequest
request
=
((
ServletRequestAttributes
)
Objects
.
requireNonNull
(
RequestContextHolder
.
getRequestAttributes
())).
getRequest
();
Map
<
String
,
String
>
tmp
=
(
Map
<
String
,
String
>)
request
.
getAttribute
(
"user"
);
User
user
=
userRepository
.
findByKeystoneId
(
tmp
.
get
(
"id"
)).
orElseThrow
(
()
->
new
CustomException
(
ErrorCode
.
NOT_FOUND_USER
)
);
/* 삭제된 엔티티 조회 */
Object
[]
args
=
joinPoint
.
getArgs
();
Long
id
=
(
Long
)
args
[
0
];
Certificate
certificate
=
certificateRepository
.
findByCertificateIdAndIsDeleted
(
id
,
true
).
orElse
(
null
);
/* 로그 메세지 작성 */
String
description
=
"domain: "
+
certificate
.
getDomain
()
+
"\n"
+
"email: "
+
certificate
.
getEmail
()
+
"\n"
+
"challenge: "
+
certificate
.
getChallenge
()
+
"\n"
+
"expiresAt: "
+
(
certificate
.
getExpiresAt
()
!=
null
?
certificate
.
getExpiresAt
().
format
(
LOG_DATE_FORMATTER
)
:
"null"
);
/* 로그 엔티티 저장 */
logRepository
.
save
(
Log
.
builder
()
.
user
(
user
)
.
objectType
(
ObjectType
.
CERTIFICATE
)
.
objectId
(
certificate
.
getCertificateId
())
.
action
(
Action
.
DELETE
)
.
projectId
(
certificate
.
getProjectId
())
.
description
(
description
)
.
build
());
}
/* Update(edit) 로깅 */
@Around
(
"execution(* com.aolda.itda.service.certificate.*Service.*edit*(..))"
)
public
Object
editLogging
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
/* 사용자 조회 */
HttpServletRequest
request
=
((
ServletRequestAttributes
)
Objects
.
requireNonNull
(
RequestContextHolder
.
getRequestAttributes
())).
getRequest
();
Map
<
String
,
String
>
tmp
=
(
Map
<
String
,
String
>)
request
.
getAttribute
(
"user"
);
User
user
=
userRepository
.
findByKeystoneId
(
tmp
.
get
(
"id"
)).
orElseThrow
(
()
->
new
CustomException
(
ErrorCode
.
NOT_FOUND_USER
)
);
/* 변경 전 엔티티 조회 */
Object
[]
args
=
joinPoint
.
getArgs
();
Long
id
=
(
Long
)
args
[
0
];
Certificate
old
=
certificateRepository
.
findByCertificateIdAndIsDeleted
(
id
,
false
).
orElse
(
null
);
if
(
old
!=
null
)
{
entityManager
.
detach
(
old
);
}
/* 메소드 진행 */
Object
result
=
joinPoint
.
proceed
();
/* 변경 후 엔티티 조회 */
Certificate
newObj
=
certificateRepository
.
findByCertificateIdAndIsDeleted
(
id
,
false
).
orElse
(
null
);
/* 로그 메세지 작성 */
String
description
=
"domain: "
+
old
.
getDomain
()
+
(
old
.
getDomain
().
equals
(
newObj
.
getDomain
())
?
""
:
" -> "
+
newObj
.
getDomain
())
+
"\n"
+
"email: "
+
old
.
getEmail
()
+
(
old
.
getEmail
().
equals
(
newObj
.
getEmail
())
?
""
:
" -> "
+
newObj
.
getEmail
())
+
"\n"
+
"challenge: "
+
old
.
getChallenge
()
+
(
old
.
getChallenge
()
==
newObj
.
getChallenge
()
?
""
:
" -> "
+
newObj
.
getChallenge
())
+
"\n"
+
"expiresAt: "
+
(
old
.
getExpiresAt
()
!=
null
?
old
.
getExpiresAt
().
format
(
LOG_DATE_FORMATTER
)
:
"null"
)
+
(
old
.
getExpiresAt
()
!=
null
&&
newObj
.
getExpiresAt
()
!=
null
&&
!
old
.
getExpiresAt
().
equals
(
newObj
.
getExpiresAt
())
?
" -> "
+
newObj
.
getExpiresAt
().
format
(
LOG_DATE_FORMATTER
)
:
""
);
/* 로그 엔티티 저장 */
logRepository
.
save
(
Log
.
builder
()
.
user
(
user
)
.
objectType
(
ObjectType
.
CERTIFICATE
)
.
objectId
(
newObj
.
getCertificateId
())
.
action
(
Action
.
UPDATE
)
.
projectId
(
newObj
.
getProjectId
())
.
description
(
description
)
.
build
());
return
result
;
}
}
\ No newline at end of file
Loading