Skip navigation links

Package com.contrastsecurity.sdk.scan

Contrast SDK package for integrating with Contrast Scan (SAST) service.

See: Description

Package com.contrastsecurity.sdk.scan Description

Contrast SDK package for integrating with Contrast Scan (SAST) service. Users should obtain an entrypoint to the Contrast Scan manager using ContrastSDK.scan(java.lang.String).

Sample:

ContrastSDK contrast =
    new ContrastSDK.Builder("username", "my-service-key", "my-api-key").build();
ScanManager scanManager = contrast.scan("organization-id");

Projects projects = scanManager.projects();
Project project =
    projects
        .findByName("spring-test-application")
        .orElseGet(
            () -> {
              try {
                return projects
                    .define()
                    .withName("spring-test-application")
                    .withLanguage("JAVA")
                    .create();
              } catch (IOException e) {
                throw new UncheckedIOException(e);
              }
            });
Path file = Paths.get("./target/spring-test-application.jar");
CodeArtifact codeArtifact = project.codeArtifacts().upload(file);
Scan scan = project.scans().define().withExistingCodeArtifact(codeArtifact).create();
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
try {
  scan.await(scheduler)
      .thenAccept(
          s -> {
            try {
              s.saveSarif(Paths.get("./contrast-scan-results.sarif.json"));
              ScanSummary summary = s.summary();
              System.out.printf("Found %d total results%n", summary.totalResults());
            } catch (IOException e) {
              throw new UncheckedIOException(e);
            }
          })
      .toCompletableFuture()
      .join();
} finally {
  scheduler.shutdown();
}
Since:
3.2
Skip navigation links

Copyright © 2021 Contrast Security, Inc.. All rights reserved.