Sunday, 21 August 2016

c# - SDE FeatureClass Granting and Revoking Privilege with ArcObjects


How can I with ArcObjects GRANT or REVOKE Privileges like SELECT, UPDATE on SDE FeatureClasses to/from Roles?



The equivalent in normal Oracle would be something like this:


GRANT SELECT ON SCHEMA.TABLE TO SOME_ROLE;
REVOKE SELECT ON SCHEMA.TABLE FROM SOME_ROLE;

I can't seem to find the interface to perform this task, and it may not exists?


My dream would be to have an Interface like this:


public interface IPrivilegeManager
{
void Grant(string privilegeName, string schemaOwnerName, string featureClassName, string roleName);
void Revoke(string privilegeName, string schemaOwnerName, string featureClassName, string roleName);

}

Related Q: For a SDE FeatureClasses list all Roles that have been Granted any Privileges on it, and which Privileges each Role have on it



Answer



You can obtain the name object for the given feature class and cast it to ISQLPrivilege, which allows you to enumerate, grant and revoke permissions.


E.g.:


var name = ((IDataset) featureClass).FullName;
var sqlPrivilege = name as ISQLPrivilege;
if (sqlPrivilege != null)
{

sqlPrivilege.Grant("USER_OR_ROLE_NAME", (int) esriSQLPrivilege.esriSelectPrivilege, false);
}

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...