arunsrajan commented on code in PR #26010:
URL: https://github.com/apache/camel/pull/26010#discussion_r3913340288


##########
components/camel-alibaba/camel-alibaba-eventbridge/src/main/java/org/apache/camel/component/alibaba/eventbridge/AlibabaEventBridgeUtils.java:
##########
@@ -62,117 +74,346 @@ public static EventBridgeClient 
createClient(AlibabaEventBridgeEndpoint endpoint
     }
 
     public static ClientConfigurations 
createClientConfigurations(AlibabaEventBridgeEndpoint endpoint, Exchange 
exchange) {
-        ClientConfigurations configuration = new ClientConfigurations();
-        configuration.setOperation(
-                OpenApiClientSupport.resolveString(exchange, 
AlibabaEventBridgeProperties.OPERATION, endpoint.getOperation()));
-        configuration.setEventBusName(
-                OpenApiClientSupport.resolveString(exchange, 
AlibabaEventBridgeProperties.EVENT_BUS_NAME,
-                        endpoint.getEventBusName()));
-        configuration.setEventSource(
+        String defaultBusName = OpenApiClientSupport.resolveString(
+                exchange, AlibabaEventBridgeProperties.EVENT_BUS_NAME, 
endpoint.getEventBusName());
+
+        return new ClientConfigurations(
+                OpenApiClientSupport.resolveString(exchange, 
AlibabaEventBridgeProperties.OPERATION, endpoint.getOperation()),
+                defaultBusName,
                 OpenApiClientSupport.resolveString(exchange, 
AlibabaEventBridgeProperties.EVENT_SOURCE,
-                        endpoint.getEventSource()));
-        configuration.setEventType(
-                OpenApiClientSupport.resolveString(exchange, 
AlibabaEventBridgeProperties.EVENT_TYPE, endpoint.getEventType()));
-        configuration.setEventSubject(
+                        endpoint.getEventSource()),
+                OpenApiClientSupport.resolveString(exchange, 
AlibabaEventBridgeProperties.EVENT_TYPE, endpoint.getEventType()),
                 OpenApiClientSupport.resolveString(exchange, 
AlibabaEventBridgeProperties.EVENT_SUBJECT,
-                        endpoint.getEventSubject()));
-        return configuration;
+                        endpoint.getEventSubject()),
+                OpenApiClientSupport.resolveBoolean(exchange, 
AlibabaEventBridgeProperties.VALIDATE_EVENT_SOURCE,
+                        endpoint.isValidateEventSource()),
+                OpenApiClientSupport.resolveBoolean(exchange, 
AlibabaEventBridgeProperties.VALIDATE_EVENT_TYPE,
+                        endpoint.isValidateEventType()),
+                OpenApiClientSupport.resolveBoolean(exchange, 
AlibabaEventBridgeProperties.VALIDATE_EVENT_SPEC,
+                        endpoint.isValidateEventSpec()),
+                resolveAllowedEventBuses(exchange, 
AlibabaEventBridgeProperties.ALLOWED_EVENT_SOURCES,
+                        endpoint.getAllowedEventSources(), defaultBusName),
+                OpenApiClientSupport.resolveLong(exchange, 
AlibabaEventBridgeProperties.EVENT_SOURCE_CACHE_TTL,
+                        endpoint.getEventSourceCacheTtl()));
     }
 
     public static List<CloudEvent> resolveCloudEvents(Exchange exchange, 
ClientConfigurations configuration) {
+        return resolveCloudEvents(exchange, configuration, null, null);
+    }
+
+    public static List<CloudEvent> resolveCloudEvents(
+            Exchange exchange, ClientConfigurations configuration,
+            EventSourceCache eventSourceCache, EventBridgeClient client) {
         Object body = exchange.getMessage().getBody();
         List<CloudEvent> events = new ArrayList<>();
+        MapCloudEventValidator mapValidator = new 
MapCloudEventValidator(eventSourceCache);
 
         if (body instanceof List<?> listBody) {
             for (Object item : listBody) {
-                events.add(toCloudEvent(item, configuration));
+                events.add(toCloudEvent(item, configuration, mapValidator, 
client));
             }
             return events;
         }
 
-        events.add(toCloudEvent(body, configuration));
+        events.add(toCloudEvent(body, configuration, mapValidator, client));
         return events;
     }
 
-    private static CloudEvent toCloudEvent(Object body, ClientConfigurations 
configuration) {
+    private static CloudEvent toCloudEvent(
+            Object body, ClientConfigurations configuration,
+            MapCloudEventValidator mapValidator, EventBridgeClient client) {
         if (body instanceof CloudEvent cloudEvent) {
+            mapValidator.validateCloudEvent(cloudEvent, configuration, client);
             return cloudEvent;
         }
 
         if (body instanceof Map<?, ?> mapBody) {
-            String eventBusName
-                    = 
stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_BUS_NAME), 
configuration.getEventBusName());
-            String source = 
stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_SOURCE), 
configuration.getEventSource());
-            String type = 
stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_TYPE), 
configuration.getEventType());
-            String subject
-                    = 
stringValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_SUBJECT), 
configuration.getEventSubject());
-            String data = 
jsonDataValue(mapBody.get(AlibabaEventBridgeConstants.EVENT_DATA));
-
-            if (ObjectHelper.isEmpty(source) || ObjectHelper.isEmpty(type) || 
ObjectHelper.isEmpty(eventBusName)) {
-                throw new IllegalArgumentException("Event source, type and 
event bus name are required");
-            }
-
-            EventBuilder builder = EventBuilder.builder()
-                    .withSource(URI.create(source))
-                    .withType(type)
-                    .withAliyunEventBus(eventBusName);
-
-            if (ObjectHelper.isNotEmpty(subject)) {
-                builder.withSubject(subject);
-            }
-            if (data != null) {
-                builder.withJsonStringData(data);
-            }
-            return builder.build();
+            return mapValidator.validateAndBuild(mapBody, configuration, 
client);
         }
 
         if (body instanceof String stringBody) {
-            if (ObjectHelper.isEmpty(configuration.getEventSource())
-                    || ObjectHelper.isEmpty(configuration.getEventType())
-                    || ObjectHelper.isEmpty(configuration.getEventBusName())) {
+            if (ObjectHelper.isEmpty(configuration.eventSource())
+                    || ObjectHelper.isEmpty(configuration.eventType())
+                    || ObjectHelper.isEmpty(configuration.eventBusName())) {
                 throw new IllegalArgumentException("Event source, type and 
event bus name are required when body is a string");
             }
 
+            mapValidator.validateBusSourceAndType(
+                    configuration.eventBusName(), configuration.eventSource(), 
configuration.eventType(),
+                    configuration, client);
+
             EventBuilder builder = EventBuilder.builder()

Review Comment:
   Good catch. Added an `[IMPORTANT]` security callout in 
`alibaba-eventbridge-component.adoc` documenting that Camel message headers 
take precedence over URI options. 
   
   For routes processing untrusted external ingress (such as HTTP webhooks or 
public queues), we explicitly recommend stripping `CamelAlibabaEventBridge*` 
headers (e.g. `.removeHeaders("CamelAlibabaEventBridge*")`) before the producer 
to prevent untrusted callers from overriding endpoint whitelist policies.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to