초기소스
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package com.wb.domainserver.domain.mngr.api.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.wb.domainserver.domain.mngr.api.service.ApiService;
|
||||
import com.wb.domainserver.response.WnbtResponse;
|
||||
import com.wb.domainserver.response.WnbtWebClientResponseHandler;
|
||||
import com.wb.domainserver.security.authorization.annotation.AuthPolicy;
|
||||
import com.wb.domainserver.security.authorization.annotation.Policy;
|
||||
import com.wb.domainserver.util.communicate.RESRC;
|
||||
import com.wb.domainserver.util.communicate.ReplyFromResrc;
|
||||
import com.wb.domainserver.util.communicate.SendToResrc;
|
||||
import com.wb.domainserver.util.dataaccess.DataMap;
|
||||
import com.wb.domainserver.util.string.StringUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value = "/mngr/api")
|
||||
@Slf4j
|
||||
public class ApiController {
|
||||
|
||||
/** WebClient 호출을 위한 wrapper */
|
||||
@Autowired
|
||||
private WnbtWebClientResponseHandler responseHandler;
|
||||
|
||||
@Autowired
|
||||
private SendToResrc sendToResrc;
|
||||
|
||||
@Autowired
|
||||
private ApiService service;
|
||||
|
||||
/**
|
||||
* Order Api
|
||||
* 주문내역 api
|
||||
*/
|
||||
@ResponseBody
|
||||
@Policy(AuthPolicy.RESTRICTED)
|
||||
@RequestMapping(value ="/select/selectOrderList", method = RequestMethod.POST)
|
||||
public String selectOrderList (@RequestBody Map<String, Object> requestBody, ModelMap model, @CookieValue(value = "authSopmalCd") String authSopmalCd, HttpServletResponse response, HttpServletRequest request) throws IOException {
|
||||
|
||||
String clientIp = request.getHeader("X-Forwarded-For");
|
||||
String agentId = request.getHeader("agent_id");
|
||||
String sessionId = request.getHeader("session_id");
|
||||
|
||||
DataMap logParams = new DataMap();
|
||||
if (!StringUtil.isEmpty(clientIp) && clientIp.contains(",")) {
|
||||
clientIp = clientIp.split(",")[0];
|
||||
}
|
||||
|
||||
log.debug("clientIp :: {}", clientIp);
|
||||
|
||||
if (!clientIp.startsWith("221.139.65.203")) {
|
||||
response.sendError(HttpServletResponse.SC_FORBIDDEN,"Forbidden: 외부 네트워크 접근 금지");
|
||||
service.insertMngrApiAccessLog(request,response,"N","외부 네트워크 접근 금지","");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.debug("selectOrderList()");
|
||||
log.debug("✅ 받은 요청 바디: " + requestBody);
|
||||
requestBody.put("authSopmalCd", authSopmalCd);
|
||||
String listStr = "";
|
||||
String clearDataStr = "";
|
||||
ResponseEntity<WnbtResponse> boResponse = responseHandler.handleResponse(
|
||||
sendToResrc.ofPost(RESRC.GCONEBO, "/gcone/api/select/selectOrderList", requestBody),
|
||||
ReplyFromResrc::getReply
|
||||
);
|
||||
|
||||
// CSV 추출
|
||||
Object resultObj = boResponse.getBody().getResBody().getResult();
|
||||
if (resultObj instanceof String) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode outerJson = mapper.readTree((String) resultObj);
|
||||
JsonNode listNode = outerJson.get("list");
|
||||
JsonNode clearDataNode = outerJson.get("clearData");
|
||||
|
||||
if (listNode != null && !listNode.isNull()) {
|
||||
listStr = listNode.toString();
|
||||
} else {
|
||||
log.warn("⚠️ 'list' 필드가 존재하지 않음");
|
||||
}
|
||||
|
||||
if (clearDataNode != null && !clearDataNode.isNull()) {
|
||||
clearDataStr = clearDataNode.toString();
|
||||
} else {
|
||||
log.warn("⚠️ 'clearDataStr' 필드가 존재하지 않음");
|
||||
}
|
||||
|
||||
}
|
||||
int clearDataStrLength = Math.min(clearDataStr.length(), 1000);
|
||||
String responseData = clearDataStr.substring(0,clearDataStrLength);
|
||||
|
||||
service.insertMngrApiAccessLog(request,response,"Y","",responseData);
|
||||
return listStr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package com.wb.domainserver.domain.mngr.api.service;
|
||||
|
||||
import com.wb.domainserver.domain.log.mapper.LogMapper;
|
||||
import com.wb.domainserver.util.dataaccess.DataMap;
|
||||
import com.wb.domainserver.util.string.StringUtil;
|
||||
import jakarta.servlet.http.Cookie;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ApiService {
|
||||
|
||||
private final LogMapper mapper;
|
||||
|
||||
|
||||
public void insertMngrApiAccessLog(HttpServletRequest request, HttpServletResponse response, String successFlag, String failMsg, String responseData) throws IOException {
|
||||
|
||||
String sessionId = request.getHeader("session_id");
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
String clientIp = request.getHeader("X-Forwarded-For");
|
||||
String agentId = "";
|
||||
String authSopmalCd = "";
|
||||
DataMap dataMap = new DataMap();
|
||||
|
||||
// 호출된 메소드 이름
|
||||
String methodName = "selectOrderList";
|
||||
|
||||
// 요청 URL
|
||||
String url = request.getRequestURI();
|
||||
|
||||
// 요청 파라미터
|
||||
String postParam = "";
|
||||
|
||||
if ("POST".equalsIgnoreCase(request.getMethod())) {
|
||||
if ("application/json".equalsIgnoreCase(request.getContentType())) {
|
||||
try {
|
||||
postParam = new String(request.getInputStream().readAllBytes(), request.getCharacterEncoding());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// agentId 가져오기
|
||||
if (request.getCookies() != null) {
|
||||
Cookie[] cookies = request.getCookies();
|
||||
for (Cookie cookie : cookies) {
|
||||
if (cookie.getName().equals("agent_id")) {
|
||||
agentId = cookie.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//접속환경
|
||||
String env;
|
||||
String upperUseAgent = userAgent.toUpperCase();
|
||||
if (upperUseAgent.contains("MOBILE") || upperUseAgent.contains("ANDROID") || upperUseAgent.contains("IPHONE")) {
|
||||
env = "MO";
|
||||
} else if (upperUseAgent.contains("TABLET") || upperUseAgent.contains("IPAD")) {
|
||||
env = "MO";
|
||||
} else {
|
||||
env = "PC";
|
||||
}
|
||||
|
||||
//ip 분리
|
||||
if (!StringUtil.isEmpty(clientIp) && clientIp.contains(",")) {
|
||||
clientIp = clientIp.split(",")[0];
|
||||
}
|
||||
|
||||
if (request.getCookies() != null) {
|
||||
for (Cookie cookie : request.getCookies()) {
|
||||
if (cookie.getName().equals("authSopmalCd")) {
|
||||
authSopmalCd = cookie.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//sessionId 정보
|
||||
String jSessionId = "";
|
||||
if (request.getCookies() != null) {
|
||||
for (Cookie cookie : request.getCookies()) {
|
||||
if (cookie.getName().equals("JSESSIONID")) {
|
||||
jSessionId = cookie.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("clientIp :: {}", clientIp);
|
||||
|
||||
dataMap.put("sesionId", sessionId);
|
||||
dataMap.put("reqstMth", methodName);
|
||||
dataMap.put("agentId",agentId);
|
||||
dataMap.put("ip",clientIp);
|
||||
dataMap.put("conectEnvrnDv", env);
|
||||
dataMap.put("reqstData", postParam);
|
||||
dataMap.put("sopmalCd", authSopmalCd);
|
||||
dataMap.put("conectUrl",url);
|
||||
dataMap.put("jSessionId", jSessionId);
|
||||
dataMap.put("successYn", successFlag);
|
||||
dataMap.put("errorCode",failMsg);
|
||||
dataMap.put("responseData", responseData);
|
||||
|
||||
mapper.insertMngrApiAccessLog(dataMap);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.wb.domainserver.domain.mngr.api.vo;
|
||||
|
||||
import com.wb.domainserver.domain.comm.vo.AbstractVO;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ApiSrchVO extends AbstractVO {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String sopmalCd;
|
||||
|
||||
private String timeStamp;
|
||||
|
||||
private String data;
|
||||
|
||||
private String hash;
|
||||
}
|
||||
Reference in New Issue
Block a user