AnsweredAssumed Answered

Checking Permission to write into PI AF Server from Code C#

Question asked by Kamil.Grzadziela on Oct 10, 2019
Latest reply on Oct 11, 2019 by Kamil.Grzadziela

Hello,
Im trying to check Write permission from code in c# through osi af sdk on my localhost Machine.
Every time i have same result:

 

 

OSIsoft.AF.PISystems piSystems = new OSIsoft.AF.PISystems();

PISystem pISystem = piSystems["xxxxx"];
Console.WriteLine("CanWrite " + pISystem.Security.CanWrite);
Console.WriteLine("CanWriteData " + pISystem.Security.CanWriteData);
Console.WriteLine("Security Rights " + pISystem.Security.SecurityRights);

PISystems piSystems2 = new PISystems();
PISystem piSystem2 = piSystems["xxxxx"];
AFDatabase afDatabase = piSystem2.Databases["YourDatabase"];
AFSecurity secObj = afDatabase.Security;
Console.WriteLine("Drugi CanWrite" + secObj.CanWrite);
Console.WriteLine("CanWriteData " + secObj.CanWriteData);
Console.WriteLine("Security Rights " + secObj.SecurityRights);

WindowsIdentity user = new WindowsIdentity("xxxx");
AFSecurity security1 = afDatabase.Security;
AFSecurityRights rights = security1.CheckSecurity(user);
Console.WriteLine("SecurityRights for '{0}': '{1}'", afDatabase.Name, rights);
Console.WriteLine(" CanRead={0}", rights.CanRead());
Console.WriteLine(" CanWrite={0}", rights.CanWrite());

CanWrite True
CanWriteData False
Security Rights ReadWrite, Delete, Admin
Drugi CanWriteTrue
CanWriteData False
Security Rights ReadWrite, Delete, Admin
SecurityRights for 'YourDatabase': 'ReadWrite, Delete, Admin'
CanRead=True
CanWrite=True

 

Even when i lost all permission to my Local server (deleted all permission) i couldnt even open the pi explorer cus of lack permission . Still had same output in visualStudio.

Outcomes