Operations which can be performed using the API should also take into consideration the user who is attempting to perform the operation and any restriction(s) they may have. This can be accomplished by calling the ManagingEnergyAPI.Login() method which sets the user identity on whose behalf the code is running (see the chapter on security for more in depth discussion). Alternatively, you can manually set the user identity of the thread context by calling ManagingEnergy.Security.UserPrincipal.SetIdentity(). In either case when the users identity as been set, execution is said to be running in a “Secure Context”.
// login as a specific user
User user = api.Login("cpowers", "mypassword");
// alternatively you can manually set the user identity for the thread context
All subsequent calls to the API will run under cpowers’ user identity. Hence, if cpowers attempts to perform an operation which he does not have privilege based on his role memberships; a security exception will be thrown. Operations performed by the API will consider the user’s identity such that only data which the user has access is returned.