public bool Execute(IThreatTypeMitigation mitigation)
        {
            var result = false;

            var model = mitigation.Model;

            if (model != null)
            {
                var rule   = mitigation.GetRule(model);
                var parent = mitigation.ThreatType;

                if (parent != null)
                {
                    var parentRule = parent.GetRule(model);

                    if (string.CompareOrdinal(rule?.ToString(), parentRule?.ToString()) != 0)
                    {
                        Ask?.Invoke(this, new Context()
                        {
                            Container = mitigation, Rule = parentRule
                        },
                                    "Inherit Auto Gen Rule from Threat Type", $"Are you sure you want to replace the existing rule for '{mitigation.Mitigation.Name}' with the one assigned to Threat Type '{parent.Name}'?",
                                    true, RequestOptions.YesNo);
                    }
                    else
                    {
                        ShowMessage?.Invoke("Nothing to do, because the Auto Gen Rules are equivalent.");
                    }
                    result = true;
                }
            }

            return(result);
        }
Пример #2
0
        private GridRow GetRow([NotNull] IThreatTypeMitigation mitigation)
        {
            GridRow result = null;

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

            foreach (var row in rows)
            {
                var panel = row.Rows.OfType <GridPanel>()
                            .FirstOrDefault(x => string.CompareOrdinal("Mitigations", x.Name) == 0);
                if (panel != null)
                {
                    result = panel.Rows.OfType <GridRow>().FirstOrDefault(x =>
                                                                          (x.Tag is IThreatTypeMitigation threatTypeMitigation) &&
                                                                          (threatTypeMitigation.MitigationId == mitigation.MitigationId) &&
                                                                          (threatTypeMitigation.ThreatTypeId == mitigation.ThreatTypeId));
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
        public bool Initialize([NotNull] IThreatTypeMitigation threatTypeMitigation)
        {
            bool result = false;

            _model = threatTypeMitigation.Model;
            _threatType.Text = threatTypeMitigation.ThreatType.Name;
            _mitigation.Text = threatTypeMitigation.Mitigation.Name;

            _strengthOverride.SelectedIndex = 0;
            var strengths = _model.Strengths?.ToArray();
            if (strengths?.Any() ?? false)
                _strengthOverride.Items.AddRange(strengths);

            _statusOverride.SelectedIndex = 0;
            _statusOverride.Items.AddRange(EnumExtensions.GetEnumLabels<MitigationStatus>().ToArray());

            _severityOverride.SelectedIndex = 0;
            var severities = _model.Severities?.Where(x => x.Visible).ToArray();
            if (severities?.Any() ?? false)
                _severityOverride.Items.AddRange(severities);

            _threatTypeRule = threatTypeMitigation.ThreatType.GetRule();
            if (_threatTypeRule != null)
            {
                result = true;
                _ruleEditor.Initialize(_model);
            }

            return result;
        }
Пример #4
0
        public static bool HasTop(this IThreatTypeMitigation mitigation, AutoGenRulesPropertySchemaManager schemaManager = null)
        {
            if (schemaManager == null)
            {
                schemaManager = new AutoGenRulesPropertySchemaManager(mitigation.Model);
            }

            return(schemaManager.IsTop(mitigation));
        }
        public bool Execute(IThreatTypeMitigation mitigation)
        {
            bool result = false;

            if (mitigation is IPropertiesContainer container)
            {
                result = Execute(container);
            }

            return(result);
        }
Пример #6
0
        public bool Execute(IThreatTypeMitigation mitigation)
        {
            var result = false;

            if (Clipboard.GetDataObject() is DataObject dataObject &&
                dataObject.GetDataPresent("AutoGenRule") &&
                dataObject.GetData("AutoGenRule") is string autoGenRule)
            {
                result = ApplyGenRule(mitigation, autoGenRule);
            }

            return(result);
        }
Пример #7
0
        private void AddGridRow([NotNull] IThreatTypeMitigation mitigation, [NotNull] GridPanel panel)
        {
            bool rule = HasSelectionRule(mitigation);

            GridRow row = new GridRow(
                mitigation.Mitigation.Name,
                rule ? "Edit Rule" : "Create Rule")
            {
                Tag = mitigation
            };

            panel.Rows.Add(row);

            ((INotifyPropertyChanged)mitigation).PropertyChanged            += OnMitigationPropertyChanged;
            ((INotifyPropertyChanged)mitigation.Mitigation).PropertyChanged += OnMitigationPropertyChanged;
            mitigation.PropertyValueChanged += OnMitigationPropertyValueChanged;
        }
Пример #8
0
        public bool Execute(IThreatTypeMitigation ttMitigation)
        {
            bool result = false;

            if (ttMitigation != null)
            {
                using (var dialog = new ItemEditorDialog())
                {
                    dialog.SetExecutionMode(_executionMode);
                    dialog.Item = ttMitigation.Mitigation;
                    dialog.ShowDialog(Form.ActiveForm);
                }
                result = true;
            }

            return(result);
        }
        public IThreatTypeMitigation AddMitigation([NotNull] IMitigation mitigation, IStrength strength)
        {
            IThreatTypeMitigation result = null;

            if (GetMitigation(mitigation.Id) == null)
            {
                result = new ThreatTypeMitigation(Model, this, mitigation, strength);
                if (_mitigations == null)
                {
                    _mitigations = new List <IThreatTypeMitigation>();
                }
                _mitigations.Add(result);
                SetDirty();
                _threatTypeMitigationAdded?.Invoke(this, result);
            }

            return(result);
        }
        public bool Execute(IThreatTypeMitigation mitigation)
        {
            bool result = false;

            using (var dialog = new MitigationRuleEditDialog())
            {
                if (dialog.Initialize(mitigation))
                {
                    result = mitigation.SetRule(dialog);
                }
                else
                {
                    ShowWarning?.Invoke("Threat Event Generation Rule for the related Threat Type has not been set.");
                }
            }

            return(result);
        }
Пример #11
0
        private void AddGridRow([NotNull] IThreatTypeMitigation mitigation, [NotNull] GridPanel panel)
        {
            GridRow row = new GridRow(
                mitigation.Mitigation.Name,
                mitigation.Mitigation.ControlType.ToString(),
                mitigation.Strength.ToString())
            {
                Tag = mitigation
            };

            row.Cells[0].CellStyles.Default.Image = mitigation.Mitigation.GetImage(ImageSize.Small);
            for (int i = 0; i < row.Cells.Count; i++)
            {
                row.Cells[i].PropertyChanged += OnMitigationCellChanged;
            }
            panel.Rows.Add(row);

            ((INotifyPropertyChanged)mitigation).PropertyChanged            += OnMitigationPropertyChanged;
            ((INotifyPropertyChanged)mitigation.Mitigation).PropertyChanged += OnMitigationPropertyChanged;
        }
Пример #12
0
        private void AddGridRow([NotNull] IThreatTypeMitigation ttm, [NotNull] GridPanel panel)
        {
            GridRow row = new GridRow(
                ttm.ThreatType.Name,
                ttm.ThreatType.Severity,
                ttm.Strength)
            {
                Tag = ttm
            };

            UpdateMitigationLevel(ttm.ThreatType, row);
            for (int i = 0; i < row.Cells.Count; i++)
            {
                row.Cells[i].PropertyChanged += OnThreatTypeCellChanged;
            }
            panel.Rows.Add(row);

            ((INotifyPropertyChanged)ttm).PropertyChanged            += OnThreatTypeMitigationPropertyChanged;
            ((INotifyPropertyChanged)ttm.ThreatType).PropertyChanged += OnThreatTypePropertyChanged;
        }
Пример #13
0
        private GridRow GetRow([NotNull] IThreatTypeMitigation threatTypeMitigation)
        {
            GridRow result = null;

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

            foreach (var row in rows)
            {
                var panel = row.Rows.OfType <GridPanel>()
                            .FirstOrDefault(x => string.CompareOrdinal("ThreatTypes", x.Name) == 0);
                var current = panel?.Rows.OfType <GridRow>().FirstOrDefault(x =>
                                                                            (x.Tag is IThreatTypeMitigation ttm) && (ttm == threatTypeMitigation));
                if (current != null)
                {
                    result = current;
                    break;
                }
            }

            return(result);
        }
Пример #14
0
 private void _ok_Click(object sender, EventArgs e)
 {
     if (_associateExisting.Checked)
     {
         if (_existingMitigation.SelectedItem is IMitigation mitigation &&
             _strengthExisting.SelectedItem != null)
         {
             _mitigation = _threatType.AddMitigation(mitigation, _strengthExisting.SelectedItem as IStrength);
         }
     }
     else if (_createNew.Checked)
     {
         if (Enum.TryParse <SecurityControlType>((string)_controlType.SelectedItem, out var controlType) &&
             _strength.SelectedItem != null)
         {
             var newMitigation = _threatType.Model.AddMitigation(_name.Text);
             newMitigation.Description = _description.Text;
             newMitigation.ControlType = controlType;
             _mitigation = _threatType.AddMitigation(newMitigation, _strength.SelectedItem as IStrength);
         }
     }
 }
        public bool Execute(IThreatTypeMitigation mitigation)
        {
            bool result = false;

            if (MessageBox.Show(Form.ActiveForm,
                                $"You are about to disassociate Mitigation '{mitigation.Mitigation.Name}'. Are you sure?",
                                "Remove Mitigation association", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                if (mitigation.ThreatType.RemoveMitigation(mitigation.MitigationId))
                {
                    result = true;
                    ShowMessage?.Invoke("Mitigation disassociated successfully.");
                }
                else
                {
                    ShowWarning?.Invoke("The Mitigation association cannot be removed.");
                }
            }

            return(result);
        }
Пример #16
0
        private void ThreatTypeMitigationRemoved([NotNull] IThreatTypeMitigationsContainer container, [NotNull] IThreatTypeMitigation threatTypeMitigation)
        {
            var row = GetRow(threatTypeMitigation);

            if (row != null)
            {
                RemoveEventSubscriptions(row);
                row.GridPanel.Rows.Remove(row);
            }
        }
Пример #17
0
 private void Update(IThreatTypeMitigationsContainer arg1, IThreatTypeMitigation arg2)
 {
     UpdateInfo?.Invoke(this.GetExtensionId(), CurrentStatus);
 }
Пример #18
0
 public static MitigationSelectionRule GetRule([NotNull] IThreatTypeMitigation threatTypeMitigation)
 {
     return(threatTypeMitigation.GetRule(threatTypeMitigation.Model) as MitigationSelectionRule);
 }
Пример #19
0
 public bool Execute(IThreatTypeMitigation mitigation)
 {
     return(mitigation != null && Execute(mitigation as IPropertiesContainer));
 }
Пример #20
0
        private void OnThreatTypeMitigationRemoved(IThreatTypeMitigationsContainer container, IThreatTypeMitigation mitigation)
        {
            if (container is IThreatType threatType)
            {
                var row = GetRow(threatType);

                var panel       = row?.Rows.OfType <GridPanel>().FirstOrDefault(x => string.CompareOrdinal(x.Name, "Mitigations") == 0);
                var scenarioRow = panel?.Rows.OfType <GridRow>()
                                  .FirstOrDefault(x =>
                                                  (x.Tag is IThreatTypeMitigation typeMitigation) && typeMitigation == mitigation);
                if (scenarioRow != null)
                {
                    panel.Rows.Remove(scenarioRow);

                    if (panel.Rows.Count == 0)
                    {
                        row.Rows.Remove(panel);
                    }

                    UpdateMitigationLevel(threatType, row);
                }
            }
        }
Пример #21
0
        private void OnThreatTypeMitigationAdded(IThreatTypeMitigationsContainer container, IThreatTypeMitigation mitigation)
        {
            if (container is IThreatType threatType)
            {
                var filterSpecial = EnumExtensions.GetEnumValue <ThreatTypeListFilter>((string)_specialFilter.SelectedItem);
                if (IsSelected(threatType, _filter.Text, filterSpecial))
                {
                    var row = GetRow(threatType);
                    if (row == null)
                    {
                        row = AddGridRow(threatType, _grid.PrimaryGrid);
                    }

                    var scenarioPanel = row.Rows.OfType <GridPanel>()
                                        .FirstOrDefault(x => string.CompareOrdinal(x.Name, "Mitigations") == 0);
                    if (scenarioPanel != null)
                    {
                        AddGridRow(mitigation, scenarioPanel);
                    }
                    else
                    {
                        scenarioPanel = CreateMitigationsPanel(threatType);
                        if (scenarioPanel != null)
                        {
                            row.Rows.Add(scenarioPanel);
                        }
                    }

                    UpdateMitigationLevel(threatType, row);
                }
            }
        }
Пример #22
0
        private void ThreatTypeMitigationAdded([NotNull] IThreatTypeMitigationsContainer container, [NotNull] IThreatTypeMitigation threatTypeMitigation)
        {
            var row = GetRow(threatTypeMitigation);

            if (row == null)
            {
                var mitigationRow = GetRow(threatTypeMitigation.Mitigation);
                if (mitigationRow != null)
                {
                    var panel = mitigationRow.Rows.OfType <GridPanel>()
                                .FirstOrDefault(x => string.CompareOrdinal("ThreatTypes", x.Name) == 0);
                    AddGridRow(threatTypeMitigation, panel);
                }
            }
        }
Пример #23
0
 public bool Execute(IThreatTypeMitigation identity)
 {
     throw new NotImplementedException();
 }