예제 #1
0
        //FOR NOW - THERE's NO OPTION WITH changes AND entity (as a shortcut) because this is a very uncommon case - if you're sending the entity, it's either new or deleted, but it wouldn't have changes
        //if you really want that last combo - use the full method call


        public async Task Enqueue <T>(string entityType, object entityId, AuditActivityType type, object userId, string userName, string auditDescription, List <RelatedEntity> related, List <PropertyComparison> changes, T entity)
        {
            if (ServiceManager.IsEnabled)
            {
                //1 item is built and queued, the queue will handle the details
                var a = new AuditActivity(entityType, entityId)
                {
                    AuditType   = type.ToString(),
                    ById        = userId.ToString(),
                    ByName      = userName,
                    Description = auditDescription
                };

                if (changes != null && changes.Count > 0)
                {
                    a.Changes = System.Text.Json.JsonSerializer.Serialize(changes);
                }
                if (entity != null)
                {
                    a.Entity = System.Text.Json.JsonSerializer.Serialize(entity);
                }
                if (related != null && related.Count > 0)
                {
                    a.Related = System.Text.Json.JsonSerializer.Serialize(related);
                }

                await AuditQueue.SendMessageAsync(System.Text.Json.JsonSerializer.Serialize(a).ToBase64());
            }
        }
예제 #2
0
        public async Task AddActivity(AuditActivity auditActivity)
        {
            switch (auditActivity.GetActivityType())
            {
            case AuditActivityType.Login:
            case AuditActivityType.Heartbeat:
                await ProcessLogin(auditActivity);

                break;

            case AuditActivityType.Permission:
                await ProcessPermissionIssue(auditActivity);

                break;

            case AuditActivityType.Create:
            case AuditActivityType.Update:
            case AuditActivityType.Delete:
            case AuditActivityType.Info:
            case AuditActivityType.Access:
            default:
                await ProcessActivity(auditActivity);

                break;
            }
        }
예제 #3
0
 public async Task EnqueueHeartbeat(object userId, string userName)
 {
     if (ServiceManager.IsLoginsEnabled)
     {
         //1 item is built and queued, the queue will handle the details
         var a = new AuditActivity(userId.ToString(), userName)
         {
             AuditType = AuditActivityType.Heartbeat.ToString(),
             ById      = userId.ToString(),
             ByName    = userName
         };
         await AuditQueue.SendMessageAsync(System.Text.Json.JsonSerializer.Serialize(a).ToBase64());
     }
 }
예제 #4
0
 public async Task EnqueuePermissionException(object userId, string userName, string resource)
 {
     if (ServiceManager.IsPermissionsEnabled)
     {
         //1 item is built and queued, the queue will handle the details
         var a = new AuditActivity(userId.ToString(), userName)
         {
             AuditType   = AuditActivityType.Permission.ToString(),
             ById        = userId.ToString(),
             ByName      = userName,
             Description = resource
         };
         await AuditQueue.SendMessageAsync(System.Text.Json.JsonSerializer.Serialize(a).ToBase64());
     }
 }
예제 #5
0
 public async Task EnqueueLogin(object userId, string userName, string provider = "forms", bool isSuccess = true)
 {
     if (ServiceManager.IsLoginsEnabled)
     {
         //1 item is built and queued, the queue will handle the details
         var a = new AuditActivity(userId.ToString(), userName)
         {
             AuditType   = AuditActivityType.Login.ToString(),
             ById        = userId.ToString(),
             ByName      = userName,
             Description = provider,
             Entity      = isSuccess.ToString()
         };
         await AuditQueue.SendMessageAsync(System.Text.Json.JsonSerializer.Serialize(a).ToBase64());
     }
 }
예제 #6
0
        async Task ProcessPermissionIssue(AuditActivity auditActivity)
        {
            var activityUser = new AuditUserActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName)
            {
                AuditType = auditActivity.AuditType,
                ExtraInfo = auditActivity.Description
            };

            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(activityUser));
            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUserLogins()), TableOperation.InsertOrReplace(activityUser));

            var activityPermission = new AuditPermissionActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName, auditActivity.EntityType, auditActivity.EntityId)
            {
                ExtraInfo = auditActivity.Description
            };

            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditPermissions()), TableOperation.InsertOrReplace(activityPermission));
        }
예제 #7
0
        async Task ProcessActivity(AuditActivity auditActivity)
        {
            var activityUser = new AuditUserActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName)
            {
                AuditType          = auditActivity.AuditType,
                EntityPartitionKey = auditActivity.PartitionKey,
                EntityRowKey       = auditActivity.RowKey,
                EntityType         = auditActivity.EntityType,
                EntityId           = auditActivity.EntityId
            };
            var auditUserHistoryActivity = new AuditUserHistoryActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName);
            var activityHistory          = new AuditActivityHistory(TimeZoneHelper.GetDate(auditActivity.On), auditActivity.ById, auditActivity.ByName, auditActivity.PartitionKey, auditActivity.RowKey)
            {
                EntityType = auditActivity.EntityType,
                EntityId   = auditActivity.EntityId,
                On         = auditActivity.On,
                AuditType  = auditActivity.AuditType
            };

            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditActivities()), TableOperation.Insert(auditActivity));
            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.Insert(activityUser));
            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(auditUserHistoryActivity));
            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditActivityHistories()), TableOperation.InsertOrReplace(activityHistory));

            if (auditActivity.GetActivityType() == AuditActivityType.Delete)
            {
                var deletion = new AuditDeletion(auditActivity.EntityType, auditActivity.EntityId)
                {
                    Entity = auditActivity.Entity,
                    ById   = auditActivity.ById,
                    ByName = auditActivity.ByName,
                    On     = auditActivity.On
                };
                await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditDeletions()), TableOperation.Insert(deletion));
            }
            ;
        }
예제 #8
0
        async Task ProcessLogin(AuditActivity auditActivity)
        {
            var activityUser = new AuditUserActivity(auditActivity.On, auditActivity.ById, auditActivity.ByName)
            {
                AuditType = auditActivity.AuditType,
                ExtraInfo = auditActivity.Description
            };

            if (auditActivity.Entity != null && bool.TryParse(auditActivity.Entity, out bool isSuccess))
            {
                activityUser.IsSuccessful = isSuccess;
            }

            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(activityUser));
            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUsers()), TableOperation.InsertOrReplace(activityUser));
            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditUserLogins()), TableOperation.InsertOrReplace(activityUser));

            var activityLogin = new AuditLoginActivity(auditActivity.On.DateTime, auditActivity.ById, auditActivity.ByName)
            {
                ExtraInfo = auditActivity.Description
            };

            await ExecuteAsync(ServiceManager.GetTableClient().GetTableReference(TableAssist.AuditLogins()), TableOperation.InsertOrReplace(activityLogin));
        }