Example of using the AR System Server REST API to impersonate a user
When an administrator impersonates a user, the administrator continues to utilize the fixed license.
You impersonate a user by using the ARSetImpersonatedUser API call. For more information, see Impersonating-a-user.
The following table gives you details about using the X-AR-Impersonated-User header in the GET operation:
URL qualifier | /entry/{formName}/{entryId} formName is the name of the form for which an entry must be read. | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Method | GET | ||||||||||||||||||||
Headers |
| ||||||||||||||||||||
Parameters |
For more information, see Endpoints-in-AR-REST-API. | ||||||||||||||||||||
Returns | An entry object | ||||||||||||||||||||
All possible error codes | If the request is not successful, one of the following error code is returned:
For more information, see Error-handling-for-the-REST-API. | ||||||||||||||||||||
Notes | The entry object contains field values for all data fields to which the user has permission. |
Here is a sample code to impersonate a user:
import java.util.Base64;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class Get {
public static void main(String[] args) throws Exception {
String token = args[0];
// start HTTP GET to get an entry
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(
"http://localhost:8008/api/arsys/v1/entry/User/000000000000001");
// add the token to the header
httpGet.addHeader("Authorization", "AR-JWT" + token);
String impersonatedUserName = "Demo2";
httpGet.addHeader("X-AR-Impersonated-User",
new String(Base64.getEncoder().encode(impersonatedUserName.getBytes(StandardCharsets.UTF_8)),
StandardCharsets.UTF_8));
// make the call and print the status
try
(CloseableHttpResponse response = httpClient.execute(httpGet)) {
HttpEntity entity = response.getEntity();
String jsonEntry = EntityUtils.toString(entity, StandardCharsets.UTF_8);
System.out.println(jsonEntry);
}
}
}
You can also use the script as described in the TestHttpClient - Command line tool to test HTTP(S) services article on BMC Communities.
The AR API log describes which user is impersonating another user. In the following example, the user Demo 2 is impersonated by user Demo:
<TID: 0000000427> <RPC ID: 0000000868> <Queue:
Fast > <Client-RPC: 390620 >
<USER: Demo2 -- Impersonated by Demo
-- >
<Overlay-Group: 0 > /*
Mon Dec 21 2020 16:06:47.1010 */ +GE
ARGetEntry -- schema User entryId 000000000000001 from Unidentified Client
(protocol 19) at IP address 10.135.36.67 using REST // :q:0.0s null
<API > <TrID: svErZYSGQBO89IWpSQuPJQ:0000001>
<TID: 0000000427> <RPC ID: 0000000868> <Queue:
Fast > <Client-RPC: 390620 >
<USER: Demo2 -- Impersonated by Demo
-- >
<Overlay-Group: 0 >
/* Mon Dec 21 2020 16:06:47.1060 */ -GE
OK