Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"CamelAwsSecurityHubUnprocessedFindings": { "index": 17, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List<BatchUpdateFindingsUnprocessedFinding>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were not updated", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#UNPROCESSED_FINDINGS" },
"CamelAwsSecurityHubProcessedFindings": { "index": 18, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List<AwsSecurityFindingIdentifier>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were updated successfully", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PROCESSED_FINDINGS" },
"CamelAwsSecurityHubFindingId": { "index": 19, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The finding ID to get history for", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_ID" },
"CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" }
"CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" },
"CamelAwsSecurityHubFindingAggregatorArn": { "index": 21, "kind": "header", "displayName": "", "group": "getFindingAggregator", "label": "getFindingAggregator", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The ARN of the finding aggregator to retrieve", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_AGGREGATOR_ARN" }
},
"properties": {
"label": { "index": 0, "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Logical name" },
Expand Down
6 changes: 6 additions & 0 deletions components/camel-aws/camel-aws-security-hub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<artifactId>camel-test-spring-junit6</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito-version}</version>
<scope>test</scope>
</dependency>
<!-- test infra -->
<dependency>
<groupId>org.apache.camel</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"CamelAwsSecurityHubUnprocessedFindings": { "index": 17, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List<BatchUpdateFindingsUnprocessedFinding>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were not updated", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#UNPROCESSED_FINDINGS" },
"CamelAwsSecurityHubProcessedFindings": { "index": 18, "kind": "header", "displayName": "", "group": "batchUpdateFindings", "label": "batchUpdateFindings", "required": false, "javaType": "List<AwsSecurityFindingIdentifier>", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The list of findings that were updated successfully", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PROCESSED_FINDINGS" },
"CamelAwsSecurityHubFindingId": { "index": 19, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The finding ID to get history for", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_ID" },
"CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" }
"CamelAwsSecurityHubProductArn": { "index": 20, "kind": "header", "displayName": "", "group": "getFindingHistory", "label": "getFindingHistory", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The product ARN for the finding", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#PRODUCT_ARN" },
"CamelAwsSecurityHubFindingAggregatorArn": { "index": 21, "kind": "header", "displayName": "", "group": "getFindingAggregator", "label": "getFindingAggregator", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The ARN of the finding aggregator to retrieve", "constantName": "org.apache.camel.component.aws.securityhub.SecurityHubConstants#FINDING_AGGREGATOR_ARN" }
},
"properties": {
"label": { "index": 0, "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Logical name" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ public interface SecurityHubConstants {
@Metadata(label = "getFindingHistory",
description = "The product ARN for the finding", javaType = "String")
String PRODUCT_ARN = "CamelAwsSecurityHubProductArn";

@Metadata(label = "getFindingAggregator",
description = "The ARN of the finding aggregator to retrieve", javaType = "String")
String FINDING_AGGREGATOR_ARN = "CamelAwsSecurityHubFindingAggregatorArn";
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import software.amazon.awssdk.services.securityhub.model.BatchUpdateFindingsResponse;
import software.amazon.awssdk.services.securityhub.model.DescribeHubRequest;
import software.amazon.awssdk.services.securityhub.model.DescribeHubResponse;
import software.amazon.awssdk.services.securityhub.model.GetFindingAggregatorRequest;
import software.amazon.awssdk.services.securityhub.model.GetFindingHistoryRequest;
import software.amazon.awssdk.services.securityhub.model.GetFindingHistoryResponse;
import software.amazon.awssdk.services.securityhub.model.GetFindingsRequest;
Expand Down Expand Up @@ -94,6 +95,9 @@ public void process(Exchange exchange) throws Exception {
case listEnabledProductsForImport:
listEnabledProductsForImport(getEndpoint().getSecurityHubClient(), exchange);
break;
case getFindingAggregator:
getFindingAggregator(getEndpoint().getSecurityHubClient(), exchange);
break;
default:
throw new IllegalArgumentException("Unsupported operation");
}
Expand Down Expand Up @@ -292,6 +296,25 @@ private void getFindingHistory(SecurityHubClient securityHubClient, Exchange exc
});
}

private void getFindingAggregator(SecurityHubClient securityHubClient, Exchange exchange)
throws InvalidPayloadException {
executeOperation(
exchange,
GetFindingAggregatorRequest.class,
securityHubClient::getFindingAggregator,
() -> {
String findingAggregatorArn
= exchange.getIn().getHeader(SecurityHubConstants.FINDING_AGGREGATOR_ARN, String.class);
if (ObjectHelper.isEmpty(findingAggregatorArn)) {
throw new IllegalArgumentException("Finding Aggregator ARN must be specified");
}
GetFindingAggregatorRequest.Builder builder = GetFindingAggregatorRequest.builder();
builder.findingAggregatorArn(findingAggregatorArn);
return securityHubClient.getFindingAggregator(builder.build());
},
"Get Finding Aggregator");
}

private void describeHub(SecurityHubClient securityHubClient, Exchange exchange) throws InvalidPayloadException {
executeOperation(
exchange,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.aws.securityhub;

import org.apache.camel.BindToRegistry;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import software.amazon.awssdk.services.securityhub.SecurityHubClient;
import software.amazon.awssdk.services.securityhub.model.GetFindingAggregatorRequest;
import software.amazon.awssdk.services.securityhub.model.GetFindingAggregatorResponse;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class SecurityHubGetFindingAggregatorTest extends CamelTestSupport {

private static final String AGGREGATOR_ARN
= "arn:aws:securityhub:eu-west-1:123456789012:finding-aggregator/abcd";

@BindToRegistry("securityHubClient")
private final SecurityHubClient securityHubClient = mock(SecurityHubClient.class);

@Test
public void getFindingAggregatorIsSupportedAndUsesTheArnHeader() throws Exception {
when(securityHubClient.getFindingAggregator(any(GetFindingAggregatorRequest.class)))
.thenReturn(GetFindingAggregatorResponse.builder().findingAggregatorArn(AGGREGATOR_ARN).build());

// Before the fix this operation fell through to "Unsupported operation".
template.send("direct:start",
exchange -> exchange.getIn().setHeader(SecurityHubConstants.FINDING_AGGREGATOR_ARN, AGGREGATOR_ARN));

ArgumentCaptor<GetFindingAggregatorRequest> captor
= ArgumentCaptor.forClass(GetFindingAggregatorRequest.class);
verify(securityHubClient).getFindingAggregator(captor.capture());
assertEquals(AGGREGATOR_ARN, captor.getValue().findingAggregatorArn());
}

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
from("direct:start")
.to("aws-security-hub://test?securityHubClient=#securityHubClient&operation=getFindingAggregator");
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,19 @@ public String awsSecurityHubFindingId() {
public String awsSecurityHubProductArn() {
return "CamelAwsSecurityHubProductArn";
}
/**
* The ARN of the finding aggregator to retrieve.
*
* The option is a: {@code String} type.
*
* Group: getFindingAggregator
*
* @return the name of the header {@code
* AwsSecurityHubFindingAggregatorArn}.
*/
public String awsSecurityHubFindingAggregatorArn() {
return "CamelAwsSecurityHubFindingAggregatorArn";
}
}
static SecurityHubEndpointBuilder endpointBuilder(String componentName, String path) {
class SecurityHubEndpointBuilderImpl extends AbstractEndpointBuilder implements SecurityHubEndpointBuilder, AdvancedSecurityHubEndpointBuilder {
Expand Down