Browse Source

Merge pull request #25897 from abpframework/maliming/fix-identity-session-cleanup

Fall back to `SignedIn` when `LastAccessed` is null in inactive session cleanup
pull/25908/head
Engincan VESKE 5 days ago
committed by GitHub
parent
commit
d1d60d590c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySessionRepository.cs
  2. 10
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs

10
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySessionRepository.cs

@ -14,10 +14,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore;
public class EfCoreIdentitySessionRepository : EfCoreRepository<IIdentityDbContext, IdentitySession, Guid>, IIdentitySessionRepository
{
public EfCoreIdentitySessionRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
protected IClock Clock { get; }
public EfCoreIdentitySessionRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider, IClock clock)
: base(dbContextProvider)
{
Clock = clock;
}
public virtual async Task<IdentitySession> FindAsync(string sessionId, CancellationToken cancellationToken = default)
@ -89,7 +91,7 @@ public class EfCoreIdentitySessionRepository : EfCoreRepository<IIdentityDbConte
public virtual async Task DeleteAllAsync(TimeSpan inactiveTimeSpan, CancellationToken cancellationToken = default)
{
var now = LazyServiceProvider.LazyGetRequiredService<IClock>().Now;
await DeleteDirectAsync(x => x.LastAccessed == null || x.LastAccessed < now.Subtract(inactiveTimeSpan), cancellationToken: cancellationToken);
var inactiveTime = Clock.Now.Subtract(inactiveTimeSpan);
await DeleteDirectAsync(x => (x.LastAccessed ?? x.SignedIn) < inactiveTime, cancellationToken: cancellationToken);
}
}

10
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs

@ -15,10 +15,12 @@ namespace Volo.Abp.Identity.MongoDB;
public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentitySession, Guid>, IIdentitySessionRepository
{
public MongoIdentitySessionRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
protected IClock Clock { get; }
public MongoIdentitySessionRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider, IClock clock)
: base(dbContextProvider)
{
Clock = clock;
}
public virtual async Task<IdentitySession> FindAsync(string sessionId, CancellationToken cancellationToken = default)
@ -93,7 +95,7 @@ public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMong
public virtual async Task DeleteAllAsync(TimeSpan inactiveTimeSpan, CancellationToken cancellationToken = default)
{
var now = LazyServiceProvider.LazyGetRequiredService<IClock>().Now;
await DeleteDirectAsync(x => x.LastAccessed == null || x.LastAccessed < now.Subtract(inactiveTimeSpan), cancellationToken: cancellationToken);
var inactiveTime = Clock.Now.Subtract(inactiveTimeSpan);
await DeleteDirectAsync(x => (x.LastAccessed ?? x.SignedIn) < inactiveTime, cancellationToken: cancellationToken);
}
}

Loading…
Cancel
Save