Navigation:  USING THE API > 3.2 WORKING WITH USERS >

3.2.1 Running under a User's Privileges

Previous page Next page
  rev. 2007-12-04        

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

ManagingEnergy.Security.UserPrincipal.SetIdentity(user);

User IDentity and API behaviour

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.



3.2.1_Running_under_a_Users_Pr         ©2017 Managing Energy Inc.