maliming
2 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
5 changed files with
13 additions and
24 deletions
-
framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.cs
-
framework/src/Volo.Abp.Security/Volo/Abp/Users/CurrentUserExtensions.cs
-
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySessionRepository.cs
-
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs
-
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Claims/AbpDefaultOpenIddictClaimsPrincipalHandler.cs
|
|
|
@ -277,7 +277,7 @@ public static class AbpClaimsIdentityExtensions |
|
|
|
return principal; |
|
|
|
} |
|
|
|
|
|
|
|
public static Guid? FindSessionId([NotNull] this IIdentity identity) |
|
|
|
public static string? FindSessionId([NotNull] this IIdentity identity) |
|
|
|
{ |
|
|
|
Check.NotNull(identity, nameof(identity)); |
|
|
|
|
|
|
|
@ -289,12 +289,7 @@ public static class AbpClaimsIdentityExtensions |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
if (Guid.TryParse(sessionIdOrNull.Value, out var guid)) |
|
|
|
{ |
|
|
|
return guid; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
return sessionIdOrNull.Value; |
|
|
|
} |
|
|
|
|
|
|
|
public static string? FindSessionId([NotNull] this ClaimsPrincipal principal) |
|
|
|
|
|
|
|
@ -71,25 +71,15 @@ public static class CurrentUserExtensions |
|
|
|
return currentUser.FindClaimValue(AbpClaimTypes.ImpersonatorUserName); |
|
|
|
} |
|
|
|
|
|
|
|
public static Guid GetSessionId([NotNull] this ICurrentUser currentUser) |
|
|
|
public static string GetSessionId([NotNull] this ICurrentUser currentUser) |
|
|
|
{ |
|
|
|
var sessionId = currentUser.FindSessionId(); |
|
|
|
Debug.Assert(sessionId != null, "sessionId != null"); |
|
|
|
return sessionId!.Value; |
|
|
|
return sessionId!; |
|
|
|
} |
|
|
|
|
|
|
|
public static Guid? FindSessionId([NotNull] this ICurrentUser currentUser) |
|
|
|
public static string? FindSessionId([NotNull] this ICurrentUser currentUser) |
|
|
|
{ |
|
|
|
var sessionId = currentUser.FindClaimValue(AbpClaimTypes.SessionId); |
|
|
|
if (sessionId.IsNullOrWhiteSpace()) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
if (Guid.TryParse(sessionId, out var guid)) |
|
|
|
{ |
|
|
|
return guid; |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
return currentUser.FindClaimValue(AbpClaimTypes.SessionId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
|
using Volo.Abp.Timing; |
|
|
|
|
|
|
|
namespace Volo.Abp.Identity.EntityFrameworkCore; |
|
|
|
|
|
|
|
@ -78,6 +79,7 @@ public class EfCoreIdentitySessionRepository : EfCoreRepository<IIdentityDbConte |
|
|
|
|
|
|
|
public virtual async Task DeleteAllAsync(TimeSpan inactiveTimeSpan, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
await DeleteDirectAsync(x => x.LastAccessed == null || x.LastAccessed < DateTime.UtcNow.Subtract(inactiveTimeSpan), cancellationToken: cancellationToken); |
|
|
|
var now = LazyServiceProvider.LazyGetRequiredService<IClock>().Now; |
|
|
|
await DeleteDirectAsync(x => x.LastAccessed == null || x.LastAccessed < now.Subtract(inactiveTimeSpan), cancellationToken: cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -9,6 +9,7 @@ using MongoDB.Driver.Linq; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories.MongoDB; |
|
|
|
using Volo.Abp.MongoDB; |
|
|
|
using Volo.Abp.Timing; |
|
|
|
|
|
|
|
namespace Volo.Abp.Identity.MongoDB; |
|
|
|
|
|
|
|
@ -83,6 +84,7 @@ public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMong |
|
|
|
|
|
|
|
public virtual async Task DeleteAllAsync(TimeSpan inactiveTimeSpan, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
await DeleteDirectAsync(x => x.LastAccessed == null || x.LastAccessed < DateTime.UtcNow.Subtract(inactiveTimeSpan), cancellationToken: cancellationToken); |
|
|
|
var now = LazyServiceProvider.LazyGetRequiredService<IClock>().Now; |
|
|
|
await DeleteDirectAsync(x => x.LastAccessed == null || x.LastAccessed < now.Subtract(inactiveTimeSpan), cancellationToken: cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -28,7 +28,7 @@ public class AbpDefaultOpenIddictClaimsPrincipalHandler : IAbpOpenIddictClaimsPr |
|
|
|
|
|
|
|
if (claim.Type == AbpClaimTypes.SessionId) |
|
|
|
{ |
|
|
|
claim.SetDestinations(OpenIddictConstants.Destinations.AccessToken); |
|
|
|
claim.SetDestinations(OpenIddictConstants.Destinations.AccessToken, OpenIddictConstants.Destinations.IdentityToken); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
|