来源:https://help.pentaho.com/Documentation/8.3/Developer_center/REST_API_Reference/User_Role_Management/0O0
以下介绍的Rest API用以PBA的安全用户&角色的管理:
- 创建、删除用户角色
- 给用户分配角色
- 获得某角色下的用户列表
- 给角色赋予权限
- 修改用户密码
Pentaho Rest API的通用格式为:
[server path]/[rest path]/[query parameter]
调用API需进行pentaho认证,参考教程。本篇示例均以Basic Auth的认证方式实现。
1. Users
本章节列的Rest API与Pentaho用户有关。
1.1 创建用户
创建一个用户包括创建用户名和密码。此请求封装在具有用户名和密码值的user对象中,请注意创建用户不包括为其分配角色,若要分配角色需要建立另外的请求。
⚠️ 终端用户必须有管理权限才可以执行。
支持方法
Http Verb | Example Request |
---|---|
PUT | PUT /pentaho/api/userroledao/createUser |
参数
Name | Description | Type |
---|---|---|
user | 用于传递userName和password的对象 | query |
Request Body
user对象传递userName&password的示例如下:
{
"userName":"cloud",
"password":"zijin.Cloud"
}
Element | Media Types |
---|---|
user | */* application/xml application/octet-stream |
Response Body
Response Body包含操作状态码
Element | Media Types |
---|---|
(custom) | */* application/xml application/octet-stream |
状态码
Code | Description |
---|---|
200* | Successfully created new user(实际上是204,无返回内容) |
400 | Provided data has invalid format. |
401 | 未认证 |
403 | Only users with administrative privileges can access this method. |
412 | Unable to create user. |
请求指令
curl -d '{"userName":"viviran","password":"password"}' -H'Authorization:Basic YWRtaW46cGFzc3dvcmQ=' -H 'Content-Type:application/json' -X PUT http://localhost:8080/pentaho/api/userroledao/createUser
创建viviran的用户
1.2 删除用户
使用一个query parameter实现用户列表的删除,若要批量删除用户,userName以tab(\t)分隔.
⚠️ 终端用户必须有管理权限才可以执行。
支持方法
HTTP Verb | Example Request |
---|---|
PUT | PUT pentaho/api/userroledao/deleteUsers?userNames=user1%09user2%09 |
参数
Name | Description | Type |
---|---|---|
userName | 用户名列表以tab (\t)分隔 | query |
Request Body
无
Response Body
Response Body包含操作状态码
Element | Media Types |
---|---|
(custom) | */* application/xml application/octet-stream |
状态码
Code | Description |
---|---|
200* | Successfully created new user(实际上是204,无返回内容) |
401 | 未认证 |
403 | Only users with administrative privileges can access this method. |
500 | Internal server error prevented the system from properly retrieving either the user or roles. |
1.3 修改用户密码
修改信息封装在ChangeUserPassword对象:userName, newPassword, oldPassword.
支持方法
HTTP Verb | Example Request |
---|---|
PUT | PUT pentaho/api/userroledao/user |
参数
Name | Description | Type |
---|---|---|
ChangePasswordUser | 封装了需要修改的用户的用户名、旧密码、新密码字段 | query |
Request Body
ChangePasswordUser对象传递的示例如下:
{
"userName":"cloud",
"newPassword":"cloud.Zijin",
"oldPassword":"zijin.Cloud"
}
Response Body
Response Body包含操作状态码
Element | Media Types |
---|---|
(custom) | */* application/xml application/octet-stream |
状态码
Code | Description |
---|---|
200* | Successfully created new user(实际上是204,无返回内容) |
400 | Provided data has invalid format. |
401 | 未认证 |
403 | Only users with administrative privileges can access this method. |
412 | Unable to create |
1.4 获得用户列表
返回Pentaho资源库中的用户列表。
支持方法
HTTP Verb | Example Request |
---|---|
GET | GET pentaho/api/userroledao/users |
参数
无
Request Body
无
Response Body
返回平台的用户列表。
Element | Media Types |
---|---|
userList | application/xml application/json |
示例:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<userList>
<users>suzy</users>
<users>pat</users>
<users>tiffany</users>
<users>admin</users>
<users>vivi</users>
<users>swran001</users>
<users>Shipped</users>
</userList>
状态码
Code | Description |
---|---|
200 | Successfully returned the list of users. |
500 | An error occurred in the platform while trying to access the list of users. |
1.5 获取用户的角色
获得某一个用户的所有角色。
支持方法
HTTP Verb | Example Request |
---|---|
GET | GET pentaho/api/userroledao/userRoles?userName=suzy |
参数
Name | Description | Type |
---|---|---|
userName | 需要获得角色的用户 | query |
Request Body
无
Response Body
返回平台的用户的角色。
Element | Media Types |
---|---|
roleList | application/xml application/json |
示例