Skip to content
Snippets Groups Projects
Commit 8207b91f authored by 천 진강's avatar 천 진강
Browse files

fix: DB 연관관계 수정, 로그 메세지가 잘못되어있던 문제 수정

parent ad7d22e6
Branches
No related tags found
3 merge requests!15Feat/certificate,!12Feat/log,!11Feat/log 사용자 CUD 활동 로그 생성 및 조회
......@@ -23,6 +23,7 @@ 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.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......@@ -46,7 +47,7 @@ public class ForwardingLogAspect {
/* 사용자 조회 */
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Map<String, String> tmp = (Map<String, String>) request.getSession().getAttribute("user");
Map<String, String> tmp = (Map<String, String>) request.getAttribute("user");
User user = userRepository.findByKeystoneId(tmp.get("id")).orElseThrow(
() -> new CustomException(ErrorCode.NOT_FOUND_USER)
);
......@@ -65,7 +66,7 @@ public class ForwardingLogAspect {
.user(user)
.objectType(ObjectType.FORWARDING)
.objectId(forwarding.getForwardingId())
.action(Action.UPDATE)
.action(Action.CREATE)
.projectId(forwarding.getProjectId())
.description(description)
.build());
......@@ -77,7 +78,7 @@ public class ForwardingLogAspect {
/* 사용자 조회 */
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Map<String, String> tmp = (Map<String, String>) request.getSession().getAttribute("user");
Map<String, String> tmp = (Map<String, String>) request.getAttribute("user");
User user = userRepository.findByKeystoneId(tmp.get("id")).orElseThrow(
() -> new CustomException(ErrorCode.NOT_FOUND_USER)
);
......@@ -99,7 +100,7 @@ public class ForwardingLogAspect {
.user(user)
.objectType(ObjectType.FORWARDING)
.objectId(forwarding.getForwardingId())
.action(Action.UPDATE)
.action(Action.DELETE)
.projectId(forwarding.getProjectId())
.description(description)
.build());
......@@ -111,7 +112,7 @@ public class ForwardingLogAspect {
/* 사용자 조회 */
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Map<String, String> tmp = (Map<String, String>) request.getSession().getAttribute("user");
Map<String, String> tmp = (Map<String, String>) request.getAttribute("user");
User user = userRepository.findByKeystoneId(tmp.get("id")).orElseThrow(
() -> new CustomException(ErrorCode.NOT_FOUND_USER)
);
......@@ -134,8 +135,8 @@ public class ForwardingLogAspect {
/* 로그 메세지 작성 */
String description = "name: " + old.getName() + (old.getName().equals(newObj.getName()) ? "" : (" -> " + newObj.getName())) + "\n"
+ "serverPort: " + old.getServerPort() + (old.getServerPort().equals(newObj.getServerPort()) ? "" : (" -> " + newObj.getServerPort())) + "\n"
+ "instanceIp: " + (old.getInstanceIp().equals(newObj.getInstanceIp()) ? "" : (" -> " + newObj.getInstanceIp())) + "\n"
+ "instancePort: " + (old.getInstancePort().equals(newObj.getInstancePort()) ? "" : (" -> " + newObj.getInstancePort()));
+ "instanceIp: " + old.getInstanceIp() + (old.getInstanceIp().equals(newObj.getInstanceIp()) ? "" : (" -> " + newObj.getInstanceIp())) + "\n"
+ "instancePort: " + old.getInstancePort() + (old.getInstancePort().equals(newObj.getInstancePort()) ? "" : (" -> " + newObj.getInstancePort()));
/* 로그 엔티티 저장 */
logRepository.save(Log.builder()
......
......@@ -23,6 +23,7 @@ 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.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
......@@ -46,7 +47,7 @@ public class RoutingLogAspect {
/* 사용자 조회 */
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Map<String, String> tmp = (Map<String, String>) request.getSession().getAttribute("user");
Map<String, String> tmp = (Map<String, String>) request.getAttribute("user");
User user = userRepository.findByKeystoneId(tmp.get("id")).orElseThrow(
() -> new CustomException(ErrorCode.NOT_FOUND_USER)
);
......@@ -58,16 +59,16 @@ public class RoutingLogAspect {
String description = "name: " + routing.getName() + "\n"
+ "domain: " + routing.getDomain() + "\n"
+ "ip: " + routing.getInstanceIp() + "\n"
+ "ip: " + routing.getInstancePort() + "\n"
+ "certificateId: " + routing.getCertificate().getCertificateId() + "\n"
+ "port: " + routing.getInstancePort() + "\n"
+ (routing.getCertificate() != null ? ("certificateId: " + routing.getCertificate().getCertificateId() + "\n") : "")
+ "caching: " + routing.getCaching() + "\n";
/* 로그 엔티티 저장 */
logRepository.save(Log.builder()
.user(user)
.objectType(ObjectType.FORWARDING)
.objectType(ObjectType.ROUTING)
.objectId(routing.getRoutingId())
.action(Action.UPDATE)
.action(Action.CREATE)
.projectId(routing.getProjectId())
.description(description)
.build());
......@@ -79,7 +80,7 @@ public class RoutingLogAspect {
/* 사용자 조회 */
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Map<String, String> tmp = (Map<String, String>) request.getSession().getAttribute("user");
Map<String, String> tmp = (Map<String, String>) request.getAttribute("user");
User user = userRepository.findByKeystoneId(tmp.get("id")).orElseThrow(
() -> new CustomException(ErrorCode.NOT_FOUND_USER)
);
......@@ -94,28 +95,28 @@ public class RoutingLogAspect {
String description = "name: " + routing.getName() + "\n"
+ "domain: " + routing.getDomain() + "\n"
+ "ip: " + routing.getInstanceIp() + "\n"
+ "ip: " + routing.getInstancePort() + "\n"
+ "certificateId: " + routing.getCertificate().getCertificateId() + "\n"
+ "port: " + routing.getInstancePort() + "\n"
+ (routing.getCertificate() != null ? ("certificateId: " + routing.getCertificate().getCertificateId() + "\n") : "")
+ "caching: " + routing.getCaching() + "\n";
/* 로그 엔티티 저장 */
logRepository.save(Log.builder()
.user(user)
.objectType(ObjectType.FORWARDING)
.objectType(ObjectType.ROUTING)
.objectId(routing.getRoutingId())
.action(Action.UPDATE)
.action(Action.DELETE)
.projectId(routing.getProjectId())
.description(description)
.build());
}
/* Update(edit) 로깅 */
@Around("execution(* com.aolda.itda.service.forwarding.*Service.*edit*(..))")
@Around("execution(* com.aolda.itda.service.routing.*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.getSession().getAttribute("user");
Map<String, String> tmp = (Map<String, String>) request.getAttribute("user");
User user = userRepository.findByKeystoneId(tmp.get("id")).orElseThrow(
() -> new CustomException(ErrorCode.NOT_FOUND_USER)
);
......@@ -136,17 +137,29 @@ public class RoutingLogAspect {
Routing newObj = routingRepository.findByRoutingIdAndIsDeleted(id, false).orElse(null);
/* 로그 메세지 작성 */
String description = "name: " + old.getName() + (old.getName().equals(newObj.getName()) ? "" : (" -> " + newObj.getName())) + "\n"
+ "domain: " + old.getDomain() + (old.getDomain().equals(newObj.getDomain()) ? "" : (" -> " + newObj.getDomain())) + "\n"
+ "ip: " + (old.getInstanceIp().equals(newObj.getInstanceIp()) ? "" : (" -> " + newObj.getInstanceIp())) + "\n"
+ "port: " + (old.getInstancePort().equals(newObj.getInstancePort()) ? "" : (" -> " + newObj.getInstancePort())) + "\n"
+ "certificateId: " + (old.getCertificate().getCertificateId() == newObj.getCertificate().getCertificateId() ? "" : (" -> " + newObj.getCertificate().getCertificateId()))
+ "certificateId: " + (old.getCaching() == newObj.getCaching() ? "" : (" -> " + newObj.getCaching()));
String description = "name: " + old.getName() + (old.getName().equals(newObj.getName()) ? "" : " -> " + newObj.getName()) + "\n"
+ "domain: " + old.getDomain() + (old.getDomain().equals(newObj.getDomain()) ? "" : " -> " + newObj.getDomain()) + "\n"
+ "ip: " + old.getInstanceIp() + (old.getInstanceIp().equals(newObj.getInstanceIp()) ? "" : " -> " + newObj.getInstanceIp()) + "\n"
+ "port: " + old.getInstancePort() + (old.getInstancePort().equals(newObj.getInstancePort()) ? "" : " -> " + newObj.getInstancePort()) + "\n";
if (old.getCertificate() == null) {
if (newObj.getCertificate() != null) {
description = description + "certificateId: null -> " + newObj.getCertificate().getCertificateId() + "\n";
}
}
else {
if (newObj.getCertificate() == null) {
description = description + "certificateId: " + old.getCertificate().getCertificateId() + " -> null\n";
}
else {
description = description + "certificateId: " + old.getCertificate().getCertificateId() + " -> " + newObj.getCertificate().getCertificateId() + "\n";
}
}
description = description + "caching: " + (old.getCaching() == newObj.getCaching() ? newObj.getCaching() : (" -> " + newObj.getCaching()));
/* 로그 엔티티 저장 */
logRepository.save(Log.builder()
.user(user)
.objectType(ObjectType.FORWARDING)
.objectType(ObjectType.ROUTING)
.objectId(newObj.getRoutingId())
.action(Action.UPDATE)
.projectId(newObj.getProjectId())
......
......@@ -23,7 +23,7 @@ public class Certificate extends BaseTimeEntity {
@Column(nullable = false)
private Long certificateId;
@OneToOne
@ManyToOne
@JoinColumn(nullable = false, name = "user_id")
private User user;
......
......@@ -20,10 +20,6 @@ public class Forwarding extends BaseTimeEntity {
@Column(nullable = false)
private Long forwardingId;
@OneToOne
@JoinColumn(name = "user_id")
private User user;
private String projectId;
private String serverIp;
......@@ -40,7 +36,6 @@ public class Forwarding extends BaseTimeEntity {
public Forwarding(Forwarding forwarding) {
this.forwardingId = forwarding.getForwardingId();
this.user = forwarding.getUser();
this.projectId = forwarding.getProjectId();
this.serverIp = forwarding.getServerIp();
this.serverPort = forwarding.getServerPort();
......
......@@ -23,7 +23,7 @@ public class Log extends BaseTimeEntity {
@Column(nullable = false)
private Long logId;
@OneToOne
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user;
......
......@@ -24,11 +24,7 @@ public class Routing extends BaseTimeEntity {
@Column(nullable = false)
private Long routingId;
@OneToOne
@JoinColumn(name = "user_id")
private User user;
@OneToOne
@ManyToOne
@JoinColumn(name = "certificate_id")
private Certificate certificate;
......
......@@ -74,31 +74,29 @@ public class LogQueryDSL {
builder.and(log.projectId.eq(projectId));
}
/* 오브젝트 타입 조건 ( 기본 : ROUTING ) */
if (type.equals("certificate")) {
builder.and(log.objectType.eq(ObjectType.CERTIFICATE));
/* 오브젝트 타입 조건 */
if (type != null) {
switch (type) {
case "certificate" -> builder.and(log.objectType.eq(ObjectType.CERTIFICATE));
case "forwarding" -> builder.and(log.objectType.eq(ObjectType.FORWARDING));
case "routing" -> builder.and(log.objectType.eq(ObjectType.ROUTING));
}
else if (type.equals("forwarding")) {
builder.and(log.objectType.eq(ObjectType.FORWARDING));
}
else {
builder.and(log.objectType.eq(ObjectType.ROUTING));
}
/* 사용자 ID 조건 */
if (username != null) {
builder.and(log.user.keystoneUsername.eq(username));
}
/* CUD 조건 */
if (action.equals("create")) {
builder.and(log.action.eq(Action.CREATE));
} else if (action.equals("update")) {
builder.and(log.action.eq(Action.UPDATE));
} else if (action.equals("delete")) {
builder.and(log.action.eq(Action.DELETE));
if (action != null) {
switch (action) {
case "create" -> builder.and(log.action.eq(Action.CREATE));
case "update" -> builder.and(log.action.eq(Action.UPDATE));
case "delete" -> builder.and(log.action.eq(Action.DELETE));
}
}
return builder;
}
}
......@@ -51,7 +51,7 @@ public class AuthService {
User entity = userRepository.findByKeystoneUsername(userId).orElse(null);
if (entity == null) {
userRepository.save(User.builder().keystoneId(validateTokenAndGetUserId(token)).
keystoneUsername(userId).build());
keystoneUsername(loginRequestDTO.getId()).build());
}
response.addHeader("X-Subject-Token", systemToken != null ? systemToken : token);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment