public static IAccessControlEntry MakeGenericAceFromType(Type rightType, Dictionary <string, string> props = null, bool isAuditAce = false) { rightType.ValidateIsEnum(); IAccessControlEntry ace = null; Type objectType = isAuditAce ? typeof(AccessControlEntryAudit <>) : typeof(AccessControlEntry <>); Type genericType = objectType.MakeGenericType(rightType); object instance = Activator.CreateInstance(genericType); ace = (IAccessControlEntry)instance; IAccessControlEntryAudit auditAce = isAuditAce ? (IAccessControlEntryAudit)ace : null; if (props?.Count > 0) { foreach (string prop in props.Keys) { if (prop.Equals(nameof(ace.UId))) { ace.UId = Guid.Parse(props[prop]); } else if (prop.Equals(RightFields.Right)) { ace.SetRight(props[prop]); } else if (prop.Equals(nameof(ace.Allowed))) { ace.Allowed = bool.Parse(props[prop]); } else if (isAuditAce && prop.Equals(nameof(auditAce.Denied))) { auditAce.Denied = bool.Parse(props[prop]); } else if (prop.Equals(nameof(ace.Inheritable))) { ace.Inheritable = bool.Parse(props[prop]); } else if (prop.Equals(nameof(ace.InheritedFrom))) { ace.InheritedFrom = Guid.Parse(props[prop]); } else if (prop.Equals(nameof(ace.TrusteeUId))) { ace.TrusteeUId = Guid.Parse(props[prop]); } } } return(ace); }
int EvalRights(int allowedMask, int deniedMask) { Type rightType = Ace.RightData.RightType; IAccessControlEntry allowedAce = AccessControlEntryUtilities.MakeGenericAceFromType(rightType); allowedAce.Allowed = true; allowedAce.SetRight(allowedMask.ToString()); IAccessControlEntry deniedAce = AccessControlEntryUtilities.MakeGenericAceFromType(rightType); deniedAce.Allowed = false; deniedAce.SetRight(deniedMask.ToString()); _sd.Clear(); _sd.Dacl.Add(allowedAce); _sd.Dacl.Add(deniedAce); _sd.Eval(rightType); //suppress reentrancy into this function: IsChecked=true fires CheckBox_Checked _suppressRightsEval = true; int mask = 0; foreach (CheckBox cb in this.Items) { cb.IsChecked = _sd.Results.GetByTypeRight(rightType, (int)cb.Content).AccessAllowed; if (cb.IsChecked.Value) { mask |= (int)cb.Content; } } _suppressRightsEval = false; return(mask); }