示例#1
0
        private void RemoveRelatedForDataFlows([NotNull] IThreatActor actor)
        {
            var dataFlows = _dataFlows?.ToArray();

            if (dataFlows?.Any() ?? false)
            {
                foreach (var dataFlow in dataFlows)
                {
                    var events = dataFlow.ThreatEvents?.ToArray();
                    if (events?.Any() ?? false)
                    {
                        foreach (var threatEvent in events)
                        {
                            var scenarios = threatEvent.Scenarios?.Where(x => x.ActorId == actor.Id).ToArray();
                            if (scenarios?.Any() ?? false)
                            {
                                foreach (var scenario in scenarios)
                                {
                                    threatEvent.RemoveScenario(scenario.Id);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        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);
        }
示例#3
0
        private void RemoveRelatedForEntities([NotNull] IThreatActor actor)
        {
            var entities = _entities?.ToArray();

            if (entities?.Any() ?? false)
            {
                foreach (var entity in entities)
                {
                    var events = entity.ThreatEvents?.ToArray();
                    if (events?.Any() ?? false)
                    {
                        foreach (var threatEvent in events)
                        {
                            var scenarios = threatEvent.Scenarios?.Where(x => x.ActorId == actor.Id).ToArray();
                            if (scenarios?.Any() ?? false)
                            {
                                foreach (var scenario in scenarios)
                                {
                                    threatEvent.RemoveScenario(scenario.Id);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#4
0
 public void Apply([NotNull] IThreatActor actor)
 {
     _id         = actor.Id;
     Description = actor.Description;
     _actor      = actor.ActorType;
     actor.CloneProperties(this);
 }
示例#5
0
        public void Add([NotNull] IThreatActor actor)
        {
            if (_actors == null)
            {
                _actors = new List <IThreatActor>();
            }

            _actors.Add(actor);

            SetDirty();
            ChildCreated?.Invoke(actor);
        }
示例#6
0
        private void AddGridRow([NotNull] IThreatActor actor, [NotNull] GridPanel panel)
        {
            var row = new GridRow(
                actor.Name);

            ((INotifyPropertyChanged)actor).PropertyChanged += OnActorPropertyChanged;
            row.Tag = actor;
            row.Cells[0].CellStyles.Default.Image = actor.GetImage(ImageSize.Small);
            for (int i = 0; i < row.Cells.Count; i++)
            {
                row.Cells[i].PropertyChanged += OnPropertyChanged;
            }
            panel.Rows.Add(row);
        }
示例#7
0
        public ThreatEventScenario([NotNull] IThreatEvent threatEvent, [NotNull] IThreatActor actor, string name = null) : this()
        {
            _id            = Guid.NewGuid();
            _model         = threatEvent.Model;
            _modelId       = threatEvent.Model.Id;
            _threatEvent   = threatEvent;
            _threatEventId = threatEvent.Id;
            _actorId       = actor.Id;
            _actor         = actor;
            Name           = string.IsNullOrWhiteSpace(name) ? actor.Name : name;
            Description    = actor.Description;

            _model.AutoApplySchemas(this);
        }
示例#8
0
        public void Add([NotNull] IThreatActor actor)
        {
            if (_actors == null)
            {
                _actors = new List <IThreatActor>();
            }

            _actors.Add(actor);

            if (this == ThreatModelManager.Model)
            {
                Dirty.IsDirty = true;
                ChildCreated?.Invoke(actor);
            }
        }
示例#9
0
        public IThreatActor AddThreatActor(DefaultActor actor)
        {
            IThreatActor result = null;

            if (actor != DefaultActor.Unknown)
            {
                var threatActor = GetThreatActor(actor);
                if (threatActor == null)
                {
                    result = new ThreatActor(this, actor);
                    Add(result);
                    RegisterEvents(result);
                }
            }

            return(result);
        }
示例#10
0
        private GridRow GetRow([NotNull] IThreatActor actor)
        {
            GridRow result = null;

            var rows = _grid.PrimaryGrid.Rows.OfType <GridRow>().ToArray();

            foreach (var row in rows)
            {
                if (row.Tag == actor)
                {
                    result = row;
                    break;
                }
            }

            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);
        }
示例#12
0
        private bool IsSelected([NotNull] IThreatActor 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);
        }
示例#13
0
 private void RemoveRelated([NotNull] IThreatActor actor)
 {
     RemoveRelatedForEntities(actor);
     RemoveRelatedForDataFlows(actor);
 }
示例#14
0
 private bool IsUsed([NotNull] IThreatActor actor)
 {
     return((_entities?.Any(x => x.ThreatEvents?.Any(y => y.Scenarios?.Any(z => z.Actor == actor) ?? false) ?? false) ?? false) ||
            (_dataFlows?.Any(x => x.ThreatEvents?.Any(y => y.Scenarios?.Any(z => z.Actor == actor) ?? false) ?? false) ?? false));
 }