private void ModelChildCreated([NotNull] ISeverity severity) { if (severity.Visible) { AddGridRow(severity, _grid.PrimaryGrid); } }
public IThreatEventScenario AddScenario(IThreatActor threatActor, ISeverity severity, string name = null) { if (!(IsInitialized?.Get() ?? false)) { return(null); } if (threatActor == null) { throw new ArgumentNullException(nameof(threatActor)); } if (severity == null) { throw new ArgumentNullException(nameof(severity)); } IThreatEventScenario result = new ThreatEventScenario(MySelf?.Get(), threatActor, name) { Severity = severity }; if (_scenarios == null) { _scenarios = new List <IThreatEventScenario>(); } _scenarios.Add(result); Dirty.IsDirty = true; _threatEventScenarioAdded?.Invoke(ScenariosContainer?.Get(), result); return(result); }
private bool IsUsed([NotNull] ISeverity severity) { return((_entities?.Any(x => x.ThreatEvents?.Any(y => y.Severity == severity) ?? false) ?? false) || (_entities?.Any(x => x.ThreatEvents?.Any(y => y.Scenarios?.Any(z => z.Severity == severity) ?? false) ?? false) ?? false) || (_dataFlows?.Any(x => x.ThreatEvents?.Any(y => y.Severity == severity) ?? false) ?? false) || (_dataFlows?.Any(x => x.ThreatEvents?.Any(y => y.Scenarios?.Any(z => z.Severity == severity) ?? false) ?? false) ?? false) || (_threatTypes?.Any(x => x.Severity == severity) ?? false)); }
public Row([NotNull] IThreatType threatType, [NotNull] ISeverity severity, IEnumerable <IThreatEventMitigation> mitigations) { RowType = RowType.ThreatType; Values = new [] { threatType.Name, severity.Name, null }; Identity = threatType; SeverityTextColor = severity.TextColor; SeverityBackColor = severity.BackColor; Mitigations = mitigations; }
public static bool ApplyMitigations(this IThreatEvent threatEvent) { bool result = false; if (threatEvent.ThreatType is IThreatType threatType && threatEvent.Model is IThreatModel model && threatEvent.Parent is IIdentity identity) { var mitigations = threatType.Mitigations?.ToArray(); if (mitigations?.Any() ?? false) { ISeverity maximumSeverity = null; var generated = false; foreach (var mitigation in mitigations) { var rule = GetRule(mitigation); if (rule?.Evaluate(identity) ?? false) { var strength = mitigation.Strength; if (rule.StrengthId.HasValue && model.GetStrength(rule.StrengthId.Value) is IStrength strengthOverride) { strength = strengthOverride; } if (rule.Status.HasValue) { generated = (threatEvent.AddMitigation(mitigation.Mitigation, strength, rule.Status.Value) != null); } else { generated = (threatEvent.AddMitigation(mitigation.Mitigation, strength) != null); } result |= generated; if (generated && rule.SeverityId.HasValue && model.GetSeverity(rule.SeverityId.Value) is ISeverity severity && (maximumSeverity == null || maximumSeverity.Id > severity.Id)) { maximumSeverity = severity; } } } if (maximumSeverity != null && maximumSeverity.Id < threatEvent.SeverityId) { threatEvent.Severity = maximumSeverity; } } } return(result); }
private void ModelChildRemoved([NotNull] ISeverity severity) { var row = GetRow(severity); if (row != null) { RemoveEventSubscriptions(row); _grid.PrimaryGrid.Rows.Remove(row); } }
private void _severities_SelectedIndexChanged(object sender, EventArgs e) { if (_severities.SelectedItem is ISeverity severity) { _severity = severity; _ok.Enabled = true; } else { _ok.Enabled = false; } }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { if ((this._parent.Sev == null)) { ISeverity sevCasted = item.As <ISeverity>(); if ((sevCasted != null)) { this._parent.Sev = sevCasted; return; } } }
//--------------------------------------------------------------------- public Parameters(int timestep, IEventParameters[] eventParameters, ISeverity[] severities, string mapNameTemplate, string logFileName) { this.timestep = timestep; this.eventParameters = eventParameters; this.severities = severities; this.mapNamesTemplate = mapNameTemplate; this.logFileName = logFileName; }
public void Add([NotNull] ISeverity severity) { if (_severities == null) { _severities = new List <ISeverity>(); } _severities.Add(severity); SetDirty(); _severityCreated?.Invoke(severity); }
public ThreatType([NotNull] IThreatModel model, [Required] string name, [NotNull] ISeverity severity) : this() { _id = Guid.NewGuid(); _model = model; _modelId = model.Id; Name = name; _severity = severity; _severityId = severity.Id; model.AutoApplySchemas(this); }
public IWeakness AddWeakness([Required] string name, [NotNull] ISeverity severity) { IWeakness result = null; if (GetWeakness(name) == null) { result = new Weakness(this, name, severity); Add(result); RegisterEvents(result); } return(result); }
public IThreatType AddThreatType([Required] string name, [NotNull] ISeverity severity) { IThreatType result = null; if (GetThreatType(name) == null) { result = new ThreatType(this, name, severity); Add(result); RegisterEvents(result); } return(result); }
public ISeverity AddSeverity([Range(0, 100)] int id, [Required] string name) { ISeverity result = null; if (!(_severities?.Any(x => x.Id == id) ?? false)) { result = new SeverityDefinition(this, id, name); Add(result); RegisterEvents(result); } return(result); }
private void _ok_Click(object sender, EventArgs e) { int id = GetFreeIdUp(_id.Value); if (id == (int)DefaultSeverity.Unknown) { id = GetFreeIdDown(_id.Value); } if (id > 0) { _severity = _threatModel.AddSeverity(id, _name.Text); _severity.Description = _description.Text; } }
public void Add([NotNull] ISeverity severity) { if (_severities == null) { _severities = new List <ISeverity>(); } _severities.Add(severity); if (this == ThreatModelManager.Model) { Dirty.IsDirty = true; _severityCreated?.Invoke(severity); } }
/// <summary> /// Get the maximum severity applied to the Threat Events derived from the specific Threat Type. /// </summary> /// <param name="threatType">Threat Type to be analyzed.</param> /// <returns>Maximum severity applied to Threat Events derived from the Threat Type.</returns> public static ISeverity GetTopSeverity(this IThreatType threatType) { ISeverity result = null; var model = threatType.Model; if (model != null) { var modelTe = model.ThreatEvents?.Where(x => x.ThreatTypeId == threatType.Id) .OrderByDescending(x => x.SeverityId).FirstOrDefault(); if (modelTe != null) { result = modelTe.Severity; } var entitiesTe = model.Entities? .Select(e => e.ThreatEvents?.Where(x => x.ThreatTypeId == threatType.Id) .OrderByDescending(x => x.SeverityId).FirstOrDefault()) .Where(x => x != null).ToArray(); if (entitiesTe?.Any() ?? false) { foreach (var entityTe in entitiesTe) { if (result == null || entityTe.SeverityId > result.Id) { result = entityTe.Severity; } } } var flowsTe = model.DataFlows? .Select(e => e.ThreatEvents?.Where(x => x.ThreatTypeId == threatType.Id) .OrderByDescending(x => x.SeverityId).FirstOrDefault()) .Where(x => x != null).ToArray(); if (flowsTe?.Any() ?? false) { foreach (var flowTe in flowsTe) { if (result == null || flowTe.SeverityId > result.Id) { result = flowTe.Severity; } } } } return(result); }
/// <summary> /// Get the maximum severity applied to the Vulnerabilities derived from the specific Weakness. /// </summary> /// <param name="weakness">Weakness to be analyzed.</param> /// <returns>Maximum severity applied to Vulnerabilities derived from the Weakness.</returns> public static ISeverity GetTopSeverity(this IWeakness weakness) { ISeverity result = null; var model = weakness.Model; if (model != null) { var modelV = model.Vulnerabilities?.Where(x => x.WeaknessId == weakness.Id) .OrderByDescending(x => x.SeverityId).FirstOrDefault(); if (modelV != null) { result = modelV.Severity; } var entitiesV = model.Entities? .Select(e => e.Vulnerabilities?.Where(x => x.WeaknessId == weakness.Id) .OrderByDescending(x => x.SeverityId).FirstOrDefault()) .Where(x => x != null).ToArray(); if (entitiesV?.Any() ?? false) { foreach (var entityV in entitiesV) { if (result == null || entityV.SeverityId > result.Id) { result = entityV.Severity; } } } var flowsV = model.DataFlows? .Select(e => e.Vulnerabilities?.Where(x => x.WeaknessId == weakness.Id) .OrderByDescending(x => x.SeverityId).FirstOrDefault()) .Where(x => x != null).ToArray(); if (flowsV?.Any() ?? false) { foreach (var flowV in flowsV) { if (result == null || flowV.SeverityId > result.Id) { result = flowV.Severity; } } } } return(result); }
private GridRow GetRow([NotNull] ISeverity severity) { GridRow result = null; var rows = _grid.PrimaryGrid.Rows.OfType <GridRow>().ToArray(); foreach (var row in rows) { if (row.Tag == severity) { result = row; break; } } return(result); }
private void AddGridRow([NotNull] ISeverity severity, [NotNull] GridPanel panel) { var row = new GridRow( severity.Id, severity.Name, severity.Description, severity.Visible, severity.TextColor.ToString(), severity.BackColor.ToString()); ((INotifyPropertyChanged)severity).PropertyChanged += OnSeverityPropertyChanged; row.Tag = severity; for (int i = 0; i < row.Cells.Count; i++) { row.Cells[i].PropertyChanged += OnPropertyChanged; } panel.Rows.Add(row); }
protected static ISeverity GetMaximumSeverity(IEnumerable <IThreatEvent> threatEvents) { ISeverity result = null; var array = threatEvents?.ToArray(); if (array?.Any() ?? false) { foreach (var item in array) { if (result == null || result.Id < (item.Severity?.Id ?? 0)) { result = item.Severity; } } } return(result); }
public static ISeverity GetCalculatedSeverity(this IThreatEvent threatEvent, int configDelta) { ISeverity result = null; if (threatEvent != null) { var totalStrength = (threatEvent.Mitigations? .Where(x => x.Status == MitigationStatus.Existing || x.Status == MitigationStatus.Implemented) .Sum(x => x.StrengthId) ?? 0) - configDelta; var severity = Math.Max(threatEvent.ThreatType.SeverityId, threatEvent.Scenarios?.Max(x => x.SeverityId) ?? 0); var projected = (int)Math.Max(Math.Ceiling(severity * (1.0 - (Math.Min(totalStrength, 100.0) / 100.0))), 1.0); result = threatEvent.Model?.GetMappedSeverity(projected); } return(result); }
private ISeverity GetTopSeverity(List <IThreatEvent> threats) { ISeverity result = null; if (threats?.Any() ?? false) { foreach (var threat in threats) { if (result == null) { result = threat.Severity; } else if (threat.SeverityId > result.Id) { result = threat.Severity; } } } return(result); }
public IThreatEventScenario AddScenario(IThreatActor threatActor, ISeverity severity, string name = null) { if (threatActor == null) { throw new ArgumentNullException(nameof(threatActor)); } if (severity == null) { throw new ArgumentNullException(nameof(severity)); } IThreatEventScenario result = null; if (Instance is IThreatEvent threatEvent) { result = new ThreatEventScenario(threatEvent, threatActor, name) { Severity = severity }; if (_scenarios == null) { _scenarios = new List <IThreatEventScenario>(); } _scenarios.Add(result); if (Instance is IDirty dirtyObject) { dirtyObject.SetDirty(); } if (Instance is IThreatEventScenariosContainer container) { _threatEventScenarioAdded?.Invoke(container, result); } } return(result); }
private bool IsSelected([NotNull] ISeverity item, [Required] string filter) { var result = (!string.IsNullOrWhiteSpace(item.Name) && item.Name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0) || (!string.IsNullOrWhiteSpace(item.Description) && item.Description.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0); if (!result && (item.Properties?.Any() ?? false)) { var properties = item.Properties.ToArray(); foreach (var property in properties) { var stringValue = property.StringValue; if ((!string.IsNullOrWhiteSpace(stringValue) && stringValue.IndexOf(filter, StringComparison.OrdinalIgnoreCase) >= 0)) { result = true; break; } } } return(result); }
public ISeverity GetMappedSeverity(int id) { ISeverity result = null; if (_severities?.Any() ?? false) { var severities = _severities?.Where(x => x.Visible).OrderBy(x => x.Id).ToArray(); foreach (var severity in severities) { if (severity.Id >= id) { result = severity; break; } } if (result == null) { result = severities.LastOrDefault(); } } return(result); }
//--------------------------------------------------------------------- public static void Initialize(IEventParameters[] eventParameters, ISeverity[] severities, int timestep) { windEventParms = eventParameters; Event.severities = severities; Event.timestep = timestep; successionPlugIn = Model.GetSuccession<AgeCohort.ICohort>(); cohorts = successionPlugIn.Cohorts; }
/// <summary> /// Creates a new observable property access proxy /// </summary> /// <param name="modelElement">The model instance element for which to create the property access proxy</param> public ValProxy(ISeverity modelElement) : base(modelElement, "val") { }
//--------------------------------------------------------------------- public static void Initialize(IEventParameters[] eventParameters, ISeverity[] severities) { windEventParms = eventParameters; Event.severities = severities; }
public static bool ApplyMitigations(this IThreatEvent threatEvent, bool topOnly, AutoGenRulesPropertySchemaManager schemaManager = null) { bool result = false; if (threatEvent.ThreatType is IThreatType threatType && threatEvent.Model is IThreatModel model && threatEvent.Parent is IIdentity identity) { if (schemaManager == null) { schemaManager = new AutoGenRulesPropertySchemaManager(model); } var mitigations = threatType.Mitigations? .Where(x => !topOnly || schemaManager.IsTop(x)) .ToArray(); if (mitigations?.Any() ?? false) { ISeverity maximumSeverity = null; foreach (var mitigation in mitigations) { var rule = GetRule(mitigation); if (rule?.Evaluate(identity) ?? false) { var strength = mitigation.Strength; if (rule is MitigationSelectionRule mitigationRule) { if (mitigationRule.StrengthId.HasValue && model.GetStrength(mitigationRule.StrengthId.Value) is IStrength strengthOverride) { strength = strengthOverride; } var status = mitigationRule.Status ?? MitigationStatus.Undefined; var generated = (threatEvent.AddMitigation(mitigation.Mitigation, strength, status) != null); result |= generated; if (generated && mitigationRule.SeverityId.HasValue && model.GetSeverity(mitigationRule.SeverityId.Value) is ISeverity severity && (maximumSeverity == null || maximumSeverity.Id > severity.Id)) { maximumSeverity = severity; } } else { result |= (threatEvent.AddMitigation(mitigation.Mitigation, strength, MitigationStatus.Undefined) != null); } } } if (maximumSeverity != null && maximumSeverity.Id < threatEvent.SeverityId) { threatEvent.Severity = maximumSeverity; } } } return(result); }
//--------------------------------------------------------------------- public static void Initialize(IEventParameters[] eventParameters, ISeverity[] severities, int timestep) { windEventParms = eventParameters; Event.severities = severities; Event.timestep = timestep; }
//--------------------------------------------------------------------- public static void Initialize(IEventParameters[] eventParameters, ISeverity[] severities) { windEventParms = eventParameters; Event.severities = severities; //Event.timestep = Model.Core.Timestep; cohorts = Model.Core.SuccessionCohorts as ILandscapeCohorts; if (cohorts == null) throw new System.ApplicationException("Error: Cohorts don't support age-cohort interface"); // successionPlugIn = Model.GetSuccession<AgeCohort.ICohort>(); // cohorts = successionPlugIn.Cohorts; }
public static bool ApplyMitigations(this IThreatEvent threatEvent, IJsonSerializableObjectPropertyType propertyType = null) { bool result = false; if (threatEvent.ThreatType is IThreatType threatType && threatEvent.Model is IThreatModel model && threatEvent.Parent is IIdentity identity) { if (propertyType == null) { var schemaManager = new AutoThreatGenPropertySchemaManager(model); propertyType = schemaManager.GetPropertyType() as IJsonSerializableObjectPropertyType; } if (propertyType != null) { var mitigations = threatType.Mitigations?.ToArray(); if (mitigations?.Any() ?? false) { ISeverity maximumSeverity = null; var generated = false; foreach (var mitigation in mitigations) { var mProperty = mitigation.GetProperty(propertyType); if (mProperty is IPropertyJsonSerializableObject jsonMProperty && jsonMProperty.Value is MitigationSelectionRule mRule && mRule.Evaluate(identity)) { var strength = mitigation.Strength; if (mRule.StrengthId.HasValue && model.GetStrength(mRule.StrengthId.Value) is IStrength strengthOverride) { strength = strengthOverride; } if (mRule.Status.HasValue) { generated = (threatEvent.AddMitigation(mitigation.Mitigation, strength, mRule.Status.Value) != null); } else { generated = (threatEvent.AddMitigation(mitigation.Mitigation, strength) != null); } result |= generated; if (generated && mRule.SeverityId.HasValue && model.GetSeverity(mRule.SeverityId.Value) is ISeverity severity && (maximumSeverity == null || maximumSeverity.Id > severity.Id)) { maximumSeverity = severity; } } } if (maximumSeverity != null && maximumSeverity.Id < threatEvent.SeverityId) { threatEvent.Severity = maximumSeverity; } } } } return(result); }
public Threshold([NotNull] ISeverity severity, [Positive] decimal value) : this(severity.Id, value) { }
public int CompareTo(ISeverity obj) { var comparer = new SeverityComparer(); return(comparer.Compare(this, obj)); }