Skip to main content

Verify RequestShield tokens with Java

If you are new to RequestShield, start with the Introduction.

RequestShield Backend SDK verifies tokens received from the Browser SDK and returns the decision that the application backend must enforce. The SDK client is configured once and invoked before each protected operation.

Prerequisites

  • Java 8 or newer.
  • The App Key used by the Browser SDK.
  • The backend-only API Secret supplied by IntelliFend.
  • Access to the IntelliFend Maven repository.
ValueWhere to use itDescription
App KeyBrowser and backendPublic application identifier. The same value must be configured in both SDKs.
API SecretBackend onlyPrivate credential used by the Backend SDK. Store it in a secret manager.

The API Secret must not be exposed in browser code, client-visible responses, source control, or logs.

1. Add the Java dependency

Configure the IntelliFend Maven repository and declare IntelliFend Client 1.3.0.

Maven

pom.xml
<repositories>
<repository>
<id>intellifend-maven</id>
<url>https://sdk.intellifend.com/packages/maven</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.intellifend.sdk</groupId>
<artifactId>intellifend-client</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>

Gradle

build.gradle.kts
repositories {
maven {
url = uri("https://sdk.intellifend.com/packages/maven")
}
}

dependencies {
implementation("com.intellifend.sdk:intellifend-client:1.3.0")
}

The IntelliFend Client includes the compatible RequestShield Backend SDK. A separate RequestShield dependency is not required.

2. Configure the client

Create one RequestShieldClient for each App Key and reuse it across requests:

import com.intellifend.requestshield.RequestShieldClient;

RequestShieldClient requestShield = RequestShieldClient.builder()
.appKey(System.getenv("REQUESTSHIELD_APP_KEY"))
.apiSecret(System.getenv("REQUESTSHIELD_API_SECRET"))
.build();
Builder methodRequiredDescription
appKey(String)YesSets the same public App Key used by the Browser SDK.
apiSecret(String)YesSets the backend-only API Secret. Pass the supplied value unchanged.
build()N/AValidates the configuration and returns a thread-safe client.

3. Verify a protected request

Read the token from the request and pass it directly to verify():

import com.intellifend.requestshield.VerificationResult;

String token = request.getHeader("X-IntelliFend-Token");
VerificationResult result = requestShield.verify(token);

if (!result.isAllowed()) {
rejectRequest();
return;
}

continueRequest();

Pass the request header value unchanged to verify(), including an empty string. The method returns the decision that the application backend must enforce.

important

result.isAllowed() must be enforced before running the protected operation. The Browser SDK result is not an access-control decision.

Verification result

verify(String token) returns a VerificationResult:

MethodReturnsDescription
isAllowed()booleanReturns whether the backend should continue processing the request.
getReason()VerificationReasonReturns the stable reason for the decision.

getReason() returns one of the following enum values. getCode() returns the corresponding lowercase value for controlled diagnostics and metrics.

VerificationReasongetCode()isAllowed()Meaning
OKoktrueToken verification and consume succeeded.
MISSING_TOKENmissing_tokenfalseThe request did not contain a token.
UNKNOWN_CUSTOMERunknown_customerfalseThe token belongs to a different App Key.
TOKEN_TAMPEREDtoken_tamperedfalseThe token is malformed, altered, or otherwise invalid.
TOKEN_EXPIREDtoken_expiredfalseThe token is outside its validity period.
TOKEN_REPLAYEDtoken_replayedfalseThe token was already consumed.
CONSUME_UNAUTHORIZEDconsume_unauthorizedfalseThe consume service rejected the configured API Secret.
INVALID_REQUESTinvalid_requestfalseThe service rejected the SDK request as invalid.
NOT_FOUNDnot_foundfalseThe configured service endpoint was not found.
SERVICE_UNAVAILABLEservice_unavailabletrueProtection was unavailable and the fixed fail-open policy was applied.

SERVICE_UNAVAILABLE is the only non-OK reason associated with an allowed result.

Use result.getReason().getCode() for controlled diagnostics and metrics. The value returned by isAllowed() must not be overridden based on a reason code.

Security requirements

  • The API Secret must remain in backend secret storage.
  • The same App Key must be configured in the Browser SDK and Backend SDK.
  • Obtain and verify a fresh token for every protected request.
  • Pass the token value unchanged to verify().
  • Enforce isAllowed() before processing the protected operation.
  • Raw tokens, decoded claims, and the API Secret must not be logged or persisted.