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