Just wanted to clarify that the GotDibb data is correct, although my question contradicts this.
I created the 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 ran the same tests as GotDibbs and got the same answers that confused me, because I would not ask if I received any other answer. But then I realized that the problem I saw was caused by a recursive plugin.
The first call to the plugin worked as expected, but when the plugin initiated another call to the plugin, it used the user credentials for the Context plugin (which makes sense) and lost the authenticated user IDs. Here is a table that hopefully helps you figure out what happens.
First for the initial plugin call:
+--------------------+------------ +----------------------+----------------------------------------+ | Org Service | Org Service | Plugin Step Run | Results | | Client Credentials | CallerId | in User Context | | +--------------------+------------ +----------------------+----------------------------------------+ | | | | InitiaitingUser : ServiceAccount | | ServiceAccount | None | PluginServiceAccount | | | | | | UserId : PluginServiceAccount | +--------------------+------------ +----------------------+----------------------------------------+ | | | | InitiaitingUser : UserBob | | ServiceAccount | UserBob | PluginServiceAccount | | | | | | UserId : PluginServiceAccount | +--------------------+------------ +----------------------+----------------------------------------+
And the second for Plugin Depth> 1
+--------------------+------------ +----------------------+----------------------------------------+ | Org Service | Org Service | Plugin Step Run | Results | | Client Credentials | CallerId | in User Context | | +--------------------+-------------+----------------------+----------------------------------------+ | | | | InitiaitingUser : PluginServiceAccount | | ServiceAccount | None | PluginServiceAccount | | | | | | UserId : PluginServiceAccount | +--------------------+-------------+----------------------+----------------------------------------+ | | | | InitiaitingUser : PluginServiceAccount | | ServiceAccount | UserBob | PluginServiceAccount | | | | | | UserId : PluginServiceAccount | +--------------------+-------------+----------------------+----------------------------------------+
Daryl source share