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

Update to support OpenFGA 1.4.3 #109

Merged
merged 1 commit into from
Feb 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
public class DevServicesOpenFGAProcessor {

private static final Logger log = Logger.getLogger(DevServicesOpenFGAProcessor.class);
static final String OPEN_FGA_VERSION = "v1.0.1";
static final String OPEN_FGA_VERSION = "v1.4.3";
static final String OPEN_FGA_IMAGE = "openfga/openfga:" + OPEN_FGA_VERSION;
static final int OPEN_FGA_EXPOSED_HTTP_PORT = 8080;
static final int OPEN_FGA_EXPOSED_GRPC_PORT = 8081;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void createTestStoreAndModel() {
Map.of("reader", new RelationMetadata(List.of(new RelationReference("user"))),
"writer", new RelationMetadata(List.of(new RelationReference("user"))))));

var typeDefs = new TypeDefinitions(List.of(useTypeDef, documentTypeDef));
var typeDefs = new TypeDefinitions("1.1", List.of(useTypeDef, documentTypeDef));

var authModelId = storeClient.authorizationModels().create(typeDefs)
.subscribe().withSubscriber(UniAssertSubscriber.create())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void canList() {
new Metadata(
Map.of("reader", new RelationMetadata(List.of(new RelationReference("user"))))));

var typeDefinitions = new TypeDefinitions(List.of(userTypeDef, documentTypeDef));
var typeDefinitions = new TypeDefinitions("1.1", List.of(userTypeDef, documentTypeDef));

