Skip to content

Commit 7ce58f4

Browse files
committed
Add reflect schema api flow for search actions.
1 parent 6034fdd commit 7ce58f4

File tree

11 files changed

+605
-53
lines changed

11 files changed

+605
-53
lines changed

components/org.wso2.carbon.identity.authz.spicedb/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<counter>COMPLEXITY</counter>
127127
<value>COVEREDRATIO</value>
128128
<!-- coverage to be increased to 0.8 in next PR -->
129-
<minimum>0.38</minimum>
129+
<minimum>0.31</minimum>
130130
</limit>
131131
</limits>
132132
</rule>

components/org.wso2.carbon.identity.authz.spicedb/src/main/java/org/wso2/carbon/identity/authz/spicedb/constants/SpiceDbApiConstants.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,9 @@ public class SpiceDbApiConstants {
3737
//Api endpoints.
3838
public static final String PERMISSION_CHECK = "v1/permissions/check";
3939
public static final String PERMISSIONS_BULKCHECK = "v1/permissions/checkbulk";
40-
public static final String PERMISSIONS_EXPAND = "v1/permissions/expand";
4140
public static final String LOOKUP_RESOURCES = "v1/permissions/resources";
4241
public static final String LOOKUP_SUBJECTS = "v1/permissions/subjects";
43-
4442
public static final String RELATIONSHIPS_READ = "v1/relationships/read";
45-
public static final String RELATIONSHIPS_WRITE = "v1/relationships/write";
46-
public static final String RELATIONSHIPS_DELETE = "v1/relationships/delete";
47-
public static final String RELATIONSHIPS_BULKIMPORT = "v1/relationships/importbulk";
48-
public static final String RELATIONSHIPS_BULKEXPORT = "v1/relationships/exportbulk";
49-
50-
public static final String SCHEMA_READ = "v1/schema/read";
51-
public static final String SCHEMA_WRITE = "v1/schema/write";
52-
53-
public static final String WATCH_SERVICE = "v1/watch";
43+
//Experimental api endpoints.
44+
public static final String REFLECT_SCHEMA = "v1/experimental/reflectschema";
5445
}

components/org.wso2.carbon.identity.authz.spicedb/src/main/java/org/wso2/carbon/identity/authz/spicedb/constants/SpiceDbModelConstants.java

