|
|
@@ -0,0 +1,32 @@
|
|
|
+package com.etotem.cfc.service.mcp;
|
|
|
+
|
|
|
+import com.etotem.cfc.config.McpConfig;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class McpAuthService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private McpConfig mcpConfig;
|
|
|
+
|
|
|
+ public boolean validate(String apiKeyHeader) {
|
|
|
+ if (apiKeyHeader == null || apiKeyHeader.isEmpty()) {
|
|
|
+ log.warn("[MCP] 缺少 Mcp-Api-Key 请求头");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String expected = mcpConfig.getApiKey();
|
|
|
+ if (expected == null || expected.isEmpty()) {
|
|
|
+ log.warn("[MCP] 未配置 mcp.api-key,所有请求被拒绝");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ boolean ok = expected.equals(apiKeyHeader);
|
|
|
+ if (!ok) {
|
|
|
+ log.warn("[MCP] Mcp-Api-Key 不匹配");
|
|
|
+ }
|
|
|
+ return ok;
|
|
|
+ }
|
|
|
+}
|