Example #1
0
        private void CheckAccessControl(AuthorizationRuleCollection authorizationRules, out Boolean canRead, out Boolean canWrite)
        {
            var rules = authorizationRules
                            .OfType<FileSystemAccessRule>()
                            .Where(x => User.IsInRole(x.IdentityReference as SecurityIdentifier) || x.IdentityReference == ((WindowsIdentity)User.Identity).User)
                            .ToList();
            canRead = true;
            canWrite = true;

            canRead &= rules.Any(x => x.AccessControlType == AccessControlType.Allow &&
                                        x.FileSystemRights.HasFlag(FileSystemRights.Read));
            canWrite &= rules.Any(x => x.AccessControlType == AccessControlType.Allow &&
                                        x.FileSystemRights.HasFlag(FileSystemRights.Write));
            canRead &= !rules.Any(x => x.AccessControlType == AccessControlType.Deny &&
                                        x.FileSystemRights.HasFlag(FileSystemRights.Read));
            canWrite &= !rules.Any(x => x.AccessControlType == AccessControlType.Deny &&
                                        x.FileSystemRights.HasFlag(FileSystemRights.Write));
        }