+16
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,20 @@ public class SpiceDbModelConstants {
9191
public static final String RESOURCE_TYPE = "resourceType";
9292
public static final String OPTIONAL_RESOURCE_ID = "optionalResourceId";
9393
public static final String OPTIONAL_SUBJECT_FILTER = "optionalSubjectFilter";
94+
95+
//Reflection API values
96+
public static final String OPTIONAL_FILTERS = "optionalFilters";
97+
public static final String OPTIONAL_DEFINITION_NAME_FILTER = "optionalDefinitionNameFilter";
98+
public static final String OPTIONAL_RELATION_NAME_FILTER = "optionalRelationNameFilter";
99+
public static final String OPTIONAL_CAVEAT_NAME_FILTER = "optionalCaveatNameFilter";
100+
public static final String OPTIONAL_PERMISSION_NAME_FILTER = "optionalPermissionNameFilter";
101+
public static final String DEFINITIONS = "definitions";
102+
public static final String DEFINITION_NAME = "name";
103+
public static final String DEFINITION_COMMENT = "comment";
104+
public static final String DEFINITION_RELATIONS = "relations";
105+
public static final String DEFINITION_PERMISSIONS = "permissions";
106+
public static final String PERMISSION_NAME = "name";
107+
public static final String PERMISSION_COMMENT = "comment";
108+
public static final String PARENT_DEFINITION = "parentDefinitionType";
109+
public static final String SUBJECT_TYPES = "subjectTypes";
94110
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.identity.authz.spicedb.handler.model;
20+
21+
import com.google.gson.annotations.Expose;
22+
import com.google.gson.annotations.SerializedName;
23+
import org.wso2.carbon.identity.authz.spicedb.constants.SpiceDbModelConstants;
24+
25+
import java.util.ArrayList;
26+
27+
/**
28+
* The {@code Definition} class represents a definition object returned in a reflection response. This definition
29+
* refers to a specific definition that is used to define the structure of an entity in SpiceDB.
30+
*/
31+
public class Definition {
32+
33+
@SerializedName(SpiceDbModelConstants.DEFINITION_NAME)
34+
@Expose
35+
private String definitionName;
36+
@SerializedName(SpiceDbModelConstants.DEFINITION_COMMENT)
37+
@Expose
38+
private String definitionComment;
39+
@SerializedName(SpiceDbModelConstants.DEFINITION_RELATIONS)
40+
@Expose
41+
private ArrayList<Object> relations;
42+
@SerializedName(SpiceDbModelConstants.DEFINITION_PERMISSIONS)
43+
@Expose
44+
private ArrayList<Permission> permissions;
45+
private ArrayList<String> permissionNames;
46+
47+
public String getDefinitionName() {
48+
49+
return definitionName;
50+
}
51+
52+
public String getDefinitionComment() {
53+
54+
return definitionComment;
55+
}
56+
57+
public ArrayList<Object> getRelations() {
58+
59+
return relations;
60+
}
61+
62+
public ArrayList<Permission> getPermissions() {
63+
64+
return permissions;
65+
}
66+
67+
public ArrayList<String> getPermissionNames() {
68+
69+
permissionNames = new ArrayList<>();
70+
if (this.permissions != null) {
71+
for (Permission permission : this.permissions) {
72+
permissionNames.add(permission.getPermissionName());
73+
}
74+
}
75+
return permissionNames;
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.identity.authz.spicedb.handler.model;
20+
21+
import com.google.gson.annotations.Expose;
22+
import com.google.gson.annotations.SerializedName;
23+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24+
import org.wso2.carbon.identity.authz.spicedb.constants.SpiceDbModelConstants;
25+
26+
/**
27+
* The {@code OptionalSchemaFilter} class represents an optional filter object in a reflection request.
28+
*/
29+
@SuppressFBWarnings(value = "URF_UNREAD_FIELD",
30+
justification = "All fields are accessed via Gson serialization")
31+
public class OptionalSchemaFilter {
32+
33+
@SerializedName(SpiceDbModelConstants.OPTIONAL_DEFINITION_NAME_FILTER)
34+
@Expose
35+
private String optionalDefinitionNameFilter;
36+
@SerializedName(SpiceDbModelConstants.OPTIONAL_RELATION_NAME_FILTER)
37+
@Expose
38+
private String optionalRelationNameFilter;
39+
@SerializedName(SpiceDbModelConstants.OPTIONAL_CAVEAT_NAME_FILTER)
40+
@Expose
41+
private String optionalCaveatNameFilter;
42+
@SerializedName(SpiceDbModelConstants.OPTIONAL_PERMISSION_NAME_FILTER)
43+
@Expose
44+
private String optionalPermissionNameFilter;
45+
46+
public void setOptionalDefinitionNameFilter(String optionalDefinitionNameFilter) {
47+
48+
this.optionalDefinitionNameFilter = optionalDefinitionNameFilter;
49+
}
50+
51+
public void setOptionalRelationNameFilter(String optionalRelationNameFilter) {
52+
53+
this.optionalRelationNameFilter = optionalRelationNameFilter;
54+
}
55+
56+
public void setOptionalCaveatNameFilter(String optionalCaveatNameFilter) {
57+
58+
this.optionalCaveatNameFilter = optionalCaveatNameFilter;
59+
}
60+
61+
public void setOptionalPermissionNameFilter(String optionalPermissionNameFilter) {
62+
63+
this.optionalPermissionNameFilter = optionalPermissionNameFilter;
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.identity.authz.spicedb.handler.model;
20+
21+
import com.google.gson.annotations.Expose;
22+
import com.google.gson.annotations.SerializedName;
23+
import org.wso2.carbon.identity.authz.spicedb.constants.SpiceDbModelConstants;
24+
25+
import java.util.ArrayList;
26+
27+
/**
28+
* The {@code Permission} class represents a permission object returned in a reflection response.
29+
*/
30+
public class Permission {
31+
32+
@SerializedName(SpiceDbModelConstants.PERMISSION_NAME)
33+
@Expose
34+
private String permissionName;
35+
@SerializedName(SpiceDbModelConstants.PERMISSION_COMMENT)
36+
@Expose
37+
private String permissionComment;
38+
@SerializedName(SpiceDbModelConstants.PARENT_DEFINITION)
39+
@Expose
40+
private String parentDefinitionType;
41+
@SerializedName(SpiceDbModelConstants.SUBJECT_TYPES)
42+
@Expose
43+
private ArrayList<Object> subjectTypes;
44+
45+
public String getPermissionName() {
46+
47+
return permissionName;
48+
}
49+
50+
public String getPermissionComment() {
51+
52+
return permissionComment;
53+
}
54+
55+
public String getParentDefinitionType() {
56+
57+
return parentDefinitionType;
58+
}
59+
60+
public ArrayList<Object> getSubjectTypes() {
61+
62+
return subjectTypes;
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.identity.authz.spicedb.handler.model;
20+
21+
import com.google.gson.annotations.Expose;
22+
import com.google.gson.annotations.SerializedName;
23+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24+
import org.wso2.carbon.identity.authz.spicedb.constants.SpiceDbModelConstants;
25+
26+
/**
27+
* The {@code LookupResourcesResult} class represents a single element in the results stream returned in a Read
28+
* Relationships response.
29+
*/
30+
@SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR",
31+
justification = "Field is populated via Gson deserialization")
32+
public class ReadRelationshipsResult {
33+
34+
@SerializedName(SpiceDbModelConstants.RESULT)
35+
@Expose
36+
ReadRelationshipsResultBody result;
37+
38+
public ReadRelationshipsResultBody getResultDetails() {
39+
40+
return result;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.identity.authz.spicedb.handler.model;
20+
21+
import com.google.gson.annotations.Expose;
22+
import com.google.gson.annotations.SerializedName;
23+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24+
import org.wso2.carbon.identity.authz.spicedb.constants.SpiceDbModelConstants;
25+
26+
import java.util.ArrayList;
27+
28+
/**
29+
* The {@code ReflectSchemaRequest} class represents a request to reflect the schema stored in SpiceDB. This is
30+
* expected to be used in introspection scenarios. The reflection API is still in experimental stages as of April 2025.
31+
*/
32+
@SuppressFBWarnings(value = "URF_UNREAD_FIELD",
33+
justification = "All fields are accessed via Gson serialization")
34+
public class ReflectSchemaRequest {
35+
36+
@SerializedName(SpiceDbModelConstants.OPTIONAL_FILTERS)
37+
@Expose
38+
private ArrayList<OptionalSchemaFilter> schemaFilters;
39+
40+
public ReflectSchemaRequest(ArrayList<OptionalSchemaFilter> schemaFilters) {
41+
42+
this.schemaFilters = schemaFilters;
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
package org.wso2.carbon.identity.authz.spicedb.handler.model;
20+
21+
import com.google.gson.annotations.Expose;
22+
import com.google.gson.annotations.SerializedName;
23+
import org.wso2.carbon.identity.authz.spicedb.constants.SpiceDbModelConstants;
24+
25+
import java.util.ArrayList;
26+
27+
/**
28+
* The {@code ReflectSchemaResponse} class represents a response object from the Reflect Schema API. This API is
29+
* expected to be used for introspection scenarios. The reflection API is still in experimental stages as of April
30+
* 2025.
31+
*/
32+
public class ReflectSchemaResponse {
33+
34+
@SerializedName(SpiceDbModelConstants.DEFINITIONS)
35+
@Expose
36+
private ArrayList<Definition> definitions;
37+
38+
public ArrayList<Definition> getDefinitions() {
39+
40+
return definitions;
41+
}
42+
43+
}

0 commit comments

Comments
 (0)