# Class ShieldConfig

java.lang.Object
com.codename1.security.shield.ShieldConfig

public final class ShieldConfig extends Object

Configuration for `AppShield.init(ShieldConfig)`. Chainable.

    AppShield.init(new ShieldConfig()
        .protect("api.mybank.example", HostPolicy.PROTECTED)
        .protect("*.mybank.example", HostPolicy.PROTECTED));

The defaults are chosen so that adding the shield to an existing app changes nothing until hosts are explicitly protected: no host is touched, failures are open, and signal collection is on because reporting costs nothing and is what makes the service useful.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `DEFAULT_TOKEN_HEADER`
  Header that carries the attestation token.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ShieldConfig()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ShieldConfig`
  `collectSignals(boolean collect)`
  Whether to gather runtime self-protection observations.
  `ShieldConfig`
  `defaultFailureMode(FailureMode mode)`
  The failure mode applied to hosts registered without an explicit one.
  `ShieldConfig`
  `endpoint(String url)`
  Overrides the attestation service endpoint.
  `FailureMode`
  `getDefaultFailureMode()`
  `String`
  `getEndpoint()`
  `int`
  `getRefreshThresholdPercent()`
  `String`
  `getTokenHeader()`
  `boolean`
  `hasProtectedHosts()`
  True when at least one host is registered, so callers can skip work entirely.
  `boolean`
  `isCollectSignals()`
  `HostPolicy`
  `policyFor(String host)`
  Resolves a host to its policy: exact match first, then the nearest `*.` wildcard, then `HostPolicy.UNPROTECTED`.
  `ShieldConfig`
  `protect(String hostPattern)`
  Registers a host with the default policy, which honours `defaultFailureMode(FailureMode)`.
  `ShieldConfig`
  `protect(String hostPattern, HostPolicy policy)`
  Registers a host to protect.
  `Enumeration`
  `protectedHosts()`
  The registered host patterns, explicit and implicit alike.
  `ShieldConfig`
  `refreshThresholdPercent(int percent)`
  How far through a token's lifetime to trigger a background refresh, as a percentage.
  `ShieldConfig`
  `tokenHeader(String name)`
  Overrides the header used to carry the token.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### DEFAULT_TOKEN_HEADER

    public static final String DEFAULT_TOKEN_HEADER

    Header that carries the attestation token.

    Deliberately not `Authorization`: that slot belongs to the app's own user authentication, and the two answer different questions -- who the user is, versus whether this is a genuine unmodified app on an uncompromised device. A backend needs both, so they must compose.

    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### ShieldConfig

    public ShieldConfig()

- ## Method Details

  - ### endpoint

    public ShieldConfig endpoint(String url)
    Overrides the attestation service endpoint. Only needed for a private deployment or a test double.

  - ### tokenHeader

    public ShieldConfig tokenHeader(String name)

    Overrides the header used to carry the token. Change this only if it collides with something already in use on your backend.

    `Content-Type` is refused. `ConnectionRequest.addRequestHeader(String, String)` special-cases that name into the request's own content type rather than the header map, so the token would replace the request's media type and -- because the removal path only clears the map -- would survive a redirect to an unprotected host and be handed to it. A leak with no symptom on the way there.

    Throws:
      `IllegalArgumentException` - if the name cannot carry a token safely

  - ### defaultFailureMode

    public ShieldConfig defaultFailureMode(FailureMode mode)
    The failure mode applied to hosts registered without an explicit one.

  - ### refreshThresholdPercent

    public ShieldConfig refreshThresholdPercent(int percent)
    How far through a token's lifetime to trigger a background refresh, as a percentage. Refreshing early is what stops a request ever having to wait on the network.

  - ### collectSignals

    public ShieldConfig collectSignals(boolean collect)
    Whether to gather runtime self-protection observations. On by default; they ride along with the token fetch, so there is no extra request and no extra battery cost.

  - ### protect

    public ShieldConfig protect(String hostPattern, HostPolicy policy)
    Registers a host to protect. Accepts an exact host or a leading `*.` wildcard covering its subdomains. Hosts not registered here are never touched.

  - ### protect

    public ShieldConfig protect(String hostPattern)
    Registers a host with the default policy, which honours `defaultFailureMode(FailureMode)`.

  - ### getEndpoint

    public String getEndpoint()

  - ### getTokenHeader

    public String getTokenHeader()

  - ### getDefaultFailureMode

    public FailureMode getDefaultFailureMode()

  - ### getRefreshThresholdPercent

    public int getRefreshThresholdPercent()

  - ### isCollectSignals

    public boolean isCollectSignals()

  - ### policyFor

    public HostPolicy policyFor(String host)
    Resolves a host to its policy: exact match first, then the nearest `*.` wildcard, then `HostPolicy.UNPROTECTED`. Never returns null.

  - ### hasProtectedHosts

    public boolean hasProtectedHosts()
    True when at least one host is registered, so callers can skip work entirely.

  - ### protectedHosts

    public Enumeration protectedHosts()
    The registered host patterns, explicit and implicit alike.