-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBIDUsers.java
More file actions
111 lines (87 loc) · 3.97 KB
/
Copy pathBIDUsers.java
File metadata and controls
111 lines (87 loc) · 3.97 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Copyright (c) 2018, 1Kosmos Inc. All rights reserved.
* Licensed under 1Kosmos Open Source Public License version 1.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of this license at
* https://github.com/1Kosmos/1Kosmos_License/blob/main/LICENSE.txt
*/
package com.bidsdk;
import com.bidsdk.model.BIDCommunityInfo;
import com.bidsdk.model.BIDKeyPair;
import com.bidsdk.model.BIDSD;
import com.bidsdk.model.BIDTenantInfo;
import com.bidsdk.utils.WTM;
import com.google.gson.Gson;
import java.util.HashMap;
import java.util.Map;
public class BIDUsers {
public static Map<String, Object> fetchUserByDID(BIDTenantInfo tenantInfo, String did, boolean fetchDevices) {
Map<String, Object> ret = null;
try {
BIDCommunityInfo communityInfo = BIDTenant.getInstance().getCommunityInfo(tenantInfo);
BIDKeyPair keySet = BIDTenant.getInstance().getKeySet();
String licenseKey = tenantInfo.licenseKey;
BIDSD sd = BIDTenant.getInstance().getSD(tenantInfo);
String sharedKey = BIDECDSA.createSharedKey(keySet.privateKey, communityInfo.community.publicKey);
Map < String, String > headers = WTM.defaultHeaders();
headers.put("licensekey", BIDECDSA.encrypt(licenseKey, sharedKey));
headers.put("requestid", BIDECDSA.encrypt(new Gson().toJson(WTM.makeRequestId()), sharedKey));
headers.put("publickey", keySet.publicKey);
headers.put("X-TenantTag", communityInfo.tenant.tenanttag);
String url = sd.adminconsole + "/api/r1/community/" + communityInfo.community.name + "/userdid/" + did
+ "/userinfo";
if (fetchDevices) {
url = url + "?devicelist=true";
}
Boolean keepAlive = false;
Map<String, Object> response = WTM.execute("get",
url,
headers,
null,
keepAlive);
String responseStr = (String) response.get("response");
int statusCode = (Integer) response.get("status");
Map<String, String> map = new Gson().fromJson(responseStr, Map.class);
String dec_data = BIDECDSA.decrypt(map.get("data"), sharedKey);
ret = new Gson().fromJson(dec_data, Map.class);
}
catch (Exception e) {
e.printStackTrace();
}
return ret;
}
public static Map<String, Object> fetchUserAccountsByDID(BIDTenantInfo tenantInfo, String did, boolean fetchDevices,
boolean fetchUsers, Map<String, Object> account) {
Map<String, Object> ret = null;
try {
BIDCommunityInfo communityInfo = BIDTenant.getInstance().getCommunityInfo(tenantInfo);
BIDKeyPair keySet = BIDTenant.getInstance().getKeySet();
String licenseKey = tenantInfo.licenseKey;
BIDSD sd = BIDTenant.getInstance().getSD(tenantInfo);
String sharedKey = BIDECDSA.createSharedKey(keySet.privateKey, communityInfo.community.publicKey);
Map<String, String> headers = WTM.defaultHeaders();
headers.put("licensekey", BIDECDSA.encrypt(licenseKey, sharedKey));
headers.put("requestid", BIDECDSA.encrypt(new Gson().toJson(WTM.makeRequestId()), sharedKey));
headers.put("publickey", keySet.publicKey);
headers.put("X-TenantTag", communityInfo.tenant.tenanttag);
String url = sd.adminconsole + "/api/r1/community/" + communityInfo.community.name + "/userdid/" + did
+ "/userinfo/fetch";
Map<String, Object> body = new HashMap<>();
body.put("devicelist", fetchDevices);
body.put("userslist", fetchUsers);
if (account != null) {
body.put("account", account);
}
Boolean keepAlive = false;
Map<String, Object> response = WTM.execute("post", url, headers, new Gson().toJson(body), keepAlive);
String responseStr = (String) response.get("response");
int statusCode = (Integer) response.get("status");
Map<String, String> map = new Gson().fromJson(responseStr, Map.class);
String dec_data = BIDECDSA.decrypt(map.get("data"), sharedKey);
ret = new Gson().fromJson(dec_data, Map.class);
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
}