Browse Source

Using `string` as session id.

pull/18242/head
maliming 2 years ago
parent
commit
ce7f84461e
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 9
      framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.cs
  2. 18
      framework/src/Volo.Abp.Security/Volo/Abp/Users/CurrentUserExtensions.cs
  3. 4
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySessionRepository.cs
  4. 4
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs
  5. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Claims/AbpDefaultOpenIddictClaimsPrincipalHandler.cs

9
framework/src/Volo.Abp.Security/System/Security/Principal/AbpClaimsIdentityExtensions.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)

18
framework/src/Volo.Abp.Security/Volo/Abp/Users/CurrentUserExtensions.cs

@ -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);
}
}

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

@ -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);
}
}

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

@ -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);
}
}

2
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Claims/AbpDefaultOpenIddictClaimsPrincipalHandler.cs

@ -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;
}

Loading…
Cancel
Save