웹훅 신청내역 수정 기능 추가
- Target URL, User Secret, 신청 이벤트 수정 로직 구현 - 수정 가능 이벤트유형 조회 및 Validation 추가 - 상세 화면 UI 및 저장 처리 로직 업데이트
This commit is contained in:
@@ -19,12 +19,14 @@
|
||||
.sub_list th, .sub_list td { border:1px solid #ebebec; padding:6px 8px; text-align:left; }
|
||||
.sub_list th { background:#f7f7f8; width:60px; }
|
||||
.empty-msg { color:#999; padding:6px 2px; }
|
||||
.event-type-item { display:inline-block; margin-right:16px; white-space:nowrap; }
|
||||
</style>
|
||||
<script language="javascript">
|
||||
var url = '<c:url value="/onl/apim/webhook/webhookReqMan.json" />';
|
||||
var url_view = '<c:url value="/onl/apim/webhook/webhookReqMan.view" />';
|
||||
var key = '${param.id}';
|
||||
var combo;
|
||||
var canWrite = "${rmsMenuAuth}" == "W";
|
||||
|
||||
function escapeHtmlJs(s) { return $('<div>').text(s == null ? '' : s).html(); }
|
||||
|
||||
@@ -48,13 +50,70 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 선택 가능한 이벤트유형 체크박스 렌더링 + 신청된 이벤트 체크
|
||||
function renderEventTypes(eventTypes) {
|
||||
if (!eventTypes || eventTypes.length === 0) {
|
||||
$('#eventTypes').text('');
|
||||
var $box = $('#eventTypes').empty();
|
||||
var selected = eventTypes || [];
|
||||
var list = (combo && combo.selectableEventTypeList) || [];
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var code = list[i].CODE;
|
||||
var $label = $('<label class="event-type-item">');
|
||||
$('<input type="checkbox" name="eventTypes">')
|
||||
.val(code)
|
||||
.prop('checked', $.inArray(code, selected) >= 0)
|
||||
.prop('disabled', !canWrite)
|
||||
.appendTo($label);
|
||||
$label.append(' ').append(document.createTextNode(list[i].NAME));
|
||||
$box.append($label);
|
||||
}
|
||||
// 선택 목록에 없는 코드로 신청된 건은 텍스트로만 안내 (저장 시 제외됨)
|
||||
var etc = $.grep(selected, function (code) {
|
||||
return !list.some(function (item) { return item.CODE == code; });
|
||||
});
|
||||
if (etc.length > 0) {
|
||||
$('<div class="empty-msg">').text('선택 불가 이벤트(저장 시 제외): '
|
||||
+ etc.map(function (code) { return eventTypeName(code); }).join(', ')).appendTo($box);
|
||||
}
|
||||
}
|
||||
|
||||
function errorMessage(e) {
|
||||
try {
|
||||
var json = JSON.parse(e.responseText);
|
||||
if (json && json.errorMsg) { return json.errorMsg; }
|
||||
} catch (ignore) { }
|
||||
return e.responseText;
|
||||
}
|
||||
|
||||
function save() {
|
||||
var targetUrl = $.trim($('#targetUrl').val());
|
||||
if (!targetUrl) {
|
||||
alert('Target URL을 입력하여 주십시오.');
|
||||
$('#targetUrl').focus();
|
||||
return;
|
||||
}
|
||||
var names = eventTypes.map(function (code) { return eventTypeName(code); });
|
||||
$('#eventTypes').text(names.join(', '));
|
||||
if (!/^https?:\/\/.+/i.test(targetUrl)) {
|
||||
alert('http:// 또는 https:// 로 시작하는 전체 주소를 입력해주세요.');
|
||||
$('#targetUrl').focus();
|
||||
return;
|
||||
}
|
||||
if ($('input[name=eventTypes]:checked').length === 0) {
|
||||
alert('신청 이벤트를 1개 이상 선택해주세요.');
|
||||
return;
|
||||
}
|
||||
if (confirm("<%= localeMessage.getString("common.checkSave")%>") != true) return;
|
||||
|
||||
var postData = $('#ajaxForm').serializeArray();
|
||||
postData.push({name: 'cmd', value: 'UPDATE'});
|
||||
postData.push({name: 'id', value: key});
|
||||
|
||||
$.ajax({
|
||||
type: "POST", url: url, data: postData,
|
||||
success: function () {
|
||||
alert("<%= localeMessage.getString("common.saveMsg") %>");
|
||||
detail();
|
||||
},
|
||||
error: function (e) { alert(errorMessage(e)); }
|
||||
});
|
||||
}
|
||||
|
||||
function detail() {
|
||||
@@ -65,9 +124,9 @@
|
||||
success: function (data) {
|
||||
$('#id').text(data.id != null ? data.id : '');
|
||||
$('#orgName').text(data.orgName || '');
|
||||
$('#targetUrl').text(data.targetUrl || '');
|
||||
$('#targetUrl').val(data.targetUrl || '');
|
||||
$('#secret').text(data.secret || '');
|
||||
$('#userSecret').text(data.userSecret || '');
|
||||
$('#userSecret').val(data.userSecret || '');
|
||||
$('#createdDate').text(data.createdDate || '');
|
||||
|
||||
renderApiList(data.apiIds);
|
||||
@@ -80,7 +139,10 @@
|
||||
$(document).ready(function () {
|
||||
var returnUrl = getReturnUrlForReturn();
|
||||
|
||||
buttonControl();
|
||||
buttonControl('DETAIL');
|
||||
if (!canWrite) {
|
||||
$('#targetUrl, #userSecret').prop('readonly', true);
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
type: "POST", url: url, dataType: "json",
|
||||
@@ -92,6 +154,7 @@
|
||||
error: function (e) { alert(e.responseText); }
|
||||
});
|
||||
|
||||
$('#btn_modify').click(save);
|
||||
$('#btn_previous').click(function () { goNav(returnUrl); });
|
||||
});
|
||||
</script>
|
||||
@@ -103,9 +166,11 @@
|
||||
</div>
|
||||
<div class="content_middle">
|
||||
<div class="search_wrap">
|
||||
<button type="button" class="cssbtn" id="btn_modify" level="W" status="DETAIL"><i class="material-icons">save</i> <%= localeMessage.getString("button.modify") %></button>
|
||||
<button type="button" class="cssbtn" id="btn_previous" level="R" status="DETAIL,NEW"><i class="material-icons">arrow_back</i> <%= localeMessage.getString("button.previous") %></button>
|
||||
</div>
|
||||
<div class="title" id="title">웹훅 신청내역 상세</div>
|
||||
<form id="ajaxForm" onsubmit="return false;">
|
||||
<table class="table_row" cellspacing="0">
|
||||
<colgroup>
|
||||
<col style="width:12%"/><col style="width:38%"/>
|
||||
@@ -122,8 +187,8 @@
|
||||
<td><span id="createdDate"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Target URL</th>
|
||||
<td colspan="3"><span id="targetUrl"></span></td>
|
||||
<th>Target URL <font color="red">*</font></th>
|
||||
<td colspan="3"><input type="text" id="targetUrl" name="targetUrl" maxlength="255" style="width:100%"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Secret</th>
|
||||
@@ -131,13 +196,14 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th>User Secret</th>
|
||||
<td colspan="3"><span id="userSecret"></span></td>
|
||||
<td colspan="3"><input type="text" id="userSecret" name="userSecret" maxlength="500" style="width:100%" placeholder="미입력 시 User Secret 없음"/></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>신청 이벤트</th>
|
||||
<td colspan="3"><span id="eventTypes"></span></td>
|
||||
<th>신청 이벤트 <font color="red">*</font></th>
|
||||
<td colspan="3"><div id="eventTypes"></div></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<div class="title" style="margin-top:20px;">API 목록</div>
|
||||
<table class="table_row">
|
||||
|
||||
@@ -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