Just wanted to clarify that GotDibb's data is correct, even though my question contradicts it.
I created a UserIdTest Plugin as follows
public void Execute(IServiceProvider serviceProvider)
{
var context = serviceProvider.GetContext();
var service = serviceProvider.GetService(context);
var iUser = service.Retrieve("systemuser", context.InitiatingUserId, new ColumnSet("fullname"));
var uUser = service.Retrieve("systemuser", context.UserId, new ColumnSet("fullname"));
throw new Exception(string.Format("Initiating: {0}, User: {1}",
iUser.GetAttributeValue<string>("fullname"),
uUser.GetAttributeValue<string>("fullname")));
}
I Performed the same testing as GotDibbs, and got the same answers, which confused me because I wouldn't have asked the question if I wasn't somehow getting a different answer. But then I realized that the issue I was seeing was being caused by a recursive plugin.
The first call to the plugin worked as expected, but when the plugin triggered another call to the plugin, it used the plugin's Context user's credentials (which makes sense) and lost the impersonated user id's credentials. Here is a table to hopefully help clarify what happens
First for the initial plugin call:
+--------------------+------------ +----------------------+----------------------------------------+
| Org Service | Org Service | Plugin Step Run | Results |
| Client Credentials | CallerId | in User's Context | |
+--------------------+------------ +----------------------+----------------------------------------+
| | | | InitiaitingUser : ServiceAccount |
| ServiceAccount | None | PluginServiceAccount | |
| | | | UserId : PluginServiceAccount |
+--------------------+------------ +----------------------+----------------------------------------+
| | | | InitiaitingUser : UserBob |
| ServiceAccount | UserBob | PluginServiceAccount | |
| | | | UserId : PluginServiceAccount |
+--------------------+------------ +----------------------+----------------------------------------+
And second for the Plugin Depth > 1
+--------------------+------------ +----------------------+----------------------------------------+
| Org Service | Org Service | Plugin Step Run | Results |
| Client Credentials | CallerId | in User's Context | |
+--------------------+-------------+----------------------+----------------------------------------+
| | | | InitiaitingUser : PluginServiceAccount |
| ServiceAccount | None | PluginServiceAccount | |
| | | | UserId : PluginServiceAccount |
+--------------------+-------------+----------------------+----------------------------------------+
| | | | InitiaitingUser : PluginServiceAccount |
| ServiceAccount | UserBob | PluginServiceAccount | |
| | | | UserId : PluginServiceAccount |
+--------------------+-------------+----------------------+----------------------------------------+