/// <summary>
        /// Transforms the given model to its endpoints acceptable structure and sends it to the endpoint
        /// </summary>
        public void SetServerThreatDetectionPolicy(ServerThreatDetectionPolicyModel model, string storageEndpointSuffix)
        {
            if (model.ThreatDetectionState == ThreatDetectionStateType.Enabled &&
                !IsRightServerVersionForThreatDetection(model.ResourceGroupName, model.ServerName))
            {
                throw new Exception(Properties.Resources.ServerNotApplicableForThreatDetection);
            }

            var serverSecurityAlertPolicyParameters = PolicizeServerSecurityAlertModel(model, storageEndpointSuffix);

            ThreatDetectionCommunicator.SetServerSecurityAlertPolicy(model.ResourceGroupName, model.ServerName, serverSecurityAlertPolicyParameters);
        }
        /// <summary>
        /// Provides a database threat detection policy model for the given database
        /// </summary>
        public ServerThreatDetectionPolicyModel GetServerThreatDetectionPolicy(string resourceGroup, string serverName, string requestId)
        {
            if (!IsRightServerVersionForThreatDetection(resourceGroup, serverName, requestId))
            {
                throw new Exception(Properties.Resources.ServerNotApplicableForThreatDetection);
            }

            var threatDetectionPolicy = ThreatDetectionCommunicator.GetServerSecurityAlertPolicy(resourceGroup, serverName, requestId);

            var serverThreatDetectionPolicyModel = ModelizeThreatDetectionPolicy(threatDetectionPolicy.Properties, new ServerThreatDetectionPolicyModel()) as ServerThreatDetectionPolicyModel;

            serverThreatDetectionPolicyModel.ResourceGroupName = resourceGroup;
            serverThreatDetectionPolicyModel.ServerName        = serverName;
            return(serverThreatDetectionPolicyModel);
        }
        /// <summary>
        /// Provides a database threat detection policy model for the given database
        /// </summary>
        public DatabaseThreatDetectionPolicyModel GetDatabaseThreatDetectionPolicy(string resourceGroup, string serverName, string databaseName)
        {
            if (!IsRightServerVersionForThreatDetection(resourceGroup, serverName))
            {
                throw new Exception(Properties.Resources.ServerNotApplicableForThreatDetection);
            }

            var threatDetectionPolicy = ThreatDetectionCommunicator.GetDatabaseSecurityAlertPolicy(resourceGroup, serverName, databaseName);

            var databaseThreatDetectionPolicyModel = ModelizeThreatDetectionPolicy(threatDetectionPolicy.Properties, new DatabaseThreatDetectionPolicyModel()) as DatabaseThreatDetectionPolicyModel;

            databaseThreatDetectionPolicyModel.ResourceGroupName = resourceGroup;
            databaseThreatDetectionPolicyModel.ServerName        = serverName;
            databaseThreatDetectionPolicyModel.DatabaseName      = databaseName;
            return(databaseThreatDetectionPolicyModel);
        }
        /// <summary>
        /// Provides a managed instance threat detection policy model for the given managed instance
        /// </summary>
        public ManagedInstanceThreatDetectionPolicyModel GetManagedInstanceThreatDetectionPolicy(string resourceGroup, string managedInstanceName)
        {
            var threatDetectionPolicy = ThreatDetectionCommunicator.GetManageInstanceSecurityAlertPolicy(resourceGroup, managedInstanceName);

            var managedInstanceThreatDetectionPolicyModel = new ManagedInstanceThreatDetectionPolicyModel()
            {
                ThreatDetectionState         = ModelizeThreatDetectionState(threatDetectionPolicy.State.ToString()),
                NotificationRecipientsEmails = string.Join(";", threatDetectionPolicy.EmailAddresses.ToArray()),
                EmailAdmins     = threatDetectionPolicy.EmailAccountAdmins == null ? false : threatDetectionPolicy.EmailAccountAdmins.Value,
                RetentionInDays = (uint)threatDetectionPolicy.RetentionDays,
            };

            managedInstanceThreatDetectionPolicyModel.ExcludedDetectionTypes = threatDetectionPolicy.DisabledAlerts.Where(alert => !string.IsNullOrEmpty(alert)).ToArray() ?? new string[] { };
            managedInstanceThreatDetectionPolicyModel.ResourceGroupName      = resourceGroup;
            managedInstanceThreatDetectionPolicyModel.ServerName             = managedInstanceName;

            ModelizeStorageAccount(managedInstanceThreatDetectionPolicyModel, threatDetectionPolicy.StorageEndpoint);

            return(managedInstanceThreatDetectionPolicyModel);
        }
Пример #5
0
        /// <summary>
        /// Transforms the given model to its endpoints acceptable structure and sends it to the endpoint
        /// </summary>
        public void SetServerThreatDetectionPolicy(ServerThreatDetectionPolicyModel model, string clientId)
        {
            if (model.ThreatDetectionState == ThreatDetectionStateType.Enabled)
            {
                if (!IsRightServerVersionForThreatDetection(model.ResourceGroupName, model.ServerName, clientId))
                {
                    throw new Exception(Properties.Resources.ServerNotApplicableForThreatDetection);
                }

                // Check that auditing is turned on:
                ServerAuditingPolicyModel serverAuditingPolicyModel;
                AuditingAdapter.GetServerAuditingPolicy(model.ResourceGroupName, model.ServerName, clientId, out serverAuditingPolicyModel);
                if (serverAuditingPolicyModel.AuditState != AuditStateType.Enabled)
                {
                    throw new Exception(Properties.Resources.AuditingIsTurnedOff);
                }
            }

            var serverSecurityAlertPolicyParameters = PolicizeServerSecurityAlertModel(model);

            ThreatDetectionCommunicator.SetServerSecurityAlertPolicy(model.ResourceGroupName, model.ServerName, clientId, serverSecurityAlertPolicyParameters);
        }
        /// <summary>
        /// Transforms the given model to its endpoints acceptable structure and sends it to the endpoint
        /// </summary>
        public void SetManagedInstanceThreatDetectionPolicy(ManagedInstanceThreatDetectionPolicyModel model, string storageEndpointSuffix)
        {
            var managedInstanceSecurityAlertPolicyParameters = PolicizeManagedInstanceSecurityAlertModel(model, storageEndpointSuffix);

            ThreatDetectionCommunicator.SetManagedInstanceSecurityAlertPolicy(model.ResourceGroupName, model.ServerName, managedInstanceSecurityAlertPolicyParameters);
        }