Search in sources :

Example 31 with Source

use of com.google.cloud.securitycenter.v1.Source in project ORCID-Source by ORCID.

the class OrcidSecurityManagerTestBase method setSource.

protected void setSource(SourceAware element, String sourceId) {
    Source source = new Source();
    source.setSourceClientId(new SourceClientId(sourceId));
    element.setSource(source);
}
Also used : SourceClientId(org.orcid.jaxb.model.common_v2.SourceClientId) Source(org.orcid.jaxb.model.common_v2.Source)

Example 32 with Source

use of com.google.cloud.securitycenter.v1.Source in project ORCID-Source by ORCID.

the class RecordManagerReadOnlyImpl method getHistory.

private History getHistory(String orcid) {
    History history = new History();
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    history.setClaimed(profile.getClaimed());
    if (profile.getCompletedDate() != null) {
        history.setCompletionDate(new CompletionDate(DateUtils.convertToXMLGregorianCalendar(profile.getCompletedDate())));
    }
    if (!PojoUtil.isEmpty(profile.getCreationMethod())) {
        history.setCreationMethod(CreationMethod.fromValue(profile.getCreationMethod()));
    }
    if (profile.getDeactivationDate() != null) {
        history.setDeactivationDate(new DeactivationDate(DateUtils.convertToXMLGregorianCalendar(profile.getDeactivationDate())));
    }
    if (profile.getLastModified() != null) {
        history.setLastModifiedDate(new LastModifiedDate(DateUtils.convertToXMLGregorianCalendar(profile.getLastModified())));
    }
    if (profile.getSubmissionDate() != null) {
        history.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(profile.getSubmissionDate())));
    }
    if (profile.getSource() != null) {
        history.setSource(new Source(profile.getSource().getSourceId()));
    }
    boolean verfiedEmail = false;
    boolean verfiedPrimaryEmail = false;
    Emails emails = emailManager.getEmails(orcid);
    if (emails != null) {
        for (Email email : emails.getEmails()) {
            if (email.isVerified()) {
                verfiedEmail = true;
                if (email.isPrimary()) {
                    verfiedPrimaryEmail = true;
                    break;
                }
            }
        }
    }
    history.setVerifiedEmail(verfiedEmail);
    history.setVerifiedPrimaryEmail(verfiedPrimaryEmail);
    return history;
}
Also used : LastModifiedDate(org.orcid.jaxb.model.common_v2.LastModifiedDate) Email(org.orcid.jaxb.model.record_v2.Email) Emails(org.orcid.jaxb.model.record_v2.Emails) History(org.orcid.jaxb.model.record_v2.History) SubmissionDate(org.orcid.jaxb.model.record_v2.SubmissionDate) CompletionDate(org.orcid.jaxb.model.record_v2.CompletionDate) DeactivationDate(org.orcid.jaxb.model.record_v2.DeactivationDate) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Source(org.orcid.jaxb.model.common_v2.Source)

Example 33 with Source

use of com.google.cloud.securitycenter.v1.Source in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method listFindingsAtTime.

// [END securitycenter_list_filtered_findings]
/**
 * List findings at a specific time under a source.
 *
 * @param sourceName The source to list findings at a specific time for.
 */
// [START securitycenter_list_findings_at_time]
static ImmutableList<ListFindingsResult> listFindingsAtTime(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organizationId=*/"123234324",
        // /*sourceId=*/"423432321");
        // 5 days ago
        Instant fiveDaysAgo = Instant.now().minus(Duration.ofDays(5));
        ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString()).setReadTime(Timestamp.newBuilder().setSeconds(fiveDaysAgo.getEpochSecond()).setNanos(fiveDaysAgo.getNano()));
        // Call the API.
        ListFindingsPagedResponse response = client.listFindings(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 in incrementally
        // by returning the Iterable returned response.iterateAll() directly.
        ImmutableList<ListFindingsResult> 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 : Instant(org.threeten.bp.Instant) 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)

Example 34 with Source

use of com.google.cloud.securitycenter.v1.Source in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method listAllFindings.

// [END securitycenter_update_finding_state]
/**
 * List all findings under an organization.
 *
 * @param organizationName The source to list all findings for.
 */
// [START securitycenter_list_all_findings]
static ImmutableList<ListFindingsResult> listAllFindings(OrganizationName organizationName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // OrganizationName organizationName = OrganizationName.of(/*organizationId=*/"123234324");
        // "-" Indicates listing across all sources.
        SourceName sourceName = SourceName.of(organizationName.getOrganization(), "-");
        ListFindingsRequest.Builder request = ListFindingsRequest.newBuilder().setParent(sourceName.toString());
        // Call the API.
        ListFindingsPagedResponse response = client.listFindings(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 in incrementally
        // by returning the Iterable returned response.iterateAll() directly.
        ImmutableList<ListFindingsResult> 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 : SourceName(com.google.cloud.securitycenter.v1.SourceName) 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)

Example 35 with Source

use of com.google.cloud.securitycenter.v1.Source in project google-cloud-java by GoogleCloudPlatform.

the class FindingSnippets method groupActiveFindingsWithSource.

// [END securitycenter_group_findings_with_source]
/**
 * Group active findings under an organization and a source by their specified properties (e.g.
 * category).
 *
 * @param sourceName The source to limit the findings to.
 */
// [START securitycenter_group_active_findings_with_source]
static ImmutableList<GroupResult> groupActiveFindingsWithSource(SourceName sourceName) {
    try (SecurityCenterClient client = SecurityCenterClient.create()) {
        // SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
        // "423432321");
        GroupFindingsRequest.Builder request = GroupFindingsRequest.newBuilder().setParent(sourceName.toString()).setGroupBy("category").setFilter("state=\"ACTIVE\"");
        // 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)

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