Search in sources :

Example 11 with Source

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)))));
    }
}
Also used : NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) IntFunction(java.util.function.IntFunction) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Notification(org.orcid.jaxb.model.notification_v2.Notification) Source(org.orcid.jaxb.model.common_v2.Source) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 12 with Source

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);
    }
}
Also used : GroupFindingsRequest(com.google.cloud.securitycenter.v1.GroupFindingsRequest) GroupResult(com.google.cloud.securitycenter.v1.GroupResult) GroupFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 13 with Source

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);
    }
}
Also used : Instant(org.threeten.bp.Instant) Finding(com.google.cloud.securitycenter.v1.Finding) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 14 with Source

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);
    }
}
Also used : TestIamPermissionsResponse(com.google.iam.v1.TestIamPermissionsResponse) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient)

Example 15 with Source

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);
    }
}
Also used : ListFindingsRequest(com.google.cloud.securitycenter.v1.ListFindingsRequest) IOException(java.io.IOException) SecurityCenterClient(com.google.cloud.securitycenter.v1.SecurityCenterClient) ListFindingsPagedResponse(com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse) ListFindingsResult(com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)

Aggregations

SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)20 IOException (java.io.IOException)20 Test (org.junit.Test)17 Source (hex.glm.GLM2.Source)11 Source (org.orcid.jaxb.model.common_v2.Source)10 Instant (org.threeten.bp.Instant)6 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)5 Finding (com.google.cloud.securitycenter.v1.Finding)4 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)4 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)4 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)4 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)4 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)4 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)4 Source (com.google.cloud.securitycenter.v1.Source)4 FieldMask (com.google.protobuf.FieldMask)3 SourceName (org.orcid.jaxb.model.common_v2.SourceName)3 Items (org.orcid.jaxb.model.notification.permission_v2.Items)3 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)3 Policy (com.google.iam.v1.Policy)2