Forum Discussion

miraks's avatar
miraks
Creator II
3 years ago

How to use GrantIdentity ?

Hi,

On ARAS R12, in server methods, I needed to grant temporary some rights.
For that, I did something like this:

var myidentity = Aras.Server.Security.Identity.GetByName("My Identity");
bool PermissionWasSet = Aras.Server.Security.Permissions.GrantIdentity();

try {
    /**************YOUR SPECIAL CODE HERE***************/
    finally
    {
    if (PermissionWasSet) Aras.Server.Security.Permissions.RevokeIdentity(myidentity);
}

Due to deprecated API, on ARAS R19, I need to use CCO.Permissions.GrantIdentity but this method doesn't return a boolean to know if the identity has been granted or not.

How should I do ? When and how to do the RevokeIdentity ?

Is this enough ?

using (CCO.Permissions.GrantIdentity(Aras.Server.Security.Identity.GetByName("My Identity")))
{
	/**************YOUR SPECIAL CODE HERE***************/
}

Thank you in advance for your answer.

4 Replies

  • I don´t use R19, but I am highly interested in this topic!

    How does Aras solve this one in the Method "PE_AffectedItemFloat" or "PE_ChangeItemTransition"? New variant should be visible in the beginning in the code if they don´t have changed the code completely.

    • miraks's avatar
      miraks
      Creator II

      Hi,

      In PE_AffectedItemFloat, I found this:

      [embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:f4b854ff-9a17-4a56-a6cf-8ab991a8ace6:type=csharp&text=Aras.Server.Security.Identity%20plmIdentity%20%3D%20Aras.Server.Security.Identity.GetByName%28%22Aras%20PLM%22%29%3B%0D%0AIDisposable%20elevatedPermissionsScope%20%3D%20CCO.Permissions.GrantIdentity%28plmIdentity%29%3B%0D%0A%0D%0A...%0D%0A%0D%0A%2F%2F%20Revoke%20%27Aras%20PLM%27%20permissions%0D%0AelevatedPermissionsScope%3F.Dispose%28%29%3B%0D%0A%0D%0Areturn%20this%3B]

      So, the temporary grant is revoked with the call to Dispose.

      So, this should work well:

      [embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:c2616d20-184c-4730-8993-bbddd2cf0940:type=text&text=using%20%28CCO.Permissions.GrantIdentity%28Aras.Server.Security.Identity.GetByName%28%22My%20Identity%22%29%29%29%0D%0A%7B%0D%0A%09%2F%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2AYOUR%20SPECIAL%20CODE%20HERE%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2A%2F%0D%0A%7D]

      • angela's avatar
        angela
        Catalyst II

        Your "using" variant sounds right for me! I already fear the amount of Methods I have to update manually once there is a new open release.[emoticon:4b473fb4671244b2a5887318abe9e44a]

        Is there somewhere an overview of the code impact due to .NET Core changes?