From 40dc60cb6cb41bb80d33b54c6d21fcadde837e85 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Fri, 10 Jul 2020 15:31:14 +0800 Subject: [PATCH] Disable Security Log feature. --- .../SecurityLog/AspNetCoreSecurityLogManager.cs | 1 - .../Abp/SecurityLog/DefaultSecurityLogManager.cs | 5 +++++ .../Volo/Abp/SecurityLog/SecurityLogInfo.cs | 10 ---------- .../Volo/Abp/SecurityLog/SimpleSecurityLogStore.cs | 12 ++++++++++-- .../Volo/Abp/Identity/IdentitySecurityLogStore.cs | 5 +++++ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/SecurityLog/AspNetCoreSecurityLogManager.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/SecurityLog/AspNetCoreSecurityLogManager.cs index 55ece86be2..f0fc0aa347 100644 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/SecurityLog/AspNetCoreSecurityLogManager.cs +++ b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/SecurityLog/AspNetCoreSecurityLogManager.cs @@ -23,7 +23,6 @@ namespace Volo.Abp.AspNetCore.SecurityLog protected ICurrentClient CurrentClient { get; } protected IHttpContextAccessor HttpContextAccessor { get; } protected ICorrelationIdProvider CorrelationIdProvider { get; } - protected IWebClientInfoProvider WebClientInfoProvider { get; } public AspNetCoreSecurityLogManager( diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/DefaultSecurityLogManager.cs b/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/DefaultSecurityLogManager.cs index ab260ff708..f628958bc4 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/DefaultSecurityLogManager.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/DefaultSecurityLogManager.cs @@ -21,6 +21,11 @@ namespace Volo.Abp.SecurityLog public async Task SaveAsync(Action saveAction = null) { + if (!SecurityLogOptions.IsEnabled) + { + return; + } + var securityLogInfo = await CreateAsync(); saveAction?.Invoke(securityLogInfo); await SecurityLogStore.SaveAsync(securityLogInfo); diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SecurityLogInfo.cs b/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SecurityLogInfo.cs index c6e562f6c8..b187b5bfa2 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SecurityLogInfo.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SecurityLogInfo.cs @@ -6,20 +6,10 @@ namespace Volo.Abp.SecurityLog [Serializable] public class SecurityLogInfo { - /// - /// The name of the application or service writing user security logs. - /// Default: null. - /// public string ApplicationName { get; set; } - /// - /// Web, JWT, Identity, Identity_Server - /// public string Identity { get; set; } - /// - /// login_successful, login_failed, logout, change_pwd, refresh_token... - /// public string Action { get; set; } public Dictionary ExtraProperties { get; } diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SimpleSecurityLogStore.cs b/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SimpleSecurityLogStore.cs index bc9c22c4df..fe6496ef40 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SimpleSecurityLogStore.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/SecurityLog/SimpleSecurityLogStore.cs @@ -1,5 +1,6 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; namespace Volo.Abp.SecurityLog @@ -7,16 +8,23 @@ namespace Volo.Abp.SecurityLog public class SimpleSecurityLogStore : ISecurityLogStore, ITransientDependency { public ILogger Logger { get; set; } + protected AbpSecurityLogOptions SecurityLogOptions { get; } - public SimpleSecurityLogStore(ILogger logger) + public SimpleSecurityLogStore(ILogger logger, IOptions securityLogOptions) { Logger = logger; + SecurityLogOptions = securityLogOptions.Value; } public Task SaveAsync(SecurityLogInfo securityLogInfo) { + if (!SecurityLogOptions.IsEnabled) + { + return Task.CompletedTask; + } + Logger.LogInformation(securityLogInfo.ToString()); - return Task.FromResult(0); + return Task.CompletedTask; } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySecurityLogStore.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySecurityLogStore.cs index 696fc3ad6a..17e3c20794 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySecurityLogStore.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySecurityLogStore.cs @@ -34,6 +34,11 @@ namespace Volo.Abp.Identity public async Task SaveAsync(SecurityLogInfo securityLogInfo) { + if (!SecurityLogOptions.IsEnabled) + { + return; + } + using (var uow = UnitOfWorkManager.Begin(requiresNew: true)) { await IdentitySecurityLogRepository.InsertAsync(new IdentitySecurityLog(GuidGenerator, securityLogInfo));