웹훅 신청내역 수정 기능 추가
- Target URL, User Secret, 신청 이벤트 수정 로직 구현 - 수정 가능 이벤트유형 조회 및 Validation 추가 - 상세 화면 UI 및 저장 처리 로직 업데이트
This commit is contained in:
@@ -188,6 +188,12 @@ class RequestWrapper extends HttpServletRequestWrapper {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 웹훅 Target URL(쿼리스트링 '&', '#')과 User Secret(HTTP 헤더로 발송)은 원문 그대로 저장되어야 함.
|
||||
if ("POST".equalsIgnoreCase(getMethod())
|
||||
&& "/onl/apim/webhook/webhookReqMan.json".equals(getServletPath())
|
||||
&& "UPDATE".equals(super.getParameter("cmd"))) {
|
||||
return true;
|
||||
}
|
||||
for (String skipParam : SKIP_CHAR_CONVERT_PARAMS) {
|
||||
if (StringUtils.equalsIgnoreCase(param, skipParam)) {
|
||||
return true;
|
||||
|
||||
@@ -38,4 +38,10 @@ public class WebhookReq {
|
||||
@Column(name = "CREATED_DATE", length = 14)
|
||||
@Comment("신청일시 (yyyyMMddHHmmss)")
|
||||
private String createdDate;
|
||||
|
||||
/** 관리자 화면 수정 — Target URL / User Secret. (SECRET 은 HMAC 서명 키라 수정 대상 아님) */
|
||||
public void update(String targetUrl, String userSecret) {
|
||||
this.targetUrl = targetUrl;
|
||||
this.userSecret = userSecret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,8 @@ public class WebhookReqEvent implements Serializable {
|
||||
|
||||
@EmbeddedId
|
||||
private WebhookReqEventId id;
|
||||
|
||||
public WebhookReqEvent(String webhookReqId, String eventType) {
|
||||
this.id = new WebhookReqEventId(webhookReqId, eventType);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-1
@@ -18,6 +18,7 @@ import com.eactive.eai.rms.common.vo.GridResponse;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqDetailUI;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqUI;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqUISearch;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqUpdateUI;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.service.WebhookReqManService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -25,7 +26,7 @@ import lombok.RequiredArgsConstructor;
|
||||
/**
|
||||
* 웹훅 신청내역(PTL_WEBHOOK_REQ) 조회 화면 컨트롤러.
|
||||
*
|
||||
* <p>조회 전용 (등록/수정/삭제 없음)</p>
|
||||
* <p>등록/삭제 없음. 상세 화면에서 Target URL, User Secret, 신청 이벤트만 수정한다.</p>
|
||||
*/
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@@ -57,6 +58,7 @@ public class WebhookReqManController extends BaseAnnotationController {
|
||||
Map<String, Object> resultMap = new HashMap<>();
|
||||
resultMap.put("eventTypeList", comboService.getMonitoringCodeSortedBySeq(
|
||||
WebhookReqManService.CODE_GROUP_EVENT_TYPE));
|
||||
resultMap.put("selectableEventTypeList", webhookReqManService.getSelectableEventTypes());
|
||||
return ResponseEntity.ok(resultMap);
|
||||
}
|
||||
|
||||
@@ -64,4 +66,10 @@ public class WebhookReqManController extends BaseAnnotationController {
|
||||
public ResponseEntity<WebhookReqDetailUI> selectDetail(String id) {
|
||||
return ResponseEntity.ok(webhookReqManService.selectDetail(id));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/onl/apim/webhook/webhookReqMan.json", params = "cmd=UPDATE")
|
||||
public ResponseEntity<String> update(WebhookReqUpdateUI webhookReqUpdateUI) {
|
||||
webhookReqManService.update(webhookReqUpdateUI);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.eactive.eai.rms.ext.djb.webhook.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 웹훅 신청내역(PTL_WEBHOOK_REQ) 상세 화면 수정 요청 DTO.
|
||||
*
|
||||
* <p>Target URL, User Secret, 신청 이벤트(PTL_WEBHOOK_REQ_EVENT)만 수정한다.</p>
|
||||
*/
|
||||
@Data
|
||||
public class WebhookReqUpdateUI {
|
||||
|
||||
private String id;
|
||||
|
||||
private String targetUrl;
|
||||
|
||||
/** 공란이면 User Secret 을 비운다(null). */
|
||||
private String userSecret;
|
||||
|
||||
/** 신청 이벤트유형 코드 목록 — 전체 삭제 후 재등록한다. */
|
||||
private List<String> eventTypes;
|
||||
}
|
||||
+102
-2
@@ -1,8 +1,14 @@
|
||||
package com.eactive.eai.rms.ext.djb.webhook.service;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -18,14 +24,18 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.eactive.apim.portal.portalorg.entity.QPortalOrg;
|
||||
import com.eactive.eai.rms.common.base.BaseService;
|
||||
import com.eactive.eai.rms.common.combo.ComboService;
|
||||
import com.eactive.eai.rms.common.combo.ComboVo;
|
||||
import com.eactive.eai.rms.common.util.StringUtils;
|
||||
import com.eactive.eai.rms.data.entity.onl.djb.webhook.QWebhookReq;
|
||||
import com.eactive.eai.rms.data.entity.onl.djb.webhook.QWebhookReqApi;
|
||||
import com.eactive.eai.rms.data.entity.onl.djb.webhook.QWebhookReqEvent;
|
||||
import com.eactive.eai.rms.data.entity.onl.djb.webhook.WebhookReq;
|
||||
import com.eactive.eai.rms.data.entity.onl.djb.webhook.WebhookReqEvent;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqDetailUI;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqUI;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqUISearch;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.dto.WebhookReqUpdateUI;
|
||||
import com.eactive.eai.rms.ext.djb.webhook.repository.WebhookReqRepository;
|
||||
import com.eactive.eai.rms.onl.common.exception.BizException;
|
||||
import com.querydsl.core.BooleanBuilder;
|
||||
@@ -34,9 +44,9 @@ import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* 웹훅 신청내역(PTL_WEBHOOK_REQ) 조회 화면 서비스.
|
||||
* 웹훅 신청내역(PTL_WEBHOOK_REQ) 조회/수정 화면 서비스.
|
||||
*
|
||||
* <p>조회 전용. orgId 는 엔티티 연관관계가 아닌 단순 컬럼이므로,
|
||||
* <p>수정은 Target URL, User Secret, 신청 이벤트만 대상으로 한다. orgId 는 엔티티 연관관계가 아닌 단순 컬럼이므로,
|
||||
* 기관명은 QueryDSL 로 ptl_org 를 별도 조회하여 매핑한다.</p>
|
||||
*/
|
||||
@Service
|
||||
@@ -47,10 +57,22 @@ public class WebhookReqManService extends BaseService {
|
||||
/** 모니터링 공통코드(tseairm28) 상의 웹훅 이벤트유형 코드 그룹. */
|
||||
public static final String CODE_GROUP_EVENT_TYPE = "EVENT_TYPE";
|
||||
|
||||
/**
|
||||
* 구독 선택 대상에서 고정 제외하는 이벤트유형 코드 (포털 WebhookEventTypeProvider 와 동일).
|
||||
* CHECK_NOTICE 는 CHECK_START 구독자에게 발송되는 사전 예고용이라 직접 구독하지 않는다.
|
||||
*/
|
||||
private static final Set<String> HIDDEN_EVENT_TYPES = Collections.unmodifiableSet(
|
||||
new HashSet<>(Arrays.asList("CHECK_NOTICE")));
|
||||
|
||||
/* DB 컬럼 길이 (PTL_WEBHOOK_REQ.TARGET_URL / USER_SECRET) */
|
||||
private static final int TARGET_URL_MAX_LENGTH = 255;
|
||||
private static final int USER_SECRET_MAX_LENGTH = 500;
|
||||
|
||||
private static final DateTimeFormatter FMT_DATETIME_OUT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
private static final DateTimeFormatter FMT_DATETIME_IN = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
|
||||
private final WebhookReqRepository webhookReqRepository;
|
||||
private final ComboService comboService;
|
||||
|
||||
@PersistenceContext(unitName = "entityManagerFactoryForEMS")
|
||||
private EntityManager entityManager;
|
||||
@@ -105,6 +127,84 @@ public class WebhookReqManService extends BaseService {
|
||||
return ui;
|
||||
}
|
||||
|
||||
/** 수정 화면에서 선택 가능한 이벤트유형 목록 ({@link #HIDDEN_EVENT_TYPES} 제외). */
|
||||
public List<ComboVo> getSelectableEventTypes() {
|
||||
return comboService.getMonitoringCodeSortedBySeq(CODE_GROUP_EVENT_TYPE).stream()
|
||||
.filter(c -> !HIDDEN_EVENT_TYPES.contains(c.getCode()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Target URL / User Secret / 신청 이벤트 수정.
|
||||
*
|
||||
* <p>SECRET(HMAC 서명 키)과 API 목록은 수정하지 않는다. 이벤트는 delete-all 후 재등록한다.
|
||||
* User Secret 은 상세 화면에 평문으로 표시되므로 공란 제출 시 값을 비운다(null).</p>
|
||||
*/
|
||||
public void update(WebhookReqUpdateUI ui) {
|
||||
WebhookReq entity = webhookReqRepository.findById(ui.getId())
|
||||
.orElseThrow(() -> new BizException("존재하지 않는 웹훅 신청내역입니다."));
|
||||
|
||||
String targetUrl = StringUtils.trimToEmpty(ui.getTargetUrl());
|
||||
if (!isValidUrl(targetUrl)) {
|
||||
throw new BizException("올바른 URL 형식이 아닙니다. http:// 또는 https:// 로 시작하는 전체 주소를 입력해주세요.");
|
||||
}
|
||||
if (targetUrl.length() > TARGET_URL_MAX_LENGTH) {
|
||||
throw new BizException("Target URL은 " + TARGET_URL_MAX_LENGTH + "자를 초과할 수 없습니다.");
|
||||
}
|
||||
|
||||
String userSecret = StringUtils.trimToNull(ui.getUserSecret());
|
||||
if (userSecret != null) {
|
||||
if (userSecret.length() > USER_SECRET_MAX_LENGTH) {
|
||||
throw new BizException("User Secret은 " + USER_SECRET_MAX_LENGTH + "자를 초과할 수 없습니다.");
|
||||
}
|
||||
// 발송 시 HTTP 헤더(x-webhook-secret)로 그대로 실리므로 출력 가능 ASCII 만 허용
|
||||
if (!userSecret.matches("^[\\x20-\\x7E]*$")) {
|
||||
throw new BizException("User Secret은 영문·숫자·특수문자 등 ASCII 문자만 입력 가능합니다.");
|
||||
}
|
||||
}
|
||||
|
||||
List<String> eventTypes = ui.getEventTypes() == null ? Collections.<String>emptyList()
|
||||
: new ArrayList<>(new LinkedHashSet<>(ui.getEventTypes()));
|
||||
if (eventTypes.isEmpty()) {
|
||||
throw new BizException("신청 이벤트를 1개 이상 선택해주세요.");
|
||||
}
|
||||
Set<String> selectable = getSelectableEventTypes().stream()
|
||||
.map(ComboVo::getCode)
|
||||
.collect(Collectors.toSet());
|
||||
for (String eventType : eventTypes) {
|
||||
if (!selectable.contains(eventType)) {
|
||||
throw new BizException("유효하지 않은 이벤트유형입니다: " + eventType);
|
||||
}
|
||||
}
|
||||
|
||||
entity.update(targetUrl, userSecret);
|
||||
webhookReqRepository.save(entity);
|
||||
|
||||
QWebhookReqEvent evt = QWebhookReqEvent.webhookReqEvent;
|
||||
new JPAQueryFactory(entityManager)
|
||||
.delete(evt)
|
||||
.where(evt.id.webhookReqId.eq(entity.getId()))
|
||||
.execute();
|
||||
for (String eventType : eventTypes) {
|
||||
entityManager.persist(new WebhookReqEvent(entity.getId(), eventType));
|
||||
}
|
||||
}
|
||||
|
||||
/** http/https 스킴 + host 존재 여부 (포털 WebhookUrlValidator 와 동일 기준). */
|
||||
private static boolean isValidUrl(String url) {
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
String scheme = uri.getScheme();
|
||||
return ("http".equalsIgnoreCase(scheme) || "https".equalsIgnoreCase(scheme))
|
||||
&& StringUtils.isNotBlank(uri.getHost());
|
||||
} catch (URISyntaxException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 기관명 LIKE 검색으로 매칭되는 orgId 목록. */
|
||||
private List<String> findOrgIdsByName(String orgName) {
|
||||
QPortalOrg org = QPortalOrg.portalOrg;
|
||||
|
||||
Reference in New Issue
Block a user