|
|
|
@ -1,15 +1,15 @@
|
|
|
|
|
package cokr.xit.ens.core.aop;
|
|
|
|
|
|
|
|
|
|
import cokr.xit.ens.core.aop.repository.AccessLogRepository;
|
|
|
|
|
import cokr.xit.ens.core.exception.EnsException;
|
|
|
|
|
import cokr.xit.ens.core.exception.code.EnsErrCd;
|
|
|
|
|
import cokr.xit.ens.core.monitor.slack.event.MonitorEvent;
|
|
|
|
|
import cokr.xit.ens.core.utils.CmmnUtil;
|
|
|
|
|
import cokr.xit.ens.core.utils.JwtUtil;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
|
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
|
@ -23,14 +23,16 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
|
|
import cokr.xit.ens.core.exception.EnsException;
|
|
|
|
|
import cokr.xit.ens.core.exception.code.EnsErrCd;
|
|
|
|
|
import cokr.xit.ens.core.monitor.slack.event.MonitorEvent;
|
|
|
|
|
import cokr.xit.ens.core.utils.CmmnUtil;
|
|
|
|
|
import cokr.xit.ens.core.utils.JwtUtil;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author (주)엑스아이티 개발팀
|
|
|
|
@ -51,7 +53,7 @@ public class AccessLogAspect {
|
|
|
|
|
|
|
|
|
|
@Value("${spring.profiles.active}")
|
|
|
|
|
private String ACTIVE_PROFILE;
|
|
|
|
|
private final AccessLogRepository accessLogRepository;
|
|
|
|
|
private final AccessLogService accessLogService;
|
|
|
|
|
|
|
|
|
|
private final String ACCESS_TOKEN_NAME = "Authorization";
|
|
|
|
|
private final ApplicationEventPublisher applicationEventPublisher;
|
|
|
|
@ -88,14 +90,12 @@ public class AccessLogAspect {
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
Object result = null;
|
|
|
|
|
AccessLog accessLog = null;
|
|
|
|
|
AccessLogDTO accessLogDTO = null;
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
log.info("[BEFORE] : ...");
|
|
|
|
|
accessLog = this.setRequestInfo(request);
|
|
|
|
|
accessLogRepository.save(accessLog);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accessLogDTO = this.setRequestInfo(request);
|
|
|
|
|
accessLogService.save(accessLogDTO);
|
|
|
|
|
|
|
|
|
|
if (this.isCertified(request)) {
|
|
|
|
|
|
|
|
|
@ -103,8 +103,8 @@ public class AccessLogAspect {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("[AFTER] : ...");
|
|
|
|
|
this.setResponseInfo(accessLog, result);
|
|
|
|
|
accessLogRepository.save(accessLog);
|
|
|
|
|
this.setResponseInfo(accessLogDTO, result);
|
|
|
|
|
accessLogService.save(accessLogDTO);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
@ -117,16 +117,15 @@ public class AccessLogAspect {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.error(String.format("[NoAuth] : %s => %s", ACCESS_TOKEN_NAME, request.getHeader(ACCESS_TOKEN_NAME)));
|
|
|
|
|
accessLog.setResponseNoAuth(msg);
|
|
|
|
|
accessLogRepository.save(accessLog);
|
|
|
|
|
|
|
|
|
|
accessLogDTO.setResponseNoAuth(msg);
|
|
|
|
|
accessLogService.save(accessLogDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (EnsException e) {
|
|
|
|
|
|
|
|
|
|
log.error(String.format("[ERROR] : %s", e.getMessage()));
|
|
|
|
|
accessLog.setResponseFail(String.format("%s: %s", e.getErrCd(), e.getMessage()));
|
|
|
|
|
accessLogRepository.save(accessLog);
|
|
|
|
|
accessLogDTO.setResponseFail(String.format("%s: %s", e.getErrCd(), e.getMessage()));
|
|
|
|
|
accessLogService.save(accessLogDTO);
|
|
|
|
|
if (result == null) {
|
|
|
|
|
EnsResponseVO restResponseVO = EnsResponseVO
|
|
|
|
|
.errBuilder()
|
|
|
|
@ -138,8 +137,8 @@ public class AccessLogAspect {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
log.error(String.format("[%s ERROR] : %s", EnsErrCd.UNKNOWN, e.getMessage()), e);
|
|
|
|
|
accessLog.setResponseFail(String.format("%s: %s", EnsErrCd.UNKNOWN, CmmnUtil.printStackTraceToString(e)));
|
|
|
|
|
accessLogRepository.save(accessLog);
|
|
|
|
|
accessLogDTO.setResponseFail(String.format("%s: %s", EnsErrCd.UNKNOWN, CmmnUtil.printStackTraceToString(e)));
|
|
|
|
|
accessLogService.save(accessLogDTO);
|
|
|
|
|
if (result == null) {
|
|
|
|
|
EnsResponseVO restResponseVO = EnsResponseVO
|
|
|
|
|
.errBuilder()
|
|
|
|
@ -150,7 +149,7 @@ public class AccessLogAspect {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
applicationEventPublisher.publishEvent(MonitorEvent.builder()
|
|
|
|
|
.message(AccessErrorMessage.builder().ACTIVE_PROFILE(ACTIVE_PROFILE).accessLog(accessLog).serverUrl(CmmnUtil.getServerUrl()).build())
|
|
|
|
|
.message(AccessErrorMessage.builder().ACTIVE_PROFILE(ACTIVE_PROFILE).accessLogDTO(accessLogDTO).serverUrl(CmmnUtil.getServerUrl()).build())
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -174,7 +173,7 @@ public class AccessLogAspect {
|
|
|
|
|
* @date: 2021. 11. 30.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
|
private AccessLog setRequestInfo(HttpServletRequest request) throws JsonProcessingException {
|
|
|
|
|
private AccessLogDTO setRequestInfo(HttpServletRequest request) throws JsonProcessingException {
|
|
|
|
|
String sessionId = request.getSession().getId();
|
|
|
|
|
String param = null;
|
|
|
|
|
try {
|
|
|
|
@ -185,7 +184,7 @@ public class AccessLogAspect {
|
|
|
|
|
param = String.format("[요청 parameter 변환 실패]: %s", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AccessLog.reqBuilder()
|
|
|
|
|
return AccessLogDTO.reqBuilder()
|
|
|
|
|
.accessToken(request.getHeader(ACCESS_TOKEN_NAME))
|
|
|
|
|
.sessionId(sessionId)
|
|
|
|
|
.ip(this.getClientIpAddr(request))
|
|
|
|
@ -199,12 +198,12 @@ public class AccessLogAspect {
|
|
|
|
|
/**
|
|
|
|
|
* <pre>메소드 설명: 응답정보 설정</pre>
|
|
|
|
|
*
|
|
|
|
|
* @param accessLog
|
|
|
|
|
* @param accessLogDTO
|
|
|
|
|
* @param result
|
|
|
|
|
* @author: 박민규
|
|
|
|
|
* @date: 2021. 11. 30.
|
|
|
|
|
*/
|
|
|
|
|
private void setResponseInfo(AccessLog accessLog, Object result) {
|
|
|
|
|
private void setResponseInfo(AccessLogDTO accessLogDTO, Object result) {
|
|
|
|
|
String response = null;
|
|
|
|
|
if (result instanceof String)
|
|
|
|
|
response = (String) result;
|
|
|
|
@ -215,7 +214,7 @@ public class AccessLogAspect {
|
|
|
|
|
else
|
|
|
|
|
response = String.valueOf(result);
|
|
|
|
|
|
|
|
|
|
accessLog.setResponseCompleted(response);
|
|
|
|
|
accessLogDTO.setResponseCompleted(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|