Hello,
would anyone advise on how to efficiently setup user impersonation in a datacontext?
In PB I can connect a DB as dba and then issue the statement EXECUTE AS mmeoni, so that all subsequent SQL statements will execute as user mmeoni, but still use the connection established with the dba user.
How the API would handle this with the connection pool?
I'd rather avoid wrapping each request into an explicit transaction with upfront EXECUTE AS:
_context.BeginTransaction();
ls_sql = "EXECUTE AS " + username;
_context.SqlExecutor.ExecuteNonQuery(ls_sql, out SqlResult sqlResult);
// any transaction here will impersonate user mmeoni
_context.Commit();
Ideally, impersonation should happen when an instance of datacontext is injected into the service class.
Any suggestion will be welcome.
Cheers,
.m
Extreme case scenario, a different user per each client.
I want to use the pool as defined in the cachename settings (i.e dba/sa user), but run SQL statements as impersonated users (username can come from custom HTTP header in the client request).
Cheers,
.m
Regards - Francisco