Skip to content

Commit

Permalink
feat: add ABAC support to OpenFgaClient
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Dec 6, 2023
1 parent 246e75c commit 6ab7079
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 97 deletions.
18 changes: 18 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 2
updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "monthly"
groups:
dependencies:
patterns:
- "*"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
groups:
dependencies:
patterns:
- "*"
3 changes: 3 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.github/CODEOWNERS
.github/ISSUE_TEMPLATE/bug_report.md
.github/ISSUE_TEMPLATE/feature_request.md
.github/dependabot.yaml
.github/workflows/main.yml
.github/workflows/semgrep.yaml
.gitignore
Expand Down Expand Up @@ -112,7 +113,9 @@ src/main/java/dev/openfga/sdk/api/client/ClientReadAuthorizationModelsResponse.j
src/main/java/dev/openfga/sdk/api/client/ClientReadChangesResponse.java
src/main/java/dev/openfga/sdk/api/client/ClientReadRequest.java
src/main/java/dev/openfga/sdk/api/client/ClientReadResponse.java
src/main/java/dev/openfga/sdk/api/client/ClientRelationshipCondition.java
src/main/java/dev/openfga/sdk/api/client/ClientTupleKey.java
src/main/java/dev/openfga/sdk/api/client/ClientTupleKeyWithCondition.java
src/main/java/dev/openfga/sdk/api/client/ClientWriteAssertionsResponse.java
src/main/java/dev/openfga/sdk/api/client/ClientWriteAuthorizationModelResponse.java
src/main/java/dev/openfga/sdk/api/client/ClientWriteRequest.java
Expand Down
2 changes: 1 addition & 1 deletion docs/AuthorizationModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**id** | **String** | | [optional] |
|**id** | **String** | | |
|**schemaVersion** | **String** | | |
|**typeDefinitions** | [**List<TypeDefinition>**](TypeDefinition.md) | | |
|**conditions** | [**Map<String, Condition>**](Condition.md) | | [optional] |
Expand Down
2 changes: 1 addition & 1 deletion docs/RelationshipCondition.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**name** | **String** | A reference (by name) of the relationship condition defined in the authorization model. | |
|**context** | **Object** | Additional context/data to persist along with the condition. The keys must match the parameters defined by the condition, and the value types must match the parameter type definitions. | |
|**context** | **Object** | Additional context/data to persist along with the condition. The keys must match the parameters defined by the condition, and the value types must match the parameter type definitions. | [optional] |



11 changes: 8 additions & 3 deletions src/main/java/dev/openfga/sdk/api/client/ClientCheckRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@

package dev.openfga.sdk.api.client;

import dev.openfga.sdk.api.model.CheckRequestTupleKey;
import java.util.List;

