Adam Carter
Adam Carter

Reputation: 35

In Active Directory, how do I determine type of ActiveDirectoryAccessRule?

I can get a collection of access rules for an Active Directory object using code such as

ActiveDirectorySecurity ads = directoryEntry.ObjectSecurity;
AuthorizationRuleCollection arc = ads.GetAccessRules(true, true, typeof(NTAccount));

foreach (ActiveDirectoryAccessRule adar in arc)
{
    // get rule properties
}

However, I would like to know if each rule is also of one of the ActiveDirectoryAccessRule subtypes such as PropertyAccessRule.

Is this possible? I don't see a class property that provides this information.

Upvotes: 3

Views: 1592

Answers (1)

Yahia
Yahia

Reputation: 70369

you can use is to check for the type - for example:

if (adar is System.DirectoryServices.PropertyAccessRule )
{
// do whatever you need to do if it is a PropertyAccessRule...
}

you can do this with the following because all inherit from ActiveDirectoryAccessRule :

System.DirectoryServices.CreateChildAccessRule
System.DirectoryServices.DeleteChildAccessRule
System.DirectoryServices.DeleteTreeAccessRule
System.DirectoryServices.ExtendedRightAccessRule
System.DirectoryServices.ListChildrenAccessRule
System.DirectoryServices.PropertyAccessRule
System.DirectoryServices.PropertySetAccessRule

see
http://msdn.microsoft.com/en-us/library/system.directoryservices.activedirectoryaccessrule.aspx#inheritanceContinued

Upvotes: 1

Related Questions