- Development Integration
- /
- SDK
- /
- Java
- /
Management module
- /
Manage data resources and permissions
- /
- Judge the user's permissions under the same level resources of the tree resource
¶ Determine the user's permissions at the same level of a tree resource (recommended)
This document is automatically generated based on https://github.com/authing/authing-docs-factory based on the https://api-explorer.genauth.ai V3 API, and is consistent with the API parameters and return results. If the document description is incorrect, please refer to the V3 API.
¶ Description
This interface is used to determine whether the user has certain permissions on the nodes of the same level of a tree resource. Since tree-type resources are more commonly used, we have added an interface for determining the permissions of tree-type resource nodes based on the business scenario of "determining whether the user has resource permissions".
¶ Note
We use the resource parameter to locate a certain level of the tree type data resource (so the parameter is passed in the format of resource code/node code path), and use the resourceNodeCodes parameter to locate the current nodes.
¶ Scenario Example
If your business scenario is: when a user deletes certain files in a folder in a file system, you need to determine whether he has the permission to delete these files, then you can use this interface.
¶ Request Example
¶ Example of judging the user's permissions at the same level of tree resources (unconditional judgment)
{
"namespaceCode": "examplePermissionNamespace",
"userId": "63721xxxxxxxxxxxxdde14a3",
"action": "read",
"resource": "treeResourceCode/structCode",
"resourceNodeCodes": [
"resourceStructChildrenCode1",
"resourceStructChildrenCode2",
"resourceStructChildrenCode3"
]
}
¶ Example of judging the permissions of users at the same level of tree resources (enabling conditional judgment)
{
"namespaceCode": "examplePermissionNamespace",
"userId": "63721xxxxxxxxxxxxdde14a3",
"action": "read",
"resource": "treeResourceCode/structCode",
"resourceNodeCodes": [
"resourceStructChildrenCode1",
"resourceStructChildrenCode2",
"resourceStructChildrenCode3"
],
"judgeConditionEnabled": true,
"authEnvParams": {
"ip": "110.96.0.0",
"city": "Beijing",
"province": "Beijing",
"country": "China",
"deviceType": "PC",
"systemType": "ios",
"browserType": "IE",
"requestDate": "2022-12-26 17:40:00"
}
}
¶ Method Name
ManagementClient.checkUserSameLevelPermission
¶ Request Parameters
| Name | Type | Is it required | Default Value | Description | Example Value |
|---|---|---|---|---|---|
| resourceNodeCodes | string[] | yes | - | Current tree resource path child node Code | ["resourceStructChildrenCode1"] |
| resource | string | yes | - | Tree resource path, multi-level paths are allowed, the example is as follows - treeResourceCode - treeResourceCode/structCode - treeResourceCode/structCode/struct1Code - treeResourceCode/.../structCode | treeResourceCode |
| action | string | yes | - | Data resource permission operation | read |
| userId | string | yes | - | User id | 63721xxxxxxxxxxxxdde14a3 |
| namespaceCode | string | yes | - | Permission space Code | examplePermissionNamespace |
| judgeConditionEnabled | boolean | no | - | Whether to enable condition judgment, the default is false and not enabled | |
| authEnvParams | AuthEnvParams | No | - | Conditional environment attribute, used if conditional judgment is enabled | {"ip":"127.0.0.1"} |
¶ Sample Code
package test.management;
import cn.authing.sdk.java.client.ManagementClient;
import cn.authing.sdk.java.dto.CheckUserSameLevelPermissionDto;
import cn.authing.sdk.java.dto.CheckUserSameLevelPermissionRespDto;
import cn.authing.sdk.java.dto.CheckUserSameLevelPermissionResponseDto;
import cn.authing.sdk.java.model.ManagementClientOptions;
import cn.authing.sdk.java.util.JsonUtils;
public class CheckUserSameLevelPermissionTest {
// Need to be replaced with your GenAuth Access Key ID
private static final String ACCESS_KEY_ID = "AUTHING_ACCESS_KEY_ID";
// Need to be replaced with your GenAuth Access Key Secret
private static final String ACCESS_KEY_SECRET = "AUTHING_ACCESS_KEY_SECRET";
public static void main(String[] args) throws Throwable {
ManagementClientOptions clientOptions = new ManagementClientOptions();
clientOptions.setAccessKeyId(ACCESS_KEY_ID);
clientOptions.setAccessKeySecret(ACCESS_KEY_SECRET);
// If you are a private deployment customer, you need to set the GenAuth service domain name
// clientOptions.setHost("https://api.your-authing-service.com");
ManagementClient client = new ManagementClient(clientOptions);
CheckUserSameLevelPermissionDto request = new CheckUserSameLevelPermissionDto();
request.setNamespaceCode("examplePermissionNamespace");
request.setUserId("63721xxxxxxxxxxxxdde14a3");
request.setAction("get");
request.setResource("treeResourceCode");
CheckUserSameLevelPermissionResponseDto response = client
.checkUserSameLevelPermission(request);
System.out.println(JsonUtils.serialize(response));
}
}
¶ Request Response
Type: CheckUserSameLevelPermissionResponseDto
| Name | Type | Description |
|---|---|---|
| statusCode | number | Business status code. You can use this status code to determine whether the operation is successful. 200 means success. |
| message | string | Description |
| apiCode | number | Segment error code, through which the specific error type can be obtained (not returned for successful requests). For a detailed list of error codes, see:API Code List (opens new window) |
| requestId | string | Request ID. Returned when the request fails. |
| data | CheckUserSameLevelPermissionDataDto | Response data |
Example Results:
{
"statusCode": 200,
"message": "Operation successful",
"requestId": "934108e5-9fbf-4d24-8da1-c330328abd6c",
"data": {
"checkLevelResultList": {
"action": "get",
"resourceNodeCode": "treeResourceStructChildrenCode1",
"enabled": true
}
}
}
¶ Data Structure
¶ AuthEnvParams
| Name | Type | Is it required | Description | Example Value |
|---|---|---|---|---|
| ip | string | no | ip | 127.0.0.1 |
| city | string | no | city | Beijing |
| province | string | no | province | Hubei |
| country | string | no | country | China |
| deviceType | string | no | device type: PC/Mobile | PC |
| systemType | string | no | operation type: Windows, Android, iOS, MacOS | Windows |
| browserType | string | no | browser type: IE/Chrome/Firefox | IE |
| requestDate | string | no | request time | 2022-07-03T03:20:30.000Z |
¶ CheckUserSameLevelPermissionDataDto
| Name | Type | Is it required | Description | Example Value |
|---|---|---|---|---|
| checkLevelResultList | array | Yes | Response result list Nested Type:CheckUserSameLevelPermissionRespDto。 |
¶ CheckUserSameLevelPermissionRespDto
| Name | Type | Is it required | Description | Example Value |
|---|---|---|---|---|
| action | string | Yes | Data resource permission operation | get |
| resourceNodeCode | string | Yes | Tree resource node code | treeResourceStructChildrenCode1 |
| enabled | boolean | Yes | Whether it has action permission | true |