public class ClientCheckRequest {
private String user;
private String relation;
private String _object;
private List<ClientTupleKey> contextualTuples;
private List<ClientTupleKeyWithCondition> contextualTuples;

public CheckRequestTupleKey asCheckRequestTupleKey() {
return new CheckRequestTupleKey().user(user).relation(relation)._object(_object);
}

public ClientCheckRequest _object(String _object) {
this._object = _object;
Expand Down Expand Up @@ -59,12 +64,12 @@ public String getUser() {
return user;
}

public ClientCheckRequest contextualTuples(List<ClientTupleKey> contextualTuples) {
public ClientCheckRequest contextualTuples(List<ClientTupleKeyWithCondition> contextualTuples) {
this.contextualTuples = contextualTuples;
return this;
}

public List<ClientTupleKey> getContextualTuples() {
public List<ClientTupleKeyWithCondition> getContextualTuples() {
return contextualTuples;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ClientListObjectsRequest {
private String user;
private String relation;
private String type;
private List<ClientTupleKey> contextualTupleKeys;
private List<ClientTupleKeyWithCondition> contextualTupleKeys;

public ClientListObjectsRequest user(String user) {
this.user = user;
Expand Down Expand Up @@ -55,12 +55,12 @@ public String getType() {
return type;
}

public ClientListObjectsRequest contextualTupleKeys(List<ClientTupleKey> contextualTupleKeys) {
public ClientListObjectsRequest contextualTupleKeys(List<ClientTupleKeyWithCondition> contextualTupleKeys) {
this.contextualTupleKeys = contextualTupleKeys;
return this;
}

public List<ClientTupleKey> getContextualTupleKeys() {
public List<ClientTupleKeyWithCondition> getContextualTupleKeys() {
return contextualTupleKeys;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 0.1
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.api.client;

import dev.openfga.sdk.api.model.RelationshipCondition;

public class ClientRelationshipCondition {
private String name;
private Object context;

public ClientRelationshipCondition name(String name) {
this.name = name;
return this;
}

public String getName() {
return name;
}

public ClientRelationshipCondition context(Object context) {
this.context = context;
return this;
}

public Object getContext() {
return context;
}

public RelationshipCondition asRelationshipCondition() {
return new RelationshipCondition().name(name).context(context);
}
}
30 changes: 30 additions & 0 deletions src/main/java/dev/openfga/sdk/api/client/ClientTupleKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,27 @@

package dev.openfga.sdk.api.client;

import dev.openfga.sdk.api.model.TupleKeyWithoutCondition;
import dev.openfga.sdk.api.model.WriteRequestDeletes;
import java.util.Collection;
import java.util.stream.Collectors;

public class ClientTupleKey {
private String user;
private String relation;
private String _object;

public TupleKeyWithoutCondition asTupleKeyWithoutCondition() {
return new TupleKeyWithoutCondition().user(user).relation(relation)._object(_object);
}

public static WriteRequestDeletes asWriteRequestDeletes(Collection<ClientTupleKey> tupleKeys) {
return new WriteRequestDeletes()
.tupleKeys(tupleKeys.stream()
.map(ClientTupleKey::asTupleKeyWithoutCondition)
.collect(Collectors.toList()));
}

public ClientTupleKey _object(String _object) {
this._object = _object;
return this;
Expand Down Expand Up @@ -55,4 +71,18 @@ public ClientTupleKey user(String user) {
public String getUser() {
return user;
}

/**
* Adds a condition to the tuple key.
* @param condition a {@link ClientRelationshipCondition}
* @return a new {@link ClientTupleKeyWithCondition} with this {@link ClientTupleKey}'s
* user, relation, and object, and the passed condition.
*/
public ClientTupleKeyWithCondition condition(ClientRelationshipCondition condition) {
return new ClientTupleKeyWithCondition()
.user(user)
.relation(relation)
._object(_object)
.condition(condition);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* OpenFGA
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar.
*
* The version of the OpenAPI document: 0.1
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

package dev.openfga.sdk.api.client;

import dev.openfga.sdk.api.model.ContextualTupleKeys;
import dev.openfga.sdk.api.model.TupleKey;
import dev.openfga.sdk.api.model.WriteRequestWrites;
import java.util.Collection;
import java.util.stream.Collectors;

public class ClientTupleKeyWithCondition extends ClientTupleKey {
private ClientRelationshipCondition condition;

public ClientTupleKeyWithCondition condition(ClientRelationshipCondition condition) {
this.condition = condition;
return this;
}

public ClientRelationshipCondition getCondition() {
return condition;
}

public TupleKey asTupleKey() {
var tupleKey = new TupleKey().user(getUser()).relation(getRelation())._object(getObject());

if (condition != null) {
tupleKey.condition(condition.asRelationshipCondition());
}

return tupleKey;
}

public static ContextualTupleKeys asContextualTupleKeys(Collection<ClientTupleKeyWithCondition> tupleKeys) {
return new ContextualTupleKeys()
.tupleKeys(tupleKeys.stream()
.map(ClientTupleKeyWithCondition::asTupleKey)
.collect(Collectors.toList()));
}

public static WriteRequestWrites asWriteRequestWrites(Collection<ClientTupleKeyWithCondition> tupleKeys) {
return new WriteRequestWrites()
.tupleKeys(tupleKeys.stream()
.map(ClientTupleKeyWithCondition::asTupleKey)
.collect(Collectors.toList()));
}

/* Overrides for correct typing */

@Override
public ClientTupleKeyWithCondition user(String user) {
super.user(user);
return this;
}

@Override
public ClientTupleKeyWithCondition relation(String relation) {
super.relation(relation);
return this;
}

@Override
public ClientTupleKeyWithCondition _object(String _object) {
super._object(_object);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
import java.util.List;

public class ClientWriteRequest {
private List<ClientTupleKey> writes;
private List<ClientTupleKeyWithCondition> writes;
private List<ClientTupleKey> deletes;

public static ClientWriteRequest ofWrites(List<ClientTupleKey> writes) {
public static ClientWriteRequest ofWrites(List<ClientTupleKeyWithCondition> writes) {
return new ClientWriteRequest().writes(writes);
}

public ClientWriteRequest writes(List<ClientTupleKey> writes) {
public ClientWriteRequest writes(List<ClientTupleKeyWithCondition> writes) {
this.writes = writes;
return this;
}

public List<ClientTupleKey> getWrites() {
public List<ClientTupleKeyWithCondition> getWrites() {
return writes;
}

Expand Down
Loading

0 comments on commit 6ab7079

Please sign in to comment.