From 32034300dbd1d2842c7bc2e9e3e2031c58af9133 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 26 Dec 2024 10:20:55 +0800 Subject: [PATCH] Added `clientIpAddress` parameter to query the `security logs`. --- .../Abp/Identity/IIdentitySecurityLogRepository.cs | 2 ++ .../EfCoreIdentitySecurityLogRepository.cs | 8 +++++++- .../MongoDB/MongoIdentitySecurityLogRepository.cs | 12 ++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentitySecurityLogRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentitySecurityLogRepository.cs index 8a1e50795f3..af163253b4f 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentitySecurityLogRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentitySecurityLogRepository.cs @@ -21,6 +21,7 @@ Task> GetListAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, bool includeDetails = false, CancellationToken cancellationToken = default); @@ -34,6 +35,7 @@ Task GetCountAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, CancellationToken cancellationToken = default); Task GetByUserIdAsync( diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySecurityLogRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySecurityLogRepository.cs index 20432933951..808d7f48f42 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySecurityLogRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySecurityLogRepository.cs @@ -31,6 +31,7 @@ public virtual async Task> GetListAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -46,6 +47,7 @@ public virtual async Task> GetListAsync( userName, clientId, correlationId, + clientIpAddress, cancellationToken ); @@ -64,6 +66,7 @@ public virtual async Task GetCountAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, CancellationToken cancellationToken = default) { cancellationToken = GetCancellationToken(cancellationToken); @@ -78,6 +81,7 @@ public virtual async Task GetCountAsync( userName, clientId, correlationId, + clientIpAddress, cancellationToken ); @@ -101,6 +105,7 @@ protected virtual async Task> GetListQueryAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, CancellationToken cancellationToken = default) { return (await GetDbSetAsync()).AsNoTracking() @@ -112,6 +117,7 @@ protected virtual async Task> GetListQueryAsync( .WhereIf(userId.HasValue, securityLog => securityLog.UserId == userId) .WhereIf(!userName.IsNullOrWhiteSpace(), securityLog => securityLog.UserName == userName) .WhereIf(!clientId.IsNullOrWhiteSpace(), securityLog => securityLog.ClientId == clientId) - .WhereIf(!correlationId.IsNullOrWhiteSpace(), securityLog => securityLog.CorrelationId == correlationId); + .WhereIf(!correlationId.IsNullOrWhiteSpace(), securityLog => securityLog.CorrelationId == correlationId) + .WhereIf(!clientIpAddress.IsNullOrWhiteSpace(), securityLog => securityLog.ClientIpAddress == clientIpAddress); } } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs index 6a875444f9f..f1732720099 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs @@ -32,6 +32,7 @@ public virtual async Task> GetListAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -45,6 +46,7 @@ public virtual async Task> GetListAsync( userName, clientId, correlationId, + clientIpAddress, cancellationToken ); @@ -64,6 +66,7 @@ public virtual async Task GetCountAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, CancellationToken cancellationToken = default) { var query = await GetListQueryAsync( @@ -76,6 +79,7 @@ public virtual async Task GetCountAsync( userName, clientId, correlationId, + clientIpAddress, cancellationToken ); @@ -101,19 +105,19 @@ protected virtual async Task> GetListQueryAsync( string userName = null, string clientId = null, string correlationId = null, + string clientIpAddress = null, CancellationToken cancellationToken = default) { return (await GetMongoQueryableAsync(cancellationToken)) .WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value) .WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date) - .WhereIf(!applicationName.IsNullOrWhiteSpace(), - securityLog => securityLog.ApplicationName == applicationName) + .WhereIf(!applicationName.IsNullOrWhiteSpace(), securityLog => securityLog.ApplicationName == applicationName) .WhereIf(!identity.IsNullOrWhiteSpace(), securityLog => securityLog.Identity == identity) .WhereIf(!action.IsNullOrWhiteSpace(), securityLog => securityLog.Action == action) .WhereIf(userId.HasValue, securityLog => securityLog.UserId == userId) .WhereIf(!userName.IsNullOrWhiteSpace(), securityLog => securityLog.UserName == userName) .WhereIf(!clientId.IsNullOrWhiteSpace(), securityLog => securityLog.ClientId == clientId) - .WhereIf(!correlationId.IsNullOrWhiteSpace(), - securityLog => securityLog.CorrelationId == correlationId); + .WhereIf(!correlationId.IsNullOrWhiteSpace(), securityLog => securityLog.CorrelationId == correlationId) + .WhereIf(!clientIpAddress.IsNullOrWhiteSpace(), securityLog => securityLog.ClientIpAddress == clientIpAddress); } }