Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for Java SDK #615

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/markdown.links.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
},
{
"pattern": "^https://www.linkedin.com"
},
{
"pattern": "https://gradle.org/"
},
{
"pattern": "https://github.com/openfga/java-sdk"
},
{
"pattern": "https://maven.apache.org/"
}
],
"httpHeaders": [
Expand Down
2 changes: 1 addition & 1 deletion docs/content/authorization-and-openfga.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This section explains [authorization](#authentication-vs-authorization), [fine-g

## What Is OpenFGA?

**OpenFGA** is an open source solution to [Fine-Grained Authorization](#what-is-fine-grained-authorization-fga) that applies the concept of [ReBAC](#what-is-relationship-based-access-control-rebac). It was created by the [Okta FGA](https://docs.fga.dev/) team and was inspired by [Zanzibar](#what-is-zanzibar). It was designed for reliability and low latency at a high scale. It offers an HTTP API and has SDKs for programming languages including [Node.js/JavaScript](https://www.npmjs.com/package/@openfga/sdk), [GoLang](https://github.com/openfga/go-sdk), [.NET](https://www.nuget.org/packages/OpenFga.Sdk) and [Python](https://pypi.org/project/openfga-sdk). More SDKs and integrations such as Rego are planned for the future.
**OpenFGA** is an open source solution to [Fine-Grained Authorization](#what-is-fine-grained-authorization-fga) that applies the concept of [ReBAC](#what-is-relationship-based-access-control-rebac). It was created by the [Okta FGA](https://docs.fga.dev/) team and was inspired by [Zanzibar](#what-is-zanzibar). It was designed for reliability and low latency at a high scale. It offers an HTTP API and has SDKs for programming languages including [Node.js/JavaScript](https://www.npmjs.com/package/@openfga/sdk), [GoLang](https://github.com/openfga/go-sdk), [.NET](https://www.nuget.org/packages/OpenFga.Sdk), [Python](https://pypi.org/project/openfga-sdk), [Java](https://central.sonatype.com/artifact/dev.openfga/openfga-sdk). More SDKs and integrations such as Rego are planned for the future.

<Playground intro={true} />

Expand Down
9 changes: 9 additions & 0 deletions docs/content/getting-started/configure-model.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ This article explains how to configure an <ProductConcept section="what-is-an-au

</TabItem>

<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

1. <SdkSetupPrerequisite />
2. You have [installed the SDK](./install-sdk.mdx), [created the store](./create-store.mdx) and [setup the SDK client](./setup-sdk-client.mdx).
3. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>

<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

1. <SdkSetupPrerequisite />
Expand Down Expand Up @@ -148,6 +156,7 @@ To configure authorization model, we can invoke the [write authorization models
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand Down
23 changes: 23 additions & 0 deletions docs/content/getting-started/create-store.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ asyncio.run(main())

</TabItem>

<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

```java
import dev.openfga.sdk.api.client.OpenFgaClient;
import dev.openfga.sdk.api.configuration.ClientConfiguration;
import dev.openfga.sdk.api.model.CreateStoreRequest;

public class Example {
public static void main(String[] args) {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "https://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")); // Optional, can be overridden per request

var fgaClient = new OpenFgaClient(config);
var body = new CreateStoreRequest().name("FGA Demo Store");
var store = fgaClient.createStore(body).get();
}
}
```

</TabItem>

<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

```shell
Expand Down
26 changes: 26 additions & 0 deletions docs/content/getting-started/install-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,27 @@ In your code, import the module and use it:
import openfga_sdk
```

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

You can find the Java package on [Maven Central](https://central.sonatype.com/artifact/dev.openfga/openfga-sdk).

Using [Maven](https://maven.apache.org/):

```
<dependency>
<groupId>dev.openfga</groupId>
<artifactId>openfga-sdk</artifactId>
<version>0.3.1</version>
</dependency>
```

Using [Gradle](https://gradle.org/):

```groovy
implementation 'dev.openfga:openfga-sdk:0.3.1'
```

</TabItem>
<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

Expand Down Expand Up @@ -196,5 +217,10 @@ Download the pre-compiled binaries from the [releases page](https://github.com/o
description: 'Connect your Python service with {ProductName} using our Python SDK',
link: 'https://github.com/openfga/python-sdk',
},
{
title: '{ProductName} Java SDK',
description: 'Connect your Java service with {ProductName} using our Java SDK',
link: 'https://github.com/openfga/java-sdk',
}
]}
/>
15 changes: 15 additions & 0 deletions docs/content/getting-started/perform-check.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ This section will illustrate how to perform a <ProductConcept section="what-is-a

</TabItem>

<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

1. <SdkSetupPrerequisite />
2. You have [installed the SDK](./install-sdk.mdx).
3. You have [configured the _authorization model_](./configure-model.mdx) and [updated the _relationship tuples_](./update-tuples.mdx).
4. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>

<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

1. <SdkSetupPrerequisite />
Expand Down Expand Up @@ -111,6 +120,11 @@ Before calling the check API, you will need to configure the API client.

<SdkSetupHeader lang={SupportedLanguage.PYTHON_SDK} />

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

<SdkSetupHeader lang={SupportedLanguage.JAVA_SDK} />

</TabItem>
<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

Expand Down Expand Up @@ -141,6 +155,7 @@ To check whether user `user:anne` has relationship `reader` with object `documen
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand Down
16 changes: 16 additions & 0 deletions docs/content/getting-started/perform-list-objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ This section will illustrate how to perform a <ProductConcept section="what-is-a
4. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>

<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

1. <SdkSetupPrerequisite />
2. You have [installed the SDK](./install-sdk.mdx).
3. You have [configured the _authorization model_](./configure-model.mdx) and [updated the _relationship tuples_](./update-tuples.mdx).
4. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>

<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

1. <SdkSetupPrerequisite />
Expand Down Expand Up @@ -110,6 +120,11 @@ Before calling the check API, you will need to configure the API client.

<SdkSetupHeader lang={SupportedLanguage.PYTHON_SDK} />

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

<SdkSetupHeader lang={SupportedLanguage.JAVA_SDK} />

</TabItem>
<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

Expand Down Expand Up @@ -141,6 +156,7 @@ To return all documents that user `user:anne` has relationship `reader` with:
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand Down
73 changes: 73 additions & 0 deletions docs/content/getting-started/setup-sdk-client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,27 @@ asyncio.run(main())
```

</TabItem>

<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

```java
import dev.openfga.sdk.api.client.OpenFgaClient;
import dev.openfga.sdk.api.configuration.ClientConfiguration;

public class Example {
public static void main(String[] args) {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "https://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")); // Optional, can be overridden per request

var fgaClient = new OpenFgaClient(config);
}
}
```

</TabItem>

<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

```shell
Expand Down Expand Up @@ -245,6 +266,30 @@ async def main():
asyncio.run(main())
```

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

```java
import dev.openfga.sdk.api.client.OpenFgaClient;
import dev.openfga.sdk.api.configuration.ApiToken;
import dev.openfga.sdk.api.configuration.ClientConfiguration;
import dev.openfga.sdk.api.configuration.Credentials;

public class Example {
public static void main(String[] args) {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "https://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")) // Optional, can be overridden per request
.credentials(new Credentials(
new ApiToken(System.getenv("FGA_API_TOKEN")) // will be passed as the "Authorization: Bearer ${ApiToken}" request header
));

var fgaClient = new OpenFgaClient(config);
}
}
```

</TabItem>
<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

Expand Down Expand Up @@ -388,6 +433,34 @@ async def main():
asyncio.run(main())
```

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

```java
import dev.openfga.sdk.api.client.OpenFgaClient;
import dev.openfga.sdk.api.configuration.ClientConfiguration;
import dev.openfga.sdk.api.configuration.ClientCredentials;
import dev.openfga.sdk.api.configuration.Credentials;

public class Example {
public static void main(String[] args) {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "https://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")) // Optional, can be overridden per request
.credentials(new Credentials(
new ClientCredentials()
.apiTokenIssuer(System.getenv("FGA_API_TOKEN_ISSUER"))
.apiAudience(System.getenv("FGA_API_AUDIENCE"))
.clientId(System.getenv("FGA_CLIENT_ID"))
.clientSecret(System.getenv("FGA_CLIENT_SECRET"))
));

var fgaClient = new OpenFgaClient(config);
}
}
```

</TabItem>
<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

Expand Down
15 changes: 15 additions & 0 deletions docs/content/getting-started/update-tuples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ This section will illustrate how to update _<ProductConcept section="what-is-a-r
3. You have [configured the _authorization model_](./configure-model.mdx).
4. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

1. <SdkSetupPrerequisite />
2. You have [installed the SDK](./install-sdk.mdx).
3. You have [configured the _authorization model_](./configure-model.mdx).
4. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>
<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

Expand Down Expand Up @@ -113,6 +121,11 @@ Before calling the write API, you will need to configure the API client.

<SdkSetupHeader lang={SupportedLanguage.PYTHON_SDK} />

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

<SdkSetupHeader lang={SupportedLanguage.JAVA_SDK} />

</TabItem>
<TabItem value={SupportedLanguage.CLI} label={languageLabelMap.get(SupportedLanguage.CLI)}>

Expand Down Expand Up @@ -146,6 +159,7 @@ To add the relationship tuples, we can invoke the write API.
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand Down Expand Up @@ -179,6 +193,7 @@ Assume that you want to delete user `user:anne`'s `reader` relationship with obj
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand Down
19 changes: 19 additions & 0 deletions docs/content/interacting/read-tuple-changes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ This section illustrates how to call the Read Changes API to get the list of rel
3. You have [configured the _authorization model_](../modeling).
4. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>
<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

1. <SdkSetupPrerequisite />
2. You have [installed the SDK](../getting-started/install-sdk.mdx).
3. You have [configured the _authorization model_](../modeling).
4. You have loaded `FGA_STORE_ID` and `FGA_API_HOST` as environment variables.

</TabItem>
<TabItem value={SupportedLanguage.CURL} label={languageLabelMap.get(SupportedLanguage.CURL)}>

Expand Down Expand Up @@ -102,6 +110,13 @@ First you will need to configure the API client.

</TabItem>

<TabItem value={SupportedLanguage.JAVA_SDK} label={languageLabelMap.get(SupportedLanguage.JAVA_SDK)}>

<SdkSetupHeader lang="java-sdk" />

</TabItem>


<TabItem value={SupportedLanguage.CURL} label={languageLabelMap.get(SupportedLanguage.CURL)}>

To obtain the [access token](https://auth0.com/docs/authorization/flows/call-your-api-using-the-client-credentials-flow):
Expand All @@ -124,6 +139,7 @@ To get a paginated list of changes that happened in your store:
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand All @@ -142,6 +158,7 @@ You can then use this token to get the next set of changes:
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand Down Expand Up @@ -222,6 +239,7 @@ It is possible to get a list of changes that happened in your store that relate
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand All @@ -239,6 +257,7 @@ The response will include a continuation token. In subsequent calls, you have to
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CLI,
SupportedLanguage.CURL,
]}
Expand Down
1 change: 1 addition & 0 deletions docs/content/interacting/transactional-writes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ The Write API allows you to send up to 10 unique tuples in the request. (This li
SupportedLanguage.GO_SDK,
SupportedLanguage.DOTNET_SDK,
SupportedLanguage.PYTHON_SDK,
SupportedLanguage.JAVA_SDK,
SupportedLanguage.CURL,
SupportedLanguage.RPC,
]}
Expand Down
Loading
Loading