在Spring Boot应用中实现Permify权限控制:Schema上传问题求助
Permify Schema上传失败(404)解决方案
核心问题:端点路径错误
你尝试的端点存在两个关键问题:
- 路径中使用了单数的
schema,而Permify v1.x版本的正确路径是复数schemas - 未确保使用POST请求方法(GET请求会直接返回404)
正确的Schema写入端点
Permify v1.x版本的标准Schema写入端点为:
POST http://localhost:3476/v1/tenants/{tenant_id}/schemas/write
- 替换
{tenant_id}:使用实际租户ID,默认租户可直接用default(Permify默认自带该租户) - 请求方法必须为
POST,不能用GET
请求体格式
需要将你的Schema内容包裹在JSON请求体中,示例如下:
{ "schema": "entity user {}\n\nentity organization {\n // organizational roles\n relation admin @user\n relation member @user\n}\n\nentity repository {\n // represents repositories parent organization\n relation parent @organization\n // represents owner of this repository\n relation owner @user\n // permissions\n permission edit = parent.admin or owner\n permission delete = owner\n}" }
Spring Boot中调用示例(RestTemplate)
import org.springframework.web.client.RestTemplate; public class PermifySchemaManager { public void uploadSchema() { RestTemplate restTemplate = new RestTemplate(); String endpoint = "http://localhost:3476/v1/tenants/default/schemas/write"; String permifySchema = """ entity user {} entity organization { // organizational roles relation admin @user relation member @user } entity repository { // represents repositories parent organization relation parent @organization // represents owner of this repository relation owner @user // permissions permission edit = parent.admin or owner permission delete = owner } """; SchemaRequest requestPayload = new SchemaRequest(permifySchema); restTemplate.postForObject(endpoint, requestPayload, String.class); } // 内部请求体封装类 static class SchemaRequest { private String schema; public SchemaRequest(String schema) { this.schema = schema; } public String getSchema() { return schema; } public void setSchema(String schema) { this.schema = schema; } } }
验证上传结果
调用以下端点确认Schema是否成功写入:
GET http://localhost:3476/v1/tenants/default/schemas/latest
返回结果中会包含你上传的完整Schema内容。
内容的提问来源于stack exchange,提问作者Sooraj Sureshkumar
相关产品推荐
相关产品推荐

