From 44708b5607fe27543f6081af2741b41caedc3b08 Mon Sep 17 00:00:00 2001 From: Dan Yishai Date: Wed, 26 Feb 2025 14:54:55 +0200 Subject: [PATCH] Added Proxy Facts to Java SDK (#523) * Added Proxy Facts to Java SDK * Added Java examples to PDP Proxy Facts --- .../manage-data/local-facts-uploader.mdx | 64 ++++++++++++++- docs/sdk/sdks-overview.mdx | 78 +++++++++---------- 2 files changed, 102 insertions(+), 40 deletions(-) diff --git a/docs/how-to/manage-data/local-facts-uploader.mdx b/docs/how-to/manage-data/local-facts-uploader.mdx index 4c7c04b1..d7e26b42 100644 --- a/docs/how-to/manage-data/local-facts-uploader.mdx +++ b/docs/how-to/manage-data/local-facts-uploader.mdx @@ -6,7 +6,7 @@ title: Send Critical Updates import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; -When checking permissions right after creating or syncing a user, there may be a delay in data syncing to the PDP. To reduce this latency, weโ€™ve implemented a mechanism that sends data updates directly to the PDP first, then distributes them through OPAL (including other PDPs if you operate in multi-PDP setup). +When checking permissions right after creating or syncing a user, there may be a delay in data syncing to the PDP. To reduce this latency, we've implemented a mechanism that sends data updates directly to the PDP first, then distributes them through OPAL (including other PDPs if you operate in multi-PDP setup). The approach works by making calls directly to the PDP, which then forwards the facts to the connected OPAL Server. The OPAL Server will then distribute the facts to all the PDPs in the environment. The update has been added as a configuration option in the SDK which enables you to use the same favorite SDK to interact with Permit.io as you have previously without changing function calls. This approach will also ensure all other PDPs running in your environment receive those facts by forwarding the facts to the connected OPAL Server which then distributes the facts to all the PDPs in the environment. @@ -84,6 +84,31 @@ func main() { } ``` + + + + +```java +import io.permit.sdk.Permit; +import io.permit.sdk.PermitConfig; + +public class PermitExample { + public static void main(String[] args) { + // Initialize the SDK with your API key and PDP configuration + PermitConfig config = new PermitConfig.Builder("") + // In production, you might need to change this URL to fit your deployment + // This is the address where you can find the PDP container + .withPdpAddress("http://localhost:7766") + // configure the SDK to upload facts via the PDP + .withProxyFactsViaPdp(true) + // Add here any more configurations that you usually use + .build(); + + Permit permit = new Permit(config); + } +} +``` + @@ -202,6 +227,43 @@ func main() { + + +```java +import io.permit.sdk.Permit; +import io.permit.sdk.PermitConfig; +import io.permit.sdk.api.models.UserCreate; + +public class PermitExample { + public static void main(String[] args) { + PermitConfig config = new PermitConfig.Builder("") + .withPdpAddress("http://localhost:7766") + .withProxyFactsViaPdp(true) + // configure the default time to wait for the facts to be synced + .withFactsSyncTimeout(10) + .build(); + + Permit permit = new Permit(config); + + // Create a new user and wait for sync + UserCreate user = new UserCreate.Builder("auth0|elon") + .withEmail("elonmusk@tesla.com") + .withFirstName("Elon") + .withLastName("Musk") + .withAttributes(Map.of( + "age", 50, + "favorite_color", "red" + )) + .build(); + + // Using the default timeout configured in PermitConfig + permit.api.users.sync(user); + } +} +``` + + + :::note Supported APIs diff --git a/docs/sdk/sdks-overview.mdx b/docs/sdk/sdks-overview.mdx index 060195ff..f2d42f17 100644 --- a/docs/sdk/sdks-overview.mdx +++ b/docs/sdk/sdks-overview.mdx @@ -16,45 +16,45 @@ This page lists the feature parity of the different SDKs that we provide to use ๐ŸŸค - Not compatible (The feature cannot be implemented in the language due to language limitations) -| Feature โคต | NodeJS | Go | .NET | Java | Python | Ruby | Terraform | -|--------------------------------|--------|----|------|------|--------|------|-----------| -| Check | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | -| Check All Tenants | โœ… | โœ… | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | -| Get User Permission | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | -| Get User Permission (ABAC) | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | -| Get User Tenant | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | -| List Role Assignments from PDP | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Get Authorized Users | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | โœ… | ๐ŸŸค | -| Get Authorized Users(ABAC) | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Check URL | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | -| Sync User | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | -| Create User | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | -| Create User + Assign Roles | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | -| Users | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸก | โœ… | -| Resources | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸก | โœ… | -| Tenants | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸก | โœ… | -| Projects | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | -| Environments | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | -| Roles | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | โœ… | -| Role Assignments | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | -| Condition Sets | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | โœ… | -| Condition Set Rules | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | โœ… | -| Relationship Tuples | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | -| Resource Relations | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | โœ… | -| Role Derivations | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | -| Resource Instances | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | -| Resource Roles | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | -| Resource Actions | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | โœ… | -| Resource Action Groups | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | -| Resource Attributes | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | โœ… | -| Bulk Check | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Elements Login | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | -| Bulk Users | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Bulk Relationship Tuples | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Bulk Role Assignments | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Bulk Tenants | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Bulk Resource Instances | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | -| Proxy Facts via PDP | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Feature โคต | NodeJS | Go | .NET | Java | Python | Ruby | Terraform | +|--------------------------------|---------|-----|-------|-------|----------|-------|------------| +| Check | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | +| Check All Tenants | โœ… | โœ… | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | +| Get User Permission | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | +| Get User Permission (ABAC) | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | +| Get User Tenant | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | +| List Role Assignments from PDP | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Get Authorized Users | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | โœ… | ๐ŸŸค | +| Get Authorized Users(ABAC) | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Check URL | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | +| Sync User | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | +| Create User | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | +| Create User + Assign Roles | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐ŸŸค | +| Users | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸก | โœ… | +| Resources | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸก | โœ… | +| Tenants | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸก | โœ… | +| Projects | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | +| Environments | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | +| Roles | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | โœ… | +| Role Assignments | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | +| Condition Sets | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | โœ… | +| Condition Set Rules | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | โœ… | +| Relationship Tuples | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | +| Resource Relations | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | โœ… | +| Role Derivations | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | +| Resource Instances | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | +| Resource Roles | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | +| Resource Actions | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | โœ… | +| Resource Action Groups | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | +| Resource Attributes | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | โœ… | +| Bulk Check | โœ… | โœ… | โœ… | โœ… | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Elements Login | โœ… | โœ… | โœ… | โœ… | โœ… | โœ… | ๐ŸŸค | +| Bulk Users | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Bulk Relationship Tuples | โœ… | โœ… | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Bulk Role Assignments | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Bulk Tenants | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Bulk Resource Instances | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | ๐Ÿ”ด | โœ… | ๐Ÿ”ด | ๐ŸŸค | +| Proxy Facts via PDP | โœ… | โœ… | ๐Ÿ”ด | โœ… | โœ… | ๐Ÿ”ด | ๐ŸŸค | :::info Terraform Provider The Terraform provider is not a full SDK, it is a tool to manage Permit.io resources using Terraform. It is not possible to implement all the features of the Permit.io API in Terraform due to Terraform limitations and basic design principles.