> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shieldlabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Java

> Read and evaluate a stored identification, then verify raw-body webhook signatures in your backend.

Read and evaluate a stored identification, then verify raw-body webhook signatures in your backend. This guide uses the supported ShieldLabs package API, not a standalone generated client.

## Before you start

Java 11+, Maven or Gradle, and a Private API Key. The SDK uses Jackson for JSON.

Register and verify the website domain in your [analytics dashboard](https://app.shieldlabs.ai/). Use credentials from the same domain and environment as the browser check. For a fresh account, start with [Quick Start](/quickstart).

## Get your credentials

Copy the domain's **Private API Key** from **Integration > API keys** and store it as `SHIELDLABS_API_KEY` in your server environment. For webhook verification, also set `SHIELDLABS_WEBHOOK_SECRET` from **Integration > Webhooks**. Never expose either secret to the browser.

## Install the SDK

```xml theme={null}
<dependency>
  <groupId>ai.shieldlabs</groupId>
  <artifactId>shieldlabs-java</artifactId>
  <version>1.0.0</version>
</dependency>
```

Version 1.0.0 is shown as an installable baseline; use the latest published stable version when upgrading.

## Add the integration

Save this as `QuickStart.java` in a project that depends on `shieldlabs-java`:

```java theme={null}
import ai.shieldlabs.EvaluateOptions;
import ai.shieldlabs.Evaluation;
import ai.shieldlabs.Identification;
import ai.shieldlabs.IdentificationScoredEvent;
import ai.shieldlabs.Risk;
import ai.shieldlabs.ShieldLabsClient;
import ai.shieldlabs.WebhookEvent;
import ai.shieldlabs.Webhooks;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public final class QuickStart {
    // Reads SHIELDLABS_API_KEY: the Private API Key of your domain (sec_...).
    private final ShieldLabsClient shieldlabs = ShieldLabsClient.fromEnvironment();

    // One identification authorizes one action. This in-memory set keeps the example short;
    // in production, claim request IDs atomically in your database or cache.
    private final Set<String> usedRequestIds = ConcurrentHashMap.newKeySet();

    // 1. Call this with the requestId the browser sent together with the signup form.
    public boolean allowSignup(String requestId) {
        // Scoring is asynchronous: this waits (up to 10 seconds by default) until the verdict is stored.
        Optional<Identification> identification = shieldlabs.identifications().get(requestId);

        // 2. Missing, reused, stale, rate limited, no device signals, browser automation
        //    or the dangerous band: refuse, or route to review or a step-up check.
        Evaluation evaluation = Risk.evaluate(
                identification.orElse(null),
                EvaluateOptions.builder().replayCheck(id -> !usedRequestIds.add(id)).build());
        evaluation.getReason().ifPresent(reason -> System.out.println("refused: " + reason.getValue()));
        return evaluation.isOk();
    }

    // 3. Call this with the raw body and the X-Shield-Signature header of a webhook delivery.
    public void handleWebhook(byte[] rawBody, String signatureHeader) {
        WebhookEvent event = Webhooks.constructEvent(
                rawBody, signatureHeader, System.getenv("SHIELDLABS_WEBHOOK_SECRET")); // whsec_...
        if (event instanceof IdentificationScoredEvent) {
            Identification scored = ((IdentificationScoredEvent) event).getIdentification();
            System.out.println(scored.getRequestId() + " " + scored.getRiskScore());
        }
    }

    public static void main(String[] args) {
        String requestId = args[0]; // a request ID your page received from the browser SDK
        System.out.println(new QuickStart().allowSignup(requestId) ? "allowed" : "refused");
    }
}
```

Run it with `SHIELDLABS_API_KEY` set and a request ID as the argument. A runnable backend with both halves (a signup guard and a webhook receiver) lives in [`examples/httpserver`](https://github.com/ShieldLabs-ai/shieldlabs-java/tree/c7aa045a2cb0b7d3e59226f811b03207a4499a7b/examples/httpserver).

## Test the complete flow

1. Use the Request ID from a real browser check on the same domain as the Private API Key.
2. Confirm the server retrieves that identification and its Risk Score.
3. Test an invalid or missing ID and an unavailable API: none should be treated as a clean identification.
4. For webhooks, test the original raw body with its signature, then change one byte and confirm rejection.

In-memory replay stores in examples are demonstrations, not shared production storage. Claim accepted IDs atomically in a durable database or cache, enforce freshness, authenticate the action, and check the expected domain and user association. Reading a valid identification alone does not authorize a business action.

## Troubleshooting

* No History row: confirm the registered domain, credential/environment match and that the browser remained open while collectors posted.
* Missing or pending verdict: scoring is asynchronous. The server helper waits within a bounded budget; handle a missing result and API errors explicitly.
* Authentication error: use the Private API Key for History, not a Public Key, Management Secret Key or MCP OAuth token.
* Invalid webhook signature: verify the original raw bytes with the endpoint's full signing secret, before trusting parsed JSON.

## Next steps

* [Runnable example](https://github.com/ShieldLabs-ai/shieldlabs-java/tree/c7aa045a2cb0b7d3e59226f811b03207a4499a7b/examples/httpserver)
* [SDK reference and changelog](https://github.com/ShieldLabs-ai/shieldlabs-java)
* [Identification flow](/api/identification-flow)
* [Server API](/api/server-api)
* [Webhook setup](/setup/webhooks)
* [Content Security Policy](/setup/csp)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.