Java Data Access SDK

Prev Next

{{snippet.SDKAuthLink}}

The PlainID Data Access SDK is a library that can be used to easily integrate the PlainID's Externalized Authorization capabilities into your applications. The SDK exposes the following PlainID Policy Decision Point Functionality:

  • Resolution Decision - Used to evaluate and enforce PlainID Data Access Policies

Prerequisites

  • Java 1.8+

Installation

Manual Installation of the SDK JAR into a Local Maven Repository

  1. Use the following command:
mvn install:install-file -Dfile=plainid-pdp-sdk-0.0.4.jar -DgroupId=com.plainid -DartifactId=plainid-pdp-sdk -Dversion=0.0.4 -Dpackaging=jar
  1. Now, add the dependency to your Maven project by adding the following lines to your pom.xml file:
<dependency>
    <groupId>com.plainid</groupId>
    <artifactId>pdp-sdk-dto</artifactId>
    <version>0.0.4</version>
</dependency>

Adding the SDK JAR Directly to the Dependency as a System Scope

Make sure that the JAR is located in <PROJECT_ROOT_FOLDER>/lib, and add the dependency to your pom.xml file:

<dependency>
    <groupId>com.plainid</groupId>
    <artifactId>pdp-sdk-dto</artifactId>
    <version>0.0.4</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/pdp-sdk-0.0.4.jar</systemPath>
</dependency>

Usage Example

Configure the PDP Authentication

import com.plainid.pdp.sdk.resolution.request.v3.AuthConfig;
AuthConfig config = AuthConfig.builder()
    .clientId("<client-id>")
    .clientSecret("<client-secret>")
    .build();

Configure the Request Parameters

import com.plainid.pdp.sdk.resolution.v3.request.ResolutionRequestParams;

final ResolutionRequestParams requestParams = ResolutionRequestParams.builder()
        .entityId("john.doe@gmail.com")
        .entityTypeId("User")
        .timeZoneOffset(3)
        .remoteIp("1.2.2.1")
        .environment("key1", Arrays.asList("val1", "val2"))
        .contextData("key", Arrays.asList("string"))
        .entityAttributes("key", Arrays.asList("string1", "string2"))
        .resourceTypes(ResourceType.builder()
                .name("name")
                .attributeList("att1")
                .attributeList("att2")
                .build())
        .assetList(AssetListEntity.builder()
                .template("temp1")
                .path("asset_path_1")
                .assetAttributes("key1", Arrays.asList("string", true, 3))
                .build())
        .includeAssetAttributes(true)
        .includeAccessPolicy(true)
        .includeIdentity(true)
        .includeContext(true)
        .useCache(false)
        .timestamp(new Date())
        .build();

AppEnforcerProperties - configuration on how to read and parse the resolution response.

It is possible to use either the default values, or override them by adding resolutionAttributes:

import com.plainid.pdp.sdk.client.v3.parser.ResolutionProperties;

final AppEnforcerProperties enforcerProperties = AppEnforcerProperties.builder()
    .resolutionAttributeProjectId("projectid")
    .resolutionAttributeDataset("dataset")
    .resolutionAttributeTable("table")
    .resolutionAttributeColumn("column")
    .build();

Call the Client

import com.plainid.pdp.sdk.client.v3.PolicyResolutionClient;
import com.plainid.pdp.sdk.client.v3.PolicyResolution;
import com.plainid.pdp.sdk.resolution.response.v3.PolicyResolutionResponse;

PolicyResolutionClient client = new PolicyResolutionClient(config, "https://<host>:<port>");

// With default AppEnforcerProperties
PolicyResolution policyResolution = client.getPolicyResolutionInstance();

// Or with overriden AppEnforcerProperties:
PolicyResolution policyResolution = client.getPolicyResolutionInstance(appEnforcerProperties);

PolicyResolutionResponse PolicyResolutionResponse = policyResolution.getPolicyResolution(requestParams);

Or with overriding default values for AppEnforcerProperties:

PolicyResolution policyResolution = client.getPolicyResolutionInstance(appEnforcerProperties);
PolicyResolutionResponse PolicyResolutionResponse = policyResolution.getPolicyResolution(requestParams);