# 访问控制(ACL)管理

# 创建基于 client id 的 ACL 规则

# URI

POST /acl

# 请求消息

名称类型描述
clientidStringclientid
topicString主题
actionString动作:sub, pub, pubsub
accessString是否允许:allow, deny

# 响应消息

名称类型描述
codeInteger0
dataObject规则对象
data.topicString主题
data.resultString结果
data.clientidStringclientid
data.actionString动作
data.accessString是否允许

# 请求示例

$ curl -u app_id:app_secret -X POST -d '{"clientid": "client1","topic": "a/b","action": "sub","access": "allow"}' {api}/acl
1

# 响应示例

{
  "data": {
    "topic": "a/b",
    "result": "ok",
    "clientid": "client1",
    "action": "sub",
    "access": "allow"
  },
  "code": 0
}
1
2
3
4
5
6
7
8
9
10

# 创建基于 username 的 ACL 规则

# URI

POST /acl

# 请求消息

名称类型描述
usernameStringusername
topicString主题
actionString动作:sub, pub, pubsub
accessString是否允许:allow, deny

# 响应消息

名称类型描述
codeInteger0
dataObject规则对象
data.topicString主题
data.resultString结果
data.usernameStringusername
data.actionString动作
data.accessString是否允许

# 请求示例

$ curl -u app_id:app_secret -X POST -d '{"username": "user1","topic": "a/b","action": "sub","access": "allow"}' {api}/acl
1

# 响应示例

{
  "data": {
    "username": "user1", 
    "topic": "a/b", 
    "result": "ok", 
    "action": "sub", 
    "access": "allow"
  }, 
  "code": 0
}
1
2
3
4
5
6
7
8
9
10

# 创建基于所有的 ACL 规则

# URI

POST /acl

# 请求消息

名称类型描述
topicString主题
actionString动作:sub, pub, pubsub
accessString是否允许:allow, deny

# 响应消息

名称类型描述
codeInteger0
dataObject规则对象
data.topicString主题
data.resultString结果
data.allString$all
data.actionString动作
data.accessString是否允许

# 请求示例

$ curl -u app_id:app_secret -X POST -d '{"topic": "a/b","action": "pub","access": "allow"}' {api}/acl
1

# 响应示例

{
  "data": {
    "topic": "a/b",
    "result": "ok",
    "all": "$all",
    "action": "pub",
    "access": "allow"
  },
  "code": 0
}
1
2
3
4
5
6
7
8
9
10

# 批量添加 ACL 规则

# URI

POST /acl

# 请求消息

名称类型描述
[0].clientidStringclientid
[0].topicString主题
[0].actionString动作:sub, pub, pubsub
[0].accessString是否允许:allow, deny
[1].usernameStringusername
[1].topicString主题
[1].actionString动作:sub, pub, pubsub
[1].accessString是否允许:allow, deny
[2].topicString主题
[2].actionString动作:sub, pub, pubsub
[2].accessString是否允许:allow, deny

# 响应消息

名称类型描述
codeInteger0
dataObject规则对象
[0].clientidStringclientid
[0].topicString主题
[0].actionString动作:sub, pub, pubsub
[0].accessString是否允许:allow, deny
[0].resultString结果
[1].usernameStringusername
[1].topicString主题
[1].actionString动作:sub, pub, pubsub
[1].accessString是否允许:allow, deny
[1].resultString结果
[2].topicString主题
[2].actionString动作:sub, pub, pubsub
[2].accessString是否允许:allow, deny
[2].allString$all
[2].resultString结果

# 请求示例

$ curl -u app_id:app_secret -X POST -d '[{"clientid": "emqx_c_1","topic": "topic/A","action": "pub","access": "allow"},{"username": "emqx_u_1","topic": "topic/A","action": "sub","access": "allow"},{"topic": "topic/+","action": "pubsub","access": "deny"}]' {api}/acl
1

# 响应示例

