From 4e8c2271b5dcc5207d4831d065abcdede39eb6dc Mon Sep 17 00:00:00 2001 From: jade Date: Tue, 4 Aug 2026 22:24:11 +0900 Subject: [PATCH] Delete ToolSourceUpdater.java for security --- .../dap/lib/util/ToolSourceUpdater.java | 123 ------------------ .../src/main/resources/application-local.yml | 2 +- .../src/main/resources/application-local.yml | 2 +- 3 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 dap-was-lib/src/main/java/io/shinhanlife/dap/lib/util/ToolSourceUpdater.java diff --git a/dap-was-lib/src/main/java/io/shinhanlife/dap/lib/util/ToolSourceUpdater.java b/dap-was-lib/src/main/java/io/shinhanlife/dap/lib/util/ToolSourceUpdater.java deleted file mode 100644 index b1a0796f9..000000000 --- a/dap-was-lib/src/main/java/io/shinhanlife/dap/lib/util/ToolSourceUpdater.java +++ /dev/null @@ -1,123 +0,0 @@ -package io.shinhanlife.dap.lib.util; - - -/** - * @package io.shinhanlife.dap.lib.util - * @className ToolSourceUpdater - * @description AX HUB 시스템 처리 클래스 - * @author 0986406 - * @create 2026.09.01 - *
- * ---------- 개정이력 ----------
- * 수정일      수정자    수정내용
- * ---------- -------- ---------------------------
- * 2026.09.01  0986406    최초생성
- * 
- * 
- */ -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class ToolSourceUpdater { - - public static void updateToolSource(String toolName, String domainGroup, String description, boolean register, Boolean requiresApproval) throws Exception { - // 1. Find all *UseCase.java files in dap-was-* directories - String envSourceDir = System.getenv("AXHUB_SOURCE_DIR"); - Path rootDir = envSourceDir != null ? Paths.get(envSourceDir) : Paths.get("."); - - List javaFiles; - try (Stream paths = Files.walk(rootDir)) { - javaFiles = paths - .filter(Files::isRegularFile) - .filter(p -> p.toString().endsWith("UseCase.java")) - .filter(p -> p.toString().contains("dap-was-") || p.toString().contains("axhub-tool-")) - .collect(Collectors.toList()); - } - - Path targetFile = null; - String content = null; - - // 2. Find the specific file for the tool - String functionName = toolName; - if (toolName.contains("_")) { - functionName = toolName.substring(toolName.indexOf("_") + 1); - } - - Pattern namePattern = Pattern.compile("@McpFunction\\s*\\([^)]*name\\s*=\\s*\"" + Pattern.quote(toolName) + "\"", Pattern.DOTALL); - Pattern namePattern2 = Pattern.compile("@McpFunction\\s*\\([^)]*name\\s*=\\s*\"" + Pattern.quote(functionName) + "\"", Pattern.DOTALL); - - for (Path path : javaFiles) { - String text = Files.readString(path); - if (namePattern.matcher(text).find()) { - targetFile = path; - content = text; - break; - } else if (namePattern2.matcher(text).find()) { - targetFile = path; - content = text; - toolName = functionName; // Use baseName for subsequent replacements - break; - } - } - - if (targetFile == null) { - throw new Exception("소스 코드를 찾을 수 없습니다: " + toolName); - } - - // 3. Update @McpTool group - if (domainGroup != null && !domainGroup.trim().isEmpty()) { - Pattern groupPattern = Pattern.compile("(@McpTool\\s*\\([^)]*group\\s*=\\s*\")([^\"]+)(\")", Pattern.DOTALL); - Matcher groupMatcher = groupPattern.matcher(content); - if (groupMatcher.find()) { - content = groupMatcher.replaceFirst("$1" + domainGroup + "$3"); - } - } - - // 4. Update @McpFunction description - if (description != null) { - Pattern funcPattern = Pattern.compile("(@McpFunction\\s*\\([^)]*name\\s*=\\s*\"" + Pattern.quote(toolName) + "\"[^)]*description\\s*=\\s*\")([^\"]+)(\")", Pattern.DOTALL); - Matcher funcMatcher = funcPattern.matcher(content); - if (funcMatcher.find()) { - content = funcMatcher.replaceFirst("$1" + description.replace("\\", "\\\\").replace("$", "\\\\$") + "$3"); - } - } - - // 5. Update register flag - Pattern regPattern = Pattern.compile("(@McpFunction\\s*\\([^)]*name\\s*=\\s*\"" + Pattern.quote(toolName) + "\"[^)]*register\\s*=\\s*)(true|false)([^a-zA-Z0-9])", Pattern.DOTALL); - Matcher regMatcher = regPattern.matcher(content); - if (regMatcher.find()) { - content = regMatcher.replaceFirst("$1" + register + "$3"); - } else { - Pattern addRegPattern = Pattern.compile("(@McpFunction\\s*\\([^)]*name\\s*=\\s*\"" + Pattern.quote(toolName) + "\")", Pattern.DOTALL); - Matcher addRegMatcher = addRegPattern.matcher(content); - if (addRegMatcher.find()) { - content = addRegMatcher.replaceFirst("$1, register = " + register); - } - } - - // 5.5 Update requiresApproval flag - if (requiresApproval != null) { - Pattern appPattern = Pattern.compile("(@McpFunction\\s*\\([^)]*name\\s*=\\s*\"" + Pattern.quote(toolName) + "\"[^)]*requiresApproval\\s*=\\s*)(true|false)([^a-zA-Z0-9])", Pattern.DOTALL); - Matcher appMatcher = appPattern.matcher(content); - if (appMatcher.find()) { - content = appMatcher.replaceFirst("$1" + requiresApproval + "$3"); - } else { - Pattern addAppPattern = Pattern.compile("(@McpFunction\\s*\\([^)]*name\\s*=\\s*\"" + Pattern.quote(toolName) + "\")", Pattern.DOTALL); - Matcher addAppMatcher = addAppPattern.matcher(content); - if (addAppMatcher.find()) { - content = addAppMatcher.replaceFirst("$1, requiresApproval = " + requiresApproval); - } - } - } - - // 6. Write back to file - Files.writeString(targetFile, content); - } -} diff --git a/dap-was-oth/src/main/resources/application-local.yml b/dap-was-oth/src/main/resources/application-local.yml index b2a4b39d3..1bf04bfb0 100644 --- a/dap-was-oth/src/main/resources/application-local.yml +++ b/dap-was-oth/src/main/resources/application-local.yml @@ -4,7 +4,7 @@ spring: url: jdbc:p6spy:h2:mem:testdb;DB_CLOSE_DELAY=-1; driverClassName: com.p6spy.engine.spy.P6SpyDriver username: sa - password: password + password: ${REDIS_PASSWORD:} h2: console: enabled: true diff --git a/dap-was-sms/src/main/resources/application-local.yml b/dap-was-sms/src/main/resources/application-local.yml index 284418349..833d4fa62 100644 --- a/dap-was-sms/src/main/resources/application-local.yml +++ b/dap-was-sms/src/main/resources/application-local.yml @@ -4,7 +4,7 @@ spring: url: jdbc:p6spy:h2:mem:testdb;DB_CLOSE_DELAY=-1; driverClassName: com.p6spy.engine.spy.P6SpyDriver username: sa - password: password + password: ${REDIS_PASSWORD:} h2: console: enabled: true