/// <summary> /// Returns XML string of the finished AppLocker policy /// </summary> /// <param name="EnforcementMode">How the policy should be enforced</param> /// <returns>XML Text</returns> public string GetXml(EnforcementMode EnforcementMode = EnforcementMode.NotConfigured) { FailedRules = new List <RuleFailure>(); XmlDocument document = new XmlDocument(); document.LoadXml(String.Format(@" <AppLockerPolicy Version=""1""> <RuleCollection Type=""Exe"" EnforcementMode=""{0}""/> <RuleCollection Type=""Dll"" EnforcementMode=""{0}""/> <RuleCollection Type=""Script"" EnforcementMode=""{0}""/> <RuleCollection Type=""Msi"" EnforcementMode=""{0}""/> <RuleCollection Type=""AppX"" EnforcementMode=""{0}""/> </AppLockerPolicy> ", EnforcementMode.ToString())); foreach (RuleBase ruleItem in Rules) { ruleItem.AddToPolicy(document, this); } XmlWriterSettings settings = new XmlWriterSettings(); settings.NewLineHandling = NewLineHandling.Replace; settings.NewLineChars = "\r\n"; settings.Indent = true; using (var stringWriter = new StringWriter()) using (var xmlTextWriter = XmlWriter.Create(stringWriter, settings)) { document.WriteTo(xmlTextWriter); xmlTextWriter.Flush(); return(stringWriter.GetStringBuilder().ToString()); } }
public BlockLimitItem(EnforcementMode mode, string blocktypeid, string blocksubtypeid, uint maxpergrid, bool adminexempt) { this._mode = mode; this._blockTypeId = blocktypeid; this._blockSubtypeId = blocksubtypeid; this._maxPerGrid = maxpergrid; this._adminExempt = adminexempt; }
internal static PolicyAssignmentData DeserializePolicyAssignmentData(JsonElement element) { Optional <AzureLocation> location = default; Optional <SystemAssignedServiceIdentity> identity = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <string> displayName = default; Optional <string> policyDefinitionId = default; Optional <string> scope = default; Optional <IList <string> > notScopes = default; Optional <IDictionary <string, ArmPolicyParameterValue> > parameters = default; Optional <string> description = default; Optional <BinaryData> metadata = default; Optional <EnforcementMode> enforcementMode = default; Optional <IList <NonComplianceMessage> > nonComplianceMessages = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("location")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } location = new AzureLocation(property.Value.GetString()); continue; } if (property.NameEquals("identity")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } identity = JsonSerializer.Deserialize <SystemAssignedServiceIdentity>(property.Value.ToString()); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("displayName")) { displayName = property0.Value.GetString(); continue; } if (property0.NameEquals("policyDefinitionId")) { policyDefinitionId = property0.Value.GetString(); continue; } if (property0.NameEquals("scope")) { scope = property0.Value.GetString(); continue; } if (property0.NameEquals("notScopes")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <string> array = new List <string>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(item.GetString()); } notScopes = array; continue; } if (property0.NameEquals("parameters")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } Dictionary <string, ArmPolicyParameterValue> dictionary = new Dictionary <string, ArmPolicyParameterValue>(); foreach (var property1 in property0.Value.EnumerateObject()) { dictionary.Add(property1.Name, ArmPolicyParameterValue.DeserializeArmPolicyParameterValue(property1.Value)); } parameters = dictionary; continue; } if (property0.NameEquals("description")) { description = property0.Value.GetString(); continue; } if (property0.NameEquals("metadata")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } metadata = BinaryData.FromString(property0.Value.GetRawText()); continue; } if (property0.NameEquals("enforcementMode")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } enforcementMode = new EnforcementMode(property0.Value.GetString()); continue; } if (property0.NameEquals("nonComplianceMessages")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } List <NonComplianceMessage> array = new List <NonComplianceMessage>(); foreach (var item in property0.Value.EnumerateArray()) { array.Add(NonComplianceMessage.DeserializeNonComplianceMessage(item)); } nonComplianceMessages = array; continue; } } continue; } } return(new PolicyAssignmentData(id, name, type, systemData, Optional.ToNullable(location), identity, displayName.Value, policyDefinitionId.Value, scope.Value, Optional.ToList(notScopes), Optional.ToDictionary(parameters), description.Value, metadata.Value, Optional.ToNullable(enforcementMode), Optional.ToList(nonComplianceMessages))); }