Add filter for IIdentitySecurityLogRepository.

pull/4675/head
maliming 5 years ago
parent a03ef99641
commit 787a09546f

@ -226,8 +226,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
{
Identity = IdentitySecurityLogIdentityConsts.IdentityExternal,
Action = result.ToIdentitySecurityLogAction(),
UserName = user.Name,
TenantId = user.TenantId
UserName = user.Name
});
return RedirectSafely(returnUrl, returnUrlHash);

@ -17,6 +17,7 @@ namespace Volo.Abp.Identity
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null,
@ -29,9 +30,16 @@ namespace Volo.Abp.Identity
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null,
CancellationToken cancellationToken = default);
Task<IdentitySecurityLog> GetByUserIdAsync(
Guid id,
Guid userId,
bool includeDetails = false,
CancellationToken cancellationToken = default);
}
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Identity
@ -14,5 +15,19 @@ namespace Volo.Abp.Identity
public string UserName { get; set; }
public string ClientId { get; set; }
public Dictionary<string, object> ExtraProperties { get; }
public IdentitySecurityLogEvent()
{
ExtraProperties = new Dictionary<string, object>();
}
public virtual IdentitySecurityLogEvent WithProperty(string key, object value)
{
ExtraProperties[key] = value;
return this;
}
}
}

@ -48,6 +48,11 @@ namespace Volo.Abp.Identity
{
securityLog.ClientId = eventData.ClientId;
}
foreach (var property in eventData.ExtraProperties)
{
securityLog.ExtraProperties[property.Key] = property.Value;
}
};
if (CurrentUser.IsAuthenticated)

@ -27,6 +27,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null,
@ -39,6 +40,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
applicationName,
identity,
action,
userId,
userName,
clientId,
correlationId
@ -55,6 +57,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null,
@ -66,6 +69,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
applicationName,
identity,
action,
userId,
userName,
clientId,
correlationId
@ -74,12 +78,18 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
return await query.LongCountAsync(GetCancellationToken(cancellationToken));
}
protected virtual IQueryable<IdentitySecurityLog> GetListQuery(
public async Task<IdentitySecurityLog> GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await DbSet.FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, GetCancellationToken(cancellationToken));
}
protected virtual IQueryable<IdentitySecurityLog> GetListQuery(
DateTime? startTime = null,
DateTime? endTime = null,
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null)
@ -90,6 +100,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
.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);

@ -11,7 +11,8 @@ using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB
{
public class MongoIdentitySecurityLogRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentitySecurityLog, Guid>, IIdentitySecurityLogRepository
public class MongoIdentitySecurityLogRepository :
MongoDbRepository<IAbpIdentityMongoDbContext, IdentitySecurityLog, Guid>, IIdentitySecurityLogRepository
{
public MongoIdentitySecurityLogRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
: base(dbContextProvider)
@ -27,6 +28,7 @@ namespace Volo.Abp.Identity.MongoDB
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null,
@ -39,6 +41,7 @@ namespace Volo.Abp.Identity.MongoDB
applicationName,
identity,
action,
userId,
userName,
clientId,
correlationId
@ -56,6 +59,7 @@ namespace Volo.Abp.Identity.MongoDB
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null,
@ -67,33 +71,47 @@ namespace Volo.Abp.Identity.MongoDB
applicationName,
identity,
action,
userId,
userName,
clientId,
correlationId
);
return await query.As<IMongoQueryable<IdentitySecurityLog>>().LongCountAsync(GetCancellationToken(cancellationToken));
return await query.As<IMongoQueryable<IdentitySecurityLog>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
protected virtual IQueryable<IdentitySecurityLog> GetListQuery(
DateTime? startTime = null,
DateTime? endTime = null,
string applicationName = null,
string identity = null,
string action = null,
string userName = null,
string clientId = null,
string correlationId = null)
{
return GetMongoQueryable()
.WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime)
.WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime >= endTime)
.WhereIf(!applicationName.IsNullOrWhiteSpace(), securityLog => securityLog.ApplicationName == applicationName)
.WhereIf(!identity.IsNullOrWhiteSpace(), securityLog => securityLog.Identity == identity)
.WhereIf(!action.IsNullOrWhiteSpace(), securityLog => securityLog.Action == action)
.WhereIf(!userName.IsNullOrWhiteSpace(), securityLog => securityLog.UserName == userName)
.WhereIf(!clientId.IsNullOrWhiteSpace(), securityLog => securityLog.ClientId == clientId)
.WhereIf(!correlationId.IsNullOrWhiteSpace(), securityLog => securityLog.CorrelationId == correlationId);
}
public async Task<IdentitySecurityLog> GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId,
GetCancellationToken(cancellationToken));
}
protected virtual IQueryable<IdentitySecurityLog> GetListQuery(
DateTime? startTime = null,
DateTime? endTime = null,
string applicationName = null,
string identity = null,
string action = null,
Guid? userId = null,
string userName = null,
string clientId = null,
string correlationId = null)
{
return GetMongoQueryable()
.WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime)
.WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime >= endTime)
.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);
}
}
}

Loading…
Cancel
Save