for (int c = 0; c < 4; c++) {
authorizationModelsClient.create(typeDefinitions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public void createTestStoreAndModel() {
Map.of("reader", new RelationMetadata(List.of(new RelationReference("user"))),
"writer", new RelationMetadata(List.of(new RelationReference("user"))))));

storeClient.authorizationModels().create(List.of(userTypeDef, documentTypeDef))
var documentTypeDefs = new TypeDefinitions("1.1", List.of(userTypeDef, documentTypeDef));

storeClient.authorizationModels().create(documentTypeDefs)
.subscribe().withSubscriber(UniAssertSubscriber.create())
.awaitItem()
.getItem();
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/test/resources/auth-model.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"schema_version": "1.1",
"type_definitions": [
{
"type": "user"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkiverse.openfga.client.model;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import javax.annotation.Nullable;
Expand All @@ -13,12 +14,16 @@ public final class AuthorizationModel {
private final String id;
private final String schemaVersion;
private final List<TypeDefinition> typeDefinitions;
@Nullable
private final Map<String, Condition> conditions;

public AuthorizationModel(String id, @JsonProperty("schema_version") String schemaVersion,
@JsonProperty("type_definitions") List<TypeDefinition> typeDefinitions) {
@JsonProperty("type_definitions") List<TypeDefinition> typeDefinitions,
@JsonProperty("conditions") @Nullable Map<String, Condition> conditions) {
this.id = Preconditions.parameterNonNull(id, "id");
this.schemaVersion = Preconditions.parameterNonNull(schemaVersion, "schemaVersion");
this.typeDefinitions = Preconditions.parameterNonNull(typeDefinitions, "typeDefinitions");
this.conditions = conditions;
}

public String getId() {
Expand All @@ -35,6 +40,12 @@ public List<TypeDefinition> getTypeDefinitions() {
return typeDefinitions;
}

@JsonProperty("conditions")
@Nullable
public Map<String, Condition> getConditions() {
return conditions;
}

@Override
public boolean equals(@Nullable Object obj) {
if (obj == this)
Expand All @@ -43,19 +54,21 @@ public boolean equals(@Nullable Object obj) {
return false;
var that = (AuthorizationModel) obj;
return Objects.equals(this.id, that.id) &&
Objects.equals(this.typeDefinitions, that.typeDefinitions);
Objects.equals(this.typeDefinitions, that.typeDefinitions) &&
Objects.equals(this.conditions, that.conditions);
}

@Override
public int hashCode() {
return Objects.hash(id, typeDefinitions);
return Objects.hash(id, typeDefinitions, conditions);
}

@Override
public String toString() {
return "AuthorizationModel[" +
"id=" + id + ", " +
"typeDefinitions=" + typeDefinitions + ']';
"typeDefinitions=" + typeDefinitions + ", " +
"conditions=" + conditions + ']';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package io.quarkiverse.openfga.client.model;

import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Condition {

public static class Parameter {

private final String typeName;
private final List<String> genericTypes;

public Parameter(@JsonProperty("type_name") String typeName, @JsonProperty("generic_types") List<String> genericTypes) {
this.typeName = typeName;
this.genericTypes = genericTypes;
}

@JsonProperty("type_name")
public String getTypeName() {
return typeName;
}

@JsonProperty("generic_types")
public List<String> getGenericTypes() {
return genericTypes;
}
}

private final String name;
private final String expression;
private final Map<String, Parameter> parameters;

public Condition(String name, String expression, Map<String, Parameter> parameters) {
this.name = name;
this.expression = expression;
this.parameters = parameters;
}

public String getName() {
return name;
}

public String getExpression() {
return expression;
}

public Map<String, Parameter> getParameters() {
return parameters;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Condition condition = (Condition) o;
return Objects.equals(name, condition.name) && Objects.equals(expression, condition.expression)
&& Objects.equals(parameters, condition.parameters);
}

@Override
public int hashCode() {
return Objects.hash(name, expression, parameters);
}

@Override
public String toString() {
return "Condition{" +
"name='" + name + '\'' +
", expression='" + expression + '\'' +
", parameters=" + parameters +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ public class RelationReference {
String relation;
@Nullable
Object wildcard;
@Nullable
String condition;

@JsonCreator
public RelationReference(String type, @Nullable String relation, @Nullable Object wildcard) {
public RelationReference(String type, @Nullable String relation, @Nullable Object wildcard, @Nullable String condition) {
this.type = type;
this.relation = relation;
this.wildcard = wildcard;
this.condition = condition;
}

public RelationReference(String type) {
this(type, null, null);
this(type, null, null, null);
}

public RelationReference(String type, String relation) {
this(type, relation, null);
this(type, relation, null, null);
}

public String getType() {
Expand All @@ -42,6 +45,11 @@ public Object getWildcard() {
return wildcard;
}

@Nullable
public String getCondition() {
return condition;
}

@Override
public boolean equals(Object o) {
if (this == o)
Expand All @@ -50,20 +58,21 @@ public boolean equals(Object o) {
return false;
RelationReference that = (RelationReference) o;
return Objects.equals(type, that.type) && Objects.equals(relation, that.relation)
&& Objects.equals(wildcard, that.wildcard);
&& Objects.equals(wildcard, that.wildcard) && Objects.equals(condition, that.condition);
}

@Override
public int hashCode() {
return Objects.hash(type, relation, wildcard);
return Objects.hash(type, relation, wildcard, condition);
}

@Override
public String toString() {
return "RelationReference{" +
"type='" + type + '\'' +
", relation='" + relation + '\'' +
", wildcard=" + wildcard +
", wildcard=" + wildcard + '\'' +
", condition='" + condition + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkiverse.openfga.client.model;

import java.util.Objects;

public class RelationshipCondition {

private final String name;
private final Object context;

public RelationshipCondition(String name, Object context) {
this.name = name;
this.context = context;
}

public String getName() {
return name;
}

public Object getContext() {
return context;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
RelationshipCondition that = (RelationshipCondition) o;
return Objects.equals(name, that.name) && Objects.equals(context, that.context);
}

@Override
public int hashCode() {
return Objects.hash(name, context);
}

@Override
public String toString() {
return "RelationshipCondition{" +
"name='" + name + '\'' +
", context=" + context +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ public final class TupleKey {
private final String object;
private final String relation;
private final String user;
private final RelationshipCondition condition;

public TupleKey(String object, String relation, String user) {
public TupleKey(String object, String relation, String user, @Nullable RelationshipCondition condition) {
this.object = Preconditions.parameterNonNull(object, "object");
this.relation = Preconditions.parameterNonNull(relation, "relation");
this.user = Preconditions.parameterNonNull(user, "user");
this.condition = condition;
}

public static TupleKey of(String object, String relation, String user) {
return new TupleKey(object, relation, user);
return new TupleKey(object, relation, user, null);
}

public String getObject() {
Expand All @@ -33,6 +35,11 @@ public String getUser() {
return user;
}

@Nullable
public RelationshipCondition getCondition() {
return condition;
}

@Override
public boolean equals(@Nullable Object obj) {
if (obj == this)
Expand All @@ -42,20 +49,22 @@ public boolean equals(@Nullable Object obj) {
var that = (TupleKey) obj;
return Objects.equals(this.object, that.object) &&
Objects.equals(this.relation, that.relation) &&
Objects.equals(this.user, that.user);
Objects.equals(this.user, that.user) &&
Objects.equals(this.condition, that.condition);
}

@Override
public int hashCode() {
return Objects.hash(object, relation, user);
return Objects.hash(object, relation, user, condition);
}

@Override
public String toString() {
return "TupleKey[" +
"object=" + object + ", " +
"relation=" + relation + ", " +
"user=" + user + ']';
"user=" + user + ", " +
"condition=" + condition + ']';
}

}
Loading
Loading