-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Proxy Facts to Java SDK (#523)
* Added Proxy Facts to Java SDK * Added Java examples to PDP Proxy Facts
- Loading branch information
Showing
2 changed files
with
102 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() { | |
} | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="java" label="Java"> | ||
|
||
```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("<your-api-key>") | ||
// 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); | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
|
@@ -202,6 +227,43 @@ func main() { | |
|
||
</TabItem> | ||
|
||
<TabItem value="java" label="Java"> | ||
|
||
```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("<your-api-key>") | ||
.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("[email protected]") | ||
.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); | ||
} | ||
} | ||
``` | ||
|
||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
:::note Supported APIs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters