use of com.google.cloud.securitycenter.v1.Source in project ORCID-Source by ORCID.
the class NotificationManagerTest method filterActionedNotificationAlertsTest.
@Test
public void filterActionedNotificationAlertsTest() {
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
when(mockNotificationDao.findByOricdAndId(Matchers.anyString(), Matchers.anyLong())).thenReturn(null);
List<Notification> notifications = IntStream.range(0, 10).mapToObj(new IntFunction<Notification>() {
@Override
public Notification apply(int value) {
if (value % 3 == 0) {
NotificationInstitutionalConnection n = new NotificationInstitutionalConnection();
n.setSource(new Source("0000-0000-0000-0000"));
n.setPutCode(Long.valueOf(value));
return n;
} else {
NotificationPermission n = new NotificationPermission();
n.setPutCode(Long.valueOf(value));
return n;
}
}
}).collect(Collectors.toList());
assertEquals(10, notifications.size());
notifications = notificationManager.filterActionedNotificationAlerts(notifications, "some-orcid");
assertEquals(6, notifications.size());
for (Notification n : notifications) {
assertEquals(NotificationType.PERMISSION, n.getNotificationType());
assertNotNull(n.getPutCode());
assertThat(n.getPutCode(), not(anyOf(is(Long.valueOf(0)), is(Long.valueOf(3)), is(Long.valueOf(6)), is(Long.valueOf(9)))));
}
}
use of com.google.cloud.securitycenter.v1.Source in project google-cloud-java by GoogleCloudPlatform.
the class FindingSnippets method groupActiveFindingsWithSourceAndCompareDuration.
// [END securitycenter_group_active_findings_with_source_at_time]
/**
* Group active findings under an organization and a source by their state_changes
* (ADDED/CHANGED/UNCHANGED) during a period.
*
* @param sourceName The source to limit the findings to.
*/
// [START securitycenter_group_active_findings_with_source_and_compare_duration]
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAndCompareDuration(SourceName sourceName, Duration duration) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
GroupFindingsRequest.Builder request = GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("state_change").setFilter("state=\"ACTIVE\"");
request.getCompareDurationBuilder().setSeconds(duration.getSeconds()).setNanos(duration.getNano());
// Call the API.
GroupFindingsPagedResponse response = client.groupFindings(request.build());
// This creates one list for all findings. If your organization has a large number of
// findings
// this can cause out of memory issues. You can process them batches by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Findings:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.securitycenter.v1.Source in project google-cloud-java by GoogleCloudPlatform.
the class FindingSnippets method setFindingState.
// [END securitycenter_update_finding_source_properties]
/**
* Updates a finding's state to INACTIVE.
*
* @param findingName The finding to update.
*/
// [START securitycenter_update_finding_state]
static Finding setFindingState(FindingName findingName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// FindingName findingName = FindingName.of(/*organization=*/"123234324",
// /*source=*/"423432321", /*findingId=*/"samplefindingid2");
// Use the current time as the finding "event time".
Instant eventTime = Instant.now();
Finding response = client.setFindingState(findingName, State.INACTIVE, Timestamp.newBuilder().setSeconds(eventTime.getEpochSecond()).setNanos(eventTime.getNano()).build());
System.out.println("Updated Finding: " + response);
return response;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.securitycenter.v1.Source in project google-cloud-java by GoogleCloudPlatform.
the class FindingSnippets method testIamPermissions.
// [END securitycenter_list_findings_at_time]
/**
* Demonstrate calling testIamPermissions to determin if the service account has the correct
* permissions.
*
* @param sourceName The source to create a finding for.
*/
// [START securitycenter_test_iam]
static TestIamPermissionsResponse testIamPermissions(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
// /*sourceId=*/"423432321");
// Iam permission to test.
List<String> permissionsToTest = new ArrayList<>();
permissionsToTest.add("securitycenter.findings.update");
// Call the API.
TestIamPermissionsResponse response = client.testIamPermissions(sourceName.toString(), permissionsToTest);
System.out.println("IAM Permission:");
System.out.println(response);
return response;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.securitycenter.v1.Source in project google-cloud-java by GoogleCloudPlatform.
the class SecurityMarkSnippets method listFindingsWithQueryMarks.
// [END securitycenter_list_assets_with_security_marks]
/**
* List all findings with a filter on security marks.
*
* @param sourceName The source to list filtered findings for.
*/
// [START securitycenter_list_findings_with_security_marks]
static ImmutableList<ListFindingsResult> listFindingsWithQueryMarks(SourceName sourceName) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// Start setting up a request for to list all findings filtered by a specific security mark.
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
String filter = "NOT security_marks.marks.key_a=\"value_a\"";
ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString()).setFilter(filter);
// Call the API.
ListFindingsPagedResponse response = client.listFindings(request.build());
// This creates one list for all findings in the filter.If your organization has a large
// number of
// findings this can cause out of memory issues. You can process them batches by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<ListFindingsResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Findings with security mark - key_a=value_a:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
Aggregations