leslie-tsang commented on a change in pull request #5274:
URL: https://github.com/apache/apisix/pull/5274#discussion_r733294821



##########
File path: docs/zh/latest/plugins/authz-casbin.md
##########
@@ -0,0 +1,249 @@
+---
+title: authz-casbin
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## 目录
+
+- [**简介**](#简介)
+- [**属性**](#属性)
+- [**元数据**](#元数据)
+- [**如何启用**](#如何启用)
+- [**测试插件**](#测试插件)
+- [**禁用插件**](#禁用插件)
+- [**示例**](#示例)
+
+## 简介
+
+`authz-casbin` 是一个基于 [Lua Casbin](https://github.com/casbin/lua-casbin/) 
的访问控制插件,该插件支持基于各种访问鉴权模型的授权场景。
+
+有关如何创建鉴权模型和鉴权策略的详细文档, 请参阅 
[Casbin](https://casbin.org/docs/en/supported-models)。
+
+## 属性
+
+| 名称         |   类型  | 必选项  | 默认值 | 有效值 | 描述                          |
+| :---------- | :----: | :----: | ------| ----- | ---------------------------  
 |
+| model_path  | string | 必须    |       |       | Casbin 鉴权模型的配置文件路径     |
+| policy_path | string | 必须    |       |       | Casbin 鉴权策略的配置文件路径     |
+| model       | string | 必须    |       |       | Casbin 鉴权模型的文本定义        |
+| policy      | string | 必须    |       |       | Casbin 鉴权策略的文本定义        |
+| username    | string | 必须    |       |       | 描述请求中可以通过访问控制的用户名  |
+
+**注意**: 在插件配置中指定 `model_path`、`policy_path` 和 `username`,或者在插件配置中指定 
`model`、`policy` 和 `username` 来使插件生效。如果想要使所有的路由共享一个 Casbin 
配置,可以先在插件元数据中指定鉴权模型和鉴权策略,然后在指定路由的插件配置中指定 `username`。
+
+## 元数据
+
+| 名称         | 类型    | 必选项  | 默认值 | 有效值 | 描述                     |
+| ----------- | ------ | ------ | ------- | ----- |------------------------|
+| model       | string | 必须    |        |       | Casbin 鉴权模型的文本定义  |
+| policy      | string | 必须    |        |       | Casbin 鉴权策略的文本定义  |
+
+## 启用

Review comment:
       Please sync with the TOC.

##########
File path: docs/zh/latest/plugins/authz-casbin.md
##########
@@ -0,0 +1,249 @@
+---
+title: authz-casbin
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## 目录
+
+- [**简介**](#简介)
+- [**属性**](#属性)
+- [**元数据**](#元数据)
+- [**如何启用**](#如何启用)
+- [**测试插件**](#测试插件)
+- [**禁用插件**](#禁用插件)
+- [**示例**](#示例)
+
+## 简介
+
+`authz-casbin` 是一个基于 [Lua Casbin](https://github.com/casbin/lua-casbin/) 
的访问控制插件,该插件支持基于各种访问鉴权模型的授权场景。
+
+有关如何创建鉴权模型和鉴权策略的详细文档, 请参阅 
[Casbin](https://casbin.org/docs/en/supported-models)。
+
+## 属性
+
+| 名称         |   类型  | 必选项  | 默认值 | 有效值 | 描述                          |
+| :---------- | :----: | :----: | ------| ----- | ---------------------------  
 |
+| model_path  | string | 必须    |       |       | Casbin 鉴权模型的配置文件路径     |
+| policy_path | string | 必须    |       |       | Casbin 鉴权策略的配置文件路径     |
+| model       | string | 必须    |       |       | Casbin 鉴权模型的文本定义        |
+| policy      | string | 必须    |       |       | Casbin 鉴权策略的文本定义        |
+| username    | string | 必须    |       |       | 描述请求中可以通过访问控制的用户名  |
+
+**注意**: 在插件配置中指定 `model_path`、`policy_path` 和 `username`,或者在插件配置中指定 
`model`、`policy` 和 `username` 来使插件生效。如果想要使所有的路由共享一个 Casbin 
配置,可以先在插件元数据中指定鉴权模型和鉴权策略,然后在指定路由的插件配置中指定 `username`。
+
+## 元数据
+
+| 名称         | 类型    | 必选项  | 默认值 | 有效值 | 描述                     |
+| ----------- | ------ | ------ | ------- | ----- |------------------------|
+| model       | string | 必须    |        |       | Casbin 鉴权模型的文本定义  |
+| policy      | string | 必须    |        |       | Casbin 鉴权策略的文本定义  |
+
+## 启用
+
+在鉴权模型/鉴权策略文件中进行定义或者直接在任意路由中添加鉴权模型/鉴权策略的配置信息以启用该插件。
+
+### 通过配置文件启用
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "plugins": {
+        "authz-casbin": {
+            "model_path": "/path/to/model.conf",
+            "policy_path": "/path/to/policy.csv",
+            "username": "user"
+        }
+    },
+    "upstream": {
+        "nodes": {
+            "127.0.0.1:1980": 1
+        },
+        "type": "roundrobin"
+    },
+    "uri": "/*"
+}'
+```
+
+上述请求会根据鉴权模型/鉴权策略文件中的定义创建一个 Casbin enforcer。
+
+### 通过路由配置启用
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "plugins": {
+        "authz-casbin": {
+            "model": "[request_definition]
+            r = sub, obj, act
+
+            [policy_definition]
+            p = sub, obj, act
+
+            [role_definition]
+            g = _, _
+
+            [policy_effect]
+            e = some(where (p.eft == allow))
+
+            [matchers]
+            m = (g(r.sub, p.sub) || keyMatch(r.sub, p.sub)) && keyMatch(r.obj, 
p.obj) && keyMatch(r.act, p.act)",
+
+            "policy": "p, *, /, GET
+            p, admin, *, *
+            g, alice, admin",
+
+            "username": "user"
+        }
+    },
+    "upstream": {
+        "nodes": {
+            "127.0.0.1:1980": 1
+        },
+        "type": "roundrobin"
+    },
+    "uri": "/*"
+}'
+```
+
+上述请求会根据鉴权模型和鉴权策略的定义创建一个 Casbin enforcer。
+
+### 通过 plugin metadata 配置模型/策略
+
+首先,使用 Admin API 发送一个 `PUT` 
请求,将鉴权模型和鉴权策略配置信息添加到插件的元数据中,通过这种方式创建路由的同时会根据请求中的配置创建一个 Casbin 
enforcer,并绑定到该路由。同时也可以使用 `PUT` 请求更新鉴权模型和鉴权策略配置信息,该插件将会自动同步最新的配置信息。
+
+```shell
+curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/authz-casbin -H 
'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -i -X PUT -d '
+{
+"model": "[request_definition]
+r = sub, obj, act
+
+[policy_definition]
+p = sub, obj, act
+
+[role_definition]
+g = _, _
+
+[policy_effect]
+e = some(where (p.eft == allow))
+
+[matchers]
+m = (g(r.sub, p.sub) || keyMatch(r.sub, p.sub)) && keyMatch(r.obj, p.obj) && 
keyMatch(r.act, p.act)",
+
+"policy": "p, *, /, GET
+p, admin, *, *
+g, alice, admin"
+}'
+```
+
+以下请求会将该插件添加到 id 为 1 的路由上。注意,此处只需要配置 `username`,不需要再增加鉴权模型/鉴权策略的定义。

Review comment:
       There is a difference in the translation here. Please sync it to en docs.

##########
File path: docs/zh/latest/plugins/authz-casbin.md
##########
@@ -0,0 +1,249 @@
+---
+title: authz-casbin
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+## 目录
+
+- [**简介**](#简介)
+- [**属性**](#属性)
+- [**元数据**](#元数据)
+- [**如何启用**](#如何启用)
+- [**测试插件**](#测试插件)
+- [**禁用插件**](#禁用插件)
+- [**示例**](#示例)
+
+## 简介
+
+`authz-casbin` 是一个基于 [Lua Casbin](https://github.com/casbin/lua-casbin/) 
的访问控制插件,该插件支持基于各种访问鉴权模型的授权场景。
+
+有关如何创建鉴权模型和鉴权策略的详细文档, 请参阅 
[Casbin](https://casbin.org/docs/en/supported-models)。
+
+## 属性
+
+| 名称         |   类型  | 必选项  | 默认值 | 有效值 | 描述                          |
+| :---------- | :----: | :----: | ------| ----- | ---------------------------  
 |
+| model_path  | string | 必须    |       |       | Casbin 鉴权模型的配置文件路径     |
+| policy_path | string | 必须    |       |       | Casbin 鉴权策略的配置文件路径     |
+| model       | string | 必须    |       |       | Casbin 鉴权模型的文本定义        |
+| policy      | string | 必须    |       |       | Casbin 鉴权策略的文本定义        |
+| username    | string | 必须    |       |       | 描述请求中可以通过访问控制的用户名  |
+
+**注意**: 在插件配置中指定 `model_path`、`policy_path` 和 `username`,或者在插件配置中指定 
`model`、`policy` 和 `username` 来使插件生效。如果想要使所有的路由共享一个 Casbin 
配置,可以先在插件元数据中指定鉴权模型和鉴权策略,然后在指定路由的插件配置中指定 `username`。

Review comment:
       ```suggestion
   **注意**: 在插件配置中指定 `model_path`、`policy_path` 和 `username`,或者在插件配置中指定 
`model`、`policy` 和 `username` 来使插件生效。如果想要使所有的路由共享 Casbin 
配置,可以先在插件元数据中指定鉴权模型和鉴权策略,然后在指定路由的插件配置中指定 `username`。
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to