{
  "data": [
    {
      "topic": "topic/+",
      "result": "ok",
      "all": "$all",
      "action": "pubsub",
      "access": "deny"
    },
    {
      "username": "emqx_u_1",
      "topic": "topic/A",
      "result": "ok",
      "action": "sub",
      "access": "allow"
    },
    {
      "topic": "topic/A",
      "result": "ok",
      "clientid": "emqx_c_1",
      "action": "pub",
      "access": "allow"
    }
  ],
  "code": 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

# 查看基于 client id 所有的 ACL 规则

# URI

GET /acl/clientid

# 请求消息

# 响应消息

名称类型描述
codeInteger0
dataArray of Objects所有认证数据
data[].topicString主题
data[].clientidStringclientid
data[].actionString动作
data[].accessString是否允许
metaObject分页信息
meta.pageInteger页码
meta.limitInteger每页显示的数据条数
meta.countInteger数据总条数

# 请求示例

$ curl -u app_id:app_secret -X GET {api}/acl/clientid
1

# 响应示例

{
  "meta": {
    "page": 1,
    "limit": 10,
    "count": 1
  },
  "data": [
    {
      "topic": "topic/A",
      "clientid": "emqx_c_1",
      "action": "pub",
      "access": "allow"
    }
  ],
  "code": 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 查看基于 username 所有的 ACL 规则

# URI

GET /acl/username

# 请求消息

# 响应消息

名称类型描述
codeInteger0
dataArray of Objects所有认证数据
data[].topicString主题
data[].usernameStringusername
data[].actionString动作
data[].accessString是否允许
metaObject分页信息
meta.pageInteger页码
meta.limitInteger每页显示的数据条数
meta.countInteger数据总条数

# 请求示例

$ curl -u app_id:app_secret -X GET {api}/acl/username
1

# 响应示例

{
  "meta": {
    "page": 1,
    "limit": 10,
    "count": 1
  },
  "data": [
    {
      "username": "emqx_u_1",
      "topic": "topic/A",
      "action": "sub",
      "access": "allow"
    }
  ],
  "code": 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 查看基于所有的 ACL 规则

# URI

GET /acl/$all

# 请求消息

# 响应消息

名称类型描述
codeInteger0
dataArray of Objects所有认证数据
data[].topicString主题
data[].allString$all
data[].actionString动作
data[].accessString是否允许
metaObject分页信息
meta.pageInteger页码
meta.limitInteger每页显示的数据条数
meta.countInteger数据总条数

# 请求示例

$ curl -u app_id:app_secret -X GET {api}/acl/\$all
1

# 响应示例

{
  "meta": {
    "page": 1,
    "limit": 10,
    "count": 1
  },
  "data": [
    {
      "topic": "topic/A",
      "all": "$all",
      "action": "sub",
      "access": "allow"
    }
  ],
  "code": 0
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 查看指定 client id 的 ACL 规则

# URI

GET /acl/clientid/{clientid}

参数:

参数类型描述
clientidStringclientid

# 请求消息

# 响应消息

名称类型描述
codeInteger0
dataArray of Objects所有认证数据
data[].topicString主题
data[].clientidStringclient id
data[].actionString动作
data[].accessString是否允许

# 请求示例

$ curl -u app_id:app_secret -X GET {api}/acl/clientid/emqx_c_1
1

# 响应示例

{
  "data": [
    {
      "topic": "topic/A",
      "clientid": "emqx_c_1",
      "action": "pub",
      "access": "allow"
    }
  ],
  "code": 0
}
1
2
3
4
5
6
7
8
9
10
11

# 查看指定 username 的 ACL 规则

# URI

GET /acl/username/{username}

参数:

参数类型描述
usernameStringusername

# 请求消息

# 响应消息

名称类型描述
codeInteger0
dataArray of Objects所有认证数据
data[].topicString主题
data[].usernameStringusername
data[].actionString动作
data[].accessString是否允许

# 请求示例

$ curl -u app_id:app_secret -X GET {api}/acl/username/emqx_u_1
1

# 响应示例

{
  "data": [
    {
      "topic": "topic/A",
      "username": "emqx_u_1",
      "action": "pub",
      "access": "allow"
    }
  ],
  "code": 0
}
1
2
3
4
5
6
7
8
9
10
11

# 删除指定 clientid 指定的 ACL 规则

# URI

DELETE /acl/clientid/{clientid}/topic/{topic}

参数:

参数类型描述
clientidStringclientid
topicStringtopic,可能需要使用 UrlEncode 编码

# 请求消息

# 响应消息

名称类型描述
codeInteger0

# 请求示例

$ curl -u app_id:app_secret -X DELETE {api}/acl/clientid/emqx_c_1/topic/topic%2fA
1

# 响应示例

{
  "code": 0
}
1
2
3

# 删除指定 username 指定的 ACL 规则

# URI

DELETE /acl/username/{username}/topic/{topic}

参数:

参数类型描述
usernameStringusername
topicStringtopic,可能需要使用 UrlEncode 编码

# 请求消息

# 响应消息

名称类型描述
codeInteger0

# 请求示例

$ curl -u app_id:app_secret -X DELETE {api}/acl/username/emqx_u_1/topic/topic%2fA
1

# 响应示例

{
  "code": 0
}
1
2
3

# 删除基于所有的指定的 ACL 规则

# URI

DELETE /acl/$all/topic/{topic}

参数:

参数类型描述
topicStringtopic,可能需要使用 UrlEncode 编码

# 请求消息

# 响应消息

名称类型描述
codeInteger0

# 请求示例

$ curl -u app_id:app_secret -X DELETE {api}/acl/\$all/topic/topic%2fA
1

# 响应示例

{
  "code": 0
}
1
2
3