public void Initialize([NotNull] IThreatModel model) { var schemaManager = new ModelConfigPropertySchemaManager(model); var schema = schemaManager.GetSchema(); var horizontalPT = schema.GetPropertyType("Diagram Layout Horizontal Spacing"); var horizontal = model.GetProperty(horizontalPT); if (horizontal == null) { model.AddProperty(horizontalPT, "200"); } else { if (string.IsNullOrWhiteSpace(horizontal.StringValue)) { horizontal.StringValue = "200"; } } var verticalPT = schema.GetPropertyType("Diagram Layout Vertical Spacing"); var vertical = model.GetProperty(verticalPT); if (vertical == null) { model.AddProperty(verticalPT, "100"); } else { if (string.IsNullOrWhiteSpace(vertical.StringValue)) { vertical.StringValue = "100"; } } }
public void Initialize([NotNull] IThreatModel model) { var schemaManager = new DefinitionsPropertySchemaManager(model); var propertyType = schemaManager.DefinitionsPropertyType; if (propertyType != null) { var property = model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null); if (property is IPropertyJsonSerializableObject jsonProperty) { var definitions = new DefinitionContainer(); definitions.SetDefinition("Threat Model", "Threat Modeling is a process to understand potential threat events to a system, determine risks from those threats, and establish appropriate mitigations."); definitions.SetDefinition("Threat Events", "Potential attack scenarios to the system. Who performs those attack scenarios is called Threat Actor."); definitions.SetDefinition("Risks", "Potential loss caused by the occurring of a Threat Event. It is typically expressed in monetary terms."); definitions.SetDefinition("Mitigations", "Actions that may decrease the Risk associated to a Threat Event."); jsonProperty.Value = definitions; } } }
public IEnumerable <string> GetPlaceholdersWithIgnoredFields() { IEnumerable <string> result = null; var schemaManager = new WordPropertySchemaManager(_model); var schema = schemaManager.GetSchema(); var propertyType = schema?.GetPropertyType("IgnoredListFields"); if (propertyType != null) { var property = _model.GetProperty(propertyType) as IPropertyArray; result = property?.Value?.Select(x => x.Split('#').FirstOrDefault()) .Distinct().Where(x => !string.IsNullOrWhiteSpace(x)); } return(result); }
public IEnumerable <Question> GetQuestions() { IEnumerable <Question> result = null; var propertyType = GetQuestionsPropertyType(); if (propertyType != null) { var property = _model.GetProperty(propertyType); if (property is IPropertyJsonSerializableObject jsonSerializableObject && jsonSerializableObject.Value is Questions questions) { result = questions.Items; } } return(result); }
private IEnumerable<string> GetSelectedProperties() { IEnumerable<string> result = null; var schema = (new ReportingConfigPropertySchemaManager(_model)).GetSchema(); var propertyType = schema?.GetPropertyType("ExcelSelectedFields"); if (propertyType != null) { var property = _model.GetProperty(propertyType); if (property is IPropertyArray propertyArray) result = propertyArray.Value; } return result; }
public IEnumerable <Parameter> GetFactProviderParameters() { IEnumerable <Parameter> result = null; var propertyType = GetSchema()?.GetPropertyType("FactProviderParams"); if (propertyType != null) { var property = _model.GetProperty(propertyType); if (property is IPropertyJsonSerializableObject jsonObject) { var parameters = jsonObject.Value as Parameters; result = parameters?.Items.AsEnumerable(); } } return(result); }
public IDevOpsConnector GetDevOpsConnector(out string url, out string project) { IDevOpsConnector result = null; url = null; project = null; var propertyType = GetPropertyTypeDevOpsConnector(); if (propertyType != null) { var property = _model.GetProperty(propertyType); if (property is IPropertyJsonSerializableObject jsonSerializableObject && jsonSerializableObject.Value is DevOpsConnection connection) { result = ExtensionUtils.GetExtension <IDevOpsConnectorFactory>(connection.ExtensionId)?.Create(); if (result != null) { url = connection.Url; project = connection.Project; result.MasterParent = connection.MasterParent; result.Tag = connection.Tag; result.WorkItemType = connection.WorkItemType; var workItemStateMappings = connection.WorkItemStateMappings; if (workItemStateMappings?.Any() ?? false) { foreach (var mapping in workItemStateMappings) { result.SetWorkItemStateMapping(mapping.Field, mapping.Status); } } var workItemFieldMappings = connection.WorkItemFieldMappings; if (workItemFieldMappings?.Any() ?? false) { foreach (var mapping in workItemFieldMappings) { result.SetWorkItemFieldMapping(mapping.Field, mapping.GetMappedField(_model)); } } } } } return(result); }
private static IPropertyJsonSerializableObject GetExtensionConfigurationProperty([NotNull] IThreatModel model, [Required] string extensionId) { var propertySchema = model.GetSchema("ExtensionsConfiguration", "https://github.com/simonec73/ThreatsManager") ?? model.AddSchema("ExtensionsConfiguration", "https://github.com/simonec73/ThreatsManager"); propertySchema.AppliesTo = Scope.ThreatModel; propertySchema.AutoApply = false; propertySchema.NotExportable = true; propertySchema.Priority = 100; propertySchema.RequiredExecutionMode = ExecutionMode.Business; propertySchema.System = true; propertySchema.Visible = false; var propertyType = propertySchema.GetPropertyType(extensionId) ?? propertySchema.AddPropertyType(extensionId, PropertyValueType.JsonSerializableObject); propertyType.Visible = false; propertyType.DoNotPrint = true; return((model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null)) as IPropertyJsonSerializableObject); }
public void SetThreatModel(IThreatModel model) { try { if (model != null) { var schema = new DefinitionsPropertySchemaManager(model); var propertyType = schema.DefinitionsPropertyType; if (propertyType != null) { var property = model.GetProperty(propertyType) ?? model.AddProperty(propertyType, null); if (property is IPropertyJsonSerializableObject jsonProperty) { if (jsonProperty.Value is DefinitionContainer container) { _container = container; var definitions = container.Definitions?.ToArray(); if (definitions?.Any() ?? false) { foreach (var definition in definitions) { _data.Rows.Add(definition.Key, definition.Value); } } } else { _container = new DefinitionContainer(); jsonProperty.Value = _container; } } } } } finally { _loading = false; } }
public void SetThreatModel([NotNull] IThreatModel threatModel) { _model = threatModel; _catalog.Model = threatModel; var propertySchemaManager = new CapecPropertySchemaManager(threatModel); var schema = propertySchemaManager.GetSchema(); var propertyType = propertySchemaManager.GetHiddenPropertiesPropertyType(); if (propertyType != null) { var property = _model.GetProperty(propertyType); if (property is IPropertyTokens propertyTokens) { var hiddenProperties = propertyTokens.Value?.ToArray(); if (hiddenProperties?.Any() ?? false) { _catalog.SetHiddenProperties(hiddenProperties); } } } _catalog.AutoLoad(); }