Exemplo n.º 1
0
 /// <summary>
 /// Extracts the storage account requested key
 /// </summary>
 private string ExtractStorageAccountKey(string storageName, BaseTableAuditingPolicyModel model, string storageAccountResourceGroup, StorageKeyKind keyType)
 {
     if (!IgnoreStorage && (model.StorageKeyType == keyType))
     {
         return(AzureCommunicator.GetStorageKeys(storageAccountResourceGroup, storageName)[keyType]);
     }
     return(null);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the content of the model object with all the retention information
        /// </summary>
        private static void ModelizeRetentionInfo(BaseTableAuditingPolicyModel model, string retentionDays, string auditLogsTableName, string fullAuditLogsTableName)
        {
            model.TableIdentifier        = auditLogsTableName;
            model.FullAuditLogsTableName = fullAuditLogsTableName;
            uint retentionDaysForModel;

            if (!(uint.TryParse(retentionDays, out retentionDaysForModel)))
            {
                retentionDaysForModel = 0;
            }
            model.RetentionInDays = retentionDaysForModel;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Updates the content of the model object with all the storage related information
 /// </summary>
 private static void ModelizeStorageInfo(BaseTableAuditingPolicyModel model, string accountName, string primary, string secondary)
 {
     model.StorageAccountName = accountName;
     if (!string.IsNullOrEmpty(secondary))
     {
         model.StorageKeyType = StorageKeyKind.Secondary;
     }
     else
     {
         model.StorageKeyType = StorageKeyKind.Primary;
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the given model with all the event types information
        /// </summary>
        private static void ModelizeEventTypesInfo(BaseTableAuditingPolicyModel model, string eventTypesToAudit)
        {
            HashSet <AuditEventType> events = new HashSet <AuditEventType>();

            if (eventTypesToAudit != null)
            {
                if (eventTypesToAudit.IndexOf(SecurityConstants.PlainSQL_Success) != -1)
                {
                    events.Add(AuditEventType.PlainSQL_Success);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.PlainSQL_Failure) != -1)
                {
                    events.Add(AuditEventType.PlainSQL_Failure);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.ParameterizedSQL_Success) != -1)
                {
                    events.Add(AuditEventType.ParameterizedSQL_Success);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.ParameterizedSQL_Failure) != -1)
                {
                    events.Add(AuditEventType.ParameterizedSQL_Failure);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.StoredProcedure_Success) != -1)
                {
                    events.Add(AuditEventType.StoredProcedure_Success);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.StoredProcedure_Failure) != -1)
                {
                    events.Add(AuditEventType.StoredProcedure_Failure);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.Login_Success) != -1)
                {
                    events.Add(AuditEventType.Login_Success);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.Login_Failure) != -1)
                {
                    events.Add(AuditEventType.Login_Failure);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.TransactionManagement_Success) != -1)
                {
                    events.Add(AuditEventType.TransactionManagement_Success);
                }
                if (eventTypesToAudit.IndexOf(SecurityConstants.TransactionManagement_Failure) != -1)
                {
                    events.Add(AuditEventType.TransactionManagement_Failure);
                }
            }

            model.EventType = events.ToArray();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Extracts the event types from the given model
        /// </summary>
        private static string ExtractEventTypes(BaseTableAuditingPolicyModel model)
        {
            if (model.EventType == null)
            {
                return(null);
            }

            var events = new StringBuilder();

            model.EventType.ToList().ForEach(e => events.Append(e.ToString()).Append(","));
            if (events.Length != 0)
            {
                events.Remove(events.Length - 1, 1); // remove trailing comma
            }
            return(events.ToString());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Extracts the event types from the given model
        /// </summary>
        private static string ExtractEventTypes(BaseTableAuditingPolicyModel model)
        {
            if (model.EventType == null)
            {
                return(null);
            }

            if (model.EventType.Any(t => t == AuditEventType.None))
            {
                if (model.EventType.Count() == 1)
                {
                    return(string.Empty);
                }
                if (model.EventType.Any(t => t != AuditEventType.None))
                {
                    throw new Exception(Properties.Resources.InvalidEventTypeSet);
                }
            }
            return(string.Join(";", model.EventType.Select(t => t.ToString())));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Extracts the storage account name from the given model
        /// </summary>
        private string ExtractStorageAccountName(BaseTableAuditingPolicyModel model)
        {
            string storageAccountName;

            if (model.StorageAccountName == FetchedStorageAccountName) // the user provided the same storage account that was given before
            {
                storageAccountName = FetchedStorageAccountName;
            }
            else if (model.StorageAccountName == null) // the user did not provided storage account for a policy for which such account is already defined
            {
                storageAccountName = FetchedStorageAccountName;
            }
            else // the user updates the name of the storage account
            {
                storageAccountName = model.StorageAccountName;
            }
            if (string.IsNullOrEmpty(storageAccountName) && (!IgnoreStorage)) // can happen if the user didn't provide account name for a policy that lacked it
            {
                throw new Exception(string.Format(Properties.Resources.NoStorageAccountWhenConfiguringAuditingPolicy));
            }
            return(storageAccountName);
        }