private static void ConfigureForAzureStorage(ContainerBuilder builder, ConfigurationService configuration) { builder.RegisterInstance(new CloudBlobClientWrapper(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant)) .AsSelf() .As <ICloudBlobClient>() .SingleInstance(); builder.RegisterType <CloudBlobFileStorageService>() .AsSelf() .As <IFileStorageService>() .SingleInstance(); // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs builder.RegisterInstance(new JsonAggregateStatsService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant)) .AsSelf() .As <IAggregateStatsService>() .SingleInstance(); // when running on Windows Azure, pull the statistics from the warehouse via storage builder.RegisterInstance(new CloudReportService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant)) .AsSelf() .As <IReportService>() .SingleInstance(); // when running on Windows Azure, download counts come from the downloads.v1.json blob var downloadCountService = new CloudDownloadCountService(configuration.Current.AzureStorageConnectionString, configuration.Current.AzureStorageReadAccessGeoRedundant); builder.RegisterInstance(downloadCountService) .AsSelf() .As <IDownloadCountService>() .SingleInstance(); ObjectMaterializedInterception.AddInterceptor(new DownloadCountObjectMaterializedInterceptor(downloadCountService)); builder.RegisterType <JsonStatisticsService>() .AsSelf() .As <IStatisticsService>() .SingleInstance(); string instanceId; try { instanceId = RoleEnvironment.CurrentRoleInstance.Id; } catch { instanceId = Environment.MachineName; } var localIp = AuditActor.GetLocalIP().Result; builder.RegisterInstance(new CloudAuditingService(instanceId, localIp, configuration.Current.AzureStorageConnectionString, CloudAuditingService.AspNetActorThunk)) .AsSelf() .As <AuditingService>() .SingleInstance(); }
public AddAuditRequest(DateTime utcTimestamp, AuditActor actor, string actorIp, string personName, string action, string entityId, string entityDescription, string oldValue, string newValue) { UtcTimestamp = utcTimestamp; Actor = actor; ActorIp = actorIp; PersonName = personName; Action = action; EntityId = entityId; EntityDescription = entityDescription; OldValue = oldValue; NewValue = newValue; }
internal static async Task <Uri> SaveAuditRecord(CloudStorageAccount storage, AuditRecord auditRecord) { string localIP = await AuditActor.GetLocalIP(); CloudAuditingService audit = new CloudAuditingService( Environment.MachineName, localIP, storage.CreateCloudBlobClient().GetContainerReference("auditing"), onBehalfOfThunk: null); return(await audit.SaveAuditRecord(auditRecord)); }
public RequestAudit(AuditActor actor, string actorIp, string personName, string action, string path, string method, string query, string body) { Id = ObjectId.GenerateNewId().ToString(); Timestamp = DateTime.UtcNow; Actor = actor; ActorIp = actorIp; PersonName = personName; Action = action; Path = path; Method = method; Query = query; Body = body; }
public AuditRecordResponse(string id, DateTime timestamp, AuditActor actor, string actorIp, string personName, string action, string entityId, string entityDescription, string oldValue, string newValue) { Id = id; Timestamp = timestamp; Actor = actor; ActorIp = actorIp; PersonName = personName; Action = action; EntityId = entityId; EntityDescription = entityDescription; OldValue = oldValue; NewValue = newValue; }
private static IAuditingService GetAuditingServiceForAzureStorage(IGalleryConfigurationService configuration) { string instanceId; try { instanceId = RoleEnvironment.CurrentRoleInstance.Id; } catch { instanceId = Environment.MachineName; } var localIp = AuditActor.GetLocalIpAddressAsync().Result; return(new CloudAuditingService(instanceId, localIp, configuration.Current.AzureStorageConnectionString, AuditActor.GetAspNetOnBehalfOfAsync)); }
private void ConfigureForAzureStorage(ConfigurationService configuration) { Bind <ICloudBlobClient>() .ToMethod(_ => new CloudBlobClientWrapper(configuration.Current.AzureStorageConnectionString)) .InSingletonScope(); Bind <IFileStorageService>() .To <CloudBlobFileStorageService>() .InSingletonScope(); // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs Bind <IAggregateStatsService>() .ToMethod(_ => new JsonAggregateStatsService(configuration.Current.AzureStorageConnectionString)) .InSingletonScope(); // when running on Windows Azure, pull the statistics from the warehouse via storage Bind <IReportService>() .ToMethod(_ => new CloudReportService(configuration.Current.AzureStorageConnectionString)) .InSingletonScope(); Bind <IStatisticsService>() .To <JsonStatisticsService>() .InSingletonScope(); string instanceId; try { instanceId = RoleEnvironment.CurrentRoleInstance.Id; } catch (Exception) { instanceId = Environment.MachineName; } var localIP = AuditActor.GetLocalIP().Result; Bind <AuditingService>() .ToMethod(_ => new CloudAuditingService( instanceId, localIP, configuration.Current.AzureStorageConnectionString, CloudAuditingService.AspNetActorThunk)) .InSingletonScope(); }
private static IAuditingService GetAuditingServiceForAzureStorage(ContainerBuilder builder, IGalleryConfigurationService configuration) { string instanceId; try { instanceId = RoleEnvironment.CurrentRoleInstance.Id; } catch { instanceId = Environment.MachineName; } var localIp = AuditActor.GetLocalIpAddressAsync().Result; var service = new CloudAuditingService(instanceId, localIp, configuration.Current.AzureStorage_Auditing_ConnectionString, AuditActor.GetAspNetOnBehalfOfAsync); builder.RegisterInstance(service) .As <ICloudStorageStatusDependency>() .SingleInstance(); return(service); }
public AuditEntry(AuditRecord record, AuditActor actor) { Record = record; Actor = actor; }
public AuditEntry(AuditRecord record, AuditActor actor) { Record = record; Actor = actor; }
protected virtual Task <AuditActor> GetActor() { return(AuditActor.GetCurrentMachineActor()); }
/// <summary> /// Convert internal service core audit data to persistence data /// </summary> public static Audit ToAudit(this AuditData me) { Audit retVal = new Audit(); retVal.ActionCode = MapOrCreateCode(me.ActionCode); retVal.EventIdCode = MapOrCreateCode(me.EventIdentifier); retVal.OutcomeCode = MapOrCreateCode(me.Outcome); retVal.EventTypeCodes = new List <AuditTerm>() { MapOrCreateCode(me.EventTypeCode) }; retVal.EventTimestamp = me.Timestamp; // Source var auditSourcePs = ApplicationServiceContext.Current.GetService <IDataPersistenceService <AuditSource> >(); var enterpriseMetadata = me.Metadata.FirstOrDefault(o => o.Key == AuditMetadataKey.EnterpriseSiteID)?.Value; if (String.IsNullOrEmpty(enterpriseMetadata)) { enterpriseMetadata = ApplicationServiceContext.Current.GetService <IConfigurationManager>().GetSection <SanteGuardConfiguration>().DefaultEnterpriseSiteID; } int tr = 0; var currentSources = auditSourcePs.Query(s => s.EnterpriseSiteId == enterpriseMetadata, 0, 1, out tr, AuthenticationContext.Current.Principal).FirstOrDefault(); if (currentSources == null) { currentSources = auditSourcePs.Insert(new AuditSource() { EnterpriseSiteId = enterpriseMetadata, AuditSourceId = Dns.GetHostName(), SourceType = new List <AuditTerm>() { MapOrCreateCode(AtnaApi.Model.AuditSourceType.ApplicationServerProcess) } }, TransactionMode.Commit, AuthenticationContext.Current.Principal); } retVal.AuditSource = currentSources; // Participants if (me.Actors != null) { var actorPs = ApplicationServiceContext.Current.GetService <IDataPersistenceService <AuditActor> >(); retVal.Participants = me.Actors.Select(a => { AuditActor act = actorPs.Query(o => o.UserName == a.UserName && o.NetworkAccessPoint == a.NetworkAccessPointId && o.UserIdentifier == a.UserIdentifier, AuthenticationContext.Current.Principal).FirstOrDefault(); if (act == null) { Guid?sid = null; if (!String.IsNullOrEmpty(a.UserName ?? a.UserIdentifier ?? a.AlternativeUserId)) { sid = ApplicationServiceContext.Current.GetService <ISecurityRepositoryService>().GetUser(a.UserName ?? a.UserIdentifier ?? a.AlternativeUserId)?.Key; } else if (!String.IsNullOrEmpty(a.NetworkAccessPointId)) { sid = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityDevice> >().Find(o => o.Name == a.NetworkAccessPointId).FirstOrDefault()?.Key; } // Create necessary act = actorPs.Insert(new AuditActor() { NetworkAccessPoint = a.NetworkAccessPointId, NetworkAccessPointType = (SanteGuard.Model.NetworkAccessPointType)((int)a.NetworkAccessPointType), UserIdentifier = a.UserIdentifier, UserName = a.UserName, SecurityIdentifier = sid }, TransactionMode.Commit, AuthenticationContext.Current.Principal); } return(new AuditParticipation() { Actor = act, IsRequestor = a.UserIsRequestor, Roles = a.ActorRoleCode.Select(r => MapOrCreateCode(r)).ToList() }); }).ToList(); } // Objects if (me.AuditableObjects != null) { retVal.Objects = me.AuditableObjects.Select(o => new AuditObject() { ExternalIdentifier = o.ObjectId, IdTypeCode = o.IDTypeCode.HasValue ? MapOrCreateCode(o.IDTypeCode) : MapOrCreateCode(o.CustomIdTypeCode), LifecycleCode = o.LifecycleType.HasValue ? MapOrCreateCode(o.LifecycleType.Value) : null, RoleCode = o.Role.HasValue ? MapOrCreateCode(o.Role.Value) : null, TypeCode = MapOrCreateCode(o.Type), Details = o.ObjectData.Select(d => new AuditObjectDetail() { DetailKey = d.Key, Value = d.Value }).ToList(), Specification = new List <AuditObjectSpecification>() { new AuditObjectSpecification() { Specification = o.QueryData, SpecificationType = "Q" }, new AuditObjectSpecification() { Specification = o.NameData, SpecificationType = "N" } }.Where(s => !string.IsNullOrEmpty(s.Specification)).ToList() }).ToList(); } // Extended data? foreach (var m in me.Metadata) { switch (m.Key) { case AuditMetadataKey.AuditSourceID: retVal.AuditSource.AuditSourceId = m.Value; break; case AuditMetadataKey.PID: retVal.ProcessId = m.Value; break; case AuditMetadataKey.ProcessName: retVal.ProcessName = m.Value; break; } } return(retVal); }
/// <summary> /// Convert to audit data from ATNA message /// </summary> public static Audit ToAudit(this AuditMessage me) { if (me == null) { throw new ArgumentNullException("Audit message cannot be null"); } Tracer traceSource = Tracer.GetTracer(typeof(AuditMessageExtensions)); Audit retVal = new Audit(); retVal.ActionCode = MapOrCreateCode(me.EventIdentification.ActionCode); retVal.EventIdCode = MapOrCreateCode(me.EventIdentification.EventId); retVal.OutcomeCode = MapOrCreateCode(me.EventIdentification.EventOutcome); retVal.EventTypeCodes = me.EventIdentification.EventType.Select(o => MapOrCreateCode(o)).ToList(); retVal.EventTimestamp = me.EventIdentification.EventDateTime; // Source if (me.SourceIdentification != null && me.SourceIdentification.Count > 0) { var auditSourcePs = ApplicationServiceContext.Current.GetService <IDataPersistenceService <AuditSource> >(); if (auditSourcePs != null) { int tr = 0; var currentSources = me.SourceIdentification.Select(o => auditSourcePs.Query(s => s.AuditSourceId == o.AuditSourceID && s.EnterpriseSiteId == o.AuditEnterpriseSiteID, 0, 1, out tr, AuthenticationContext.Current.Principal).FirstOrDefault()).Where(o => o != null).FirstOrDefault(); if (currentSources == null) { currentSources = auditSourcePs.Insert(new AuditSource() { EnterpriseSiteId = me.SourceIdentification.First().AuditEnterpriseSiteID, AuditSourceId = me.SourceIdentification.First().AuditSourceID, SourceType = me.SourceIdentification.First().AuditSourceTypeCode.Select(o => MapOrCreateCode(o)).ToList() }, TransactionMode.Commit, AuthenticationContext.Current.Principal); } retVal.AuditSource = currentSources; } else { retVal.AuditSource = new AuditSource() { EnterpriseSiteId = me.SourceIdentification.First().AuditEnterpriseSiteID, AuditSourceId = me.SourceIdentification.First().AuditSourceID, SourceType = me.SourceIdentification.First().AuditSourceTypeCode.Select(o => MapOrCreateCode(o)).ToList() } }; } // Participants if (me.Actors != null) { var actorPs = ApplicationServiceContext.Current.GetService <IDataPersistenceService <AuditActor> >(); retVal.Participants = me.Actors?.Select(a => { AuditActor act = null; // No persistence service just translate if (actorPs != null) { act = actorPs.Query(o => o.UserName == a.UserName && o.NetworkAccessPoint == a.NetworkAccessPointId && o.UserIdentifier == a.UserIdentifier, AuthenticationContext.Current.Principal).FirstOrDefault(); if (act == null) { Guid?sid = null; if (!String.IsNullOrEmpty(a.UserName ?? a.UserIdentifier ?? a.AlternativeUserId)) { sid = ApplicationServiceContext.Current.GetService <ISecurityRepositoryService>().GetUser(a.UserName ?? a.UserIdentifier ?? a.AlternativeUserId)?.Key; } else if (!String.IsNullOrEmpty(a.NetworkAccessPointId)) { sid = ApplicationServiceContext.Current.GetService <IRepositoryService <SecurityDevice> >().Find(o => o.Name == a.NetworkAccessPointId).FirstOrDefault()?.Key; } // Create necessary act = actorPs.Insert(new AuditActor() { NetworkAccessPoint = a.NetworkAccessPointId, NetworkAccessPointType = (SanteGuard.Model.NetworkAccessPointType)((int)a.NetworkAccessPointType), UserIdentifier = a.UserIdentifier, UserName = a.UserName, SecurityIdentifier = sid }, TransactionMode.Commit, AuthenticationContext.Current.Principal); } } else { act = new AuditActor() { NetworkAccessPoint = a.NetworkAccessPointId, NetworkAccessPointType = (SanteGuard.Model.NetworkAccessPointType)((int)a.NetworkAccessPointType), UserIdentifier = a.UserIdentifier, UserName = a.UserName, } }; return(new AuditParticipation() { Actor = act, IsRequestor = a.UserIsRequestor, Roles = a.ActorRoleCode.Select(r => MapOrCreateCode(r)).ToList() }); }).ToList(); } // Objects if (me.AuditableObjects != null) { retVal.Objects = me.AuditableObjects.Select(o => new AuditObject() { Key = Guid.NewGuid(), ExternalIdentifier = o.ObjectId, IdTypeCode = MapOrCreateCode(o.IDTypeCode), LifecycleCode = o.LifecycleTypeSpecified ? MapOrCreateCode(o.LifecycleType) : null, RoleCode = o.RoleSpecified ? MapOrCreateCode(o.Role) : null, TypeCode = o.TypeSpecified ? MapOrCreateCode(o.Type) : null, Details = o.ObjectDetail.Select(d => new AuditObjectDetail() { Key = Guid.NewGuid(), DetailKey = d.Type, Value = d.Value }).ToList(), Specification = !String.IsNullOrEmpty(o.ObjectSpec) ? new List <AuditObjectSpecification>() { new AuditObjectSpecification() { Key = Guid.NewGuid(), Specification = o.ObjectSpec, SpecificationType = o.ObjectSpecChoice == ObjectDataChoiceType.ParticipantObjectQuery ? "Q" : "N" } } : null }).ToList(); } traceSource.TraceInfo("Successfully processed audit: {0}", retVal.ToDisplay()); return(retVal); }