From 65ec7ced2617cf8ac10816696995f6bbd4bf26cf Mon Sep 17 00:00:00 2001 From: colin Date: Sun, 21 Jun 2026 18:27:49 +0800 Subject: [PATCH] fix: The token cleanup operation failed to be repaired. --- ...rverMigrationsEntityFrameworkCoreModule.cs | 6 +++ .../EfCoreMySqlOpenIddictTokenRepository.cs | 39 +++++++++++++++++++ ...BackendAdminHttpApiHostModule.Configure.cs | 11 +++++- .../BackendAdminHttpApiHostModule.cs | 11 +++--- ...roService.BackendAdmin.HttpApi.Host.csproj | 7 +--- .../SystemGroupSettingDefinitionProvider.cs | 6 ++- 6 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreMySqlOpenIddictTokenRepository.cs diff --git a/aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/AuthServerMigrationsEntityFrameworkCoreModule.cs b/aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/AuthServerMigrationsEntityFrameworkCoreModule.cs index 57eb2f8fe..242e60e62 100644 --- a/aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/AuthServerMigrationsEntityFrameworkCoreModule.cs +++ b/aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/AuthServerMigrationsEntityFrameworkCoreModule.cs @@ -13,6 +13,7 @@ using Volo.Abp.EntityFrameworkCore; using Volo.Abp.FeatureManagement.EntityFrameworkCore; using Volo.Abp.Modularity; using Volo.Abp.OpenIddict.EntityFrameworkCore; +using Volo.Abp.OpenIddict.Tokens; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.SettingManagement.EntityFrameworkCore; @@ -48,5 +49,10 @@ public class AuthServerMigrationsEntityFrameworkCoreModule : AbpModule mysql.UseParameterizedCollectionMode(ParameterTranslationMode.Constant); }); }); + + context.Services.AddAbpDbContext(options => + { + options.AddRepository(); + }); } } diff --git a/aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreMySqlOpenIddictTokenRepository.cs b/aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreMySqlOpenIddictTokenRepository.cs new file mode 100644 index 000000000..a4661373d --- /dev/null +++ b/aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreMySqlOpenIddictTokenRepository.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore; +using OpenIddict.Abstractions; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.OpenIddict.Authorizations; +using Volo.Abp.OpenIddict.EntityFrameworkCore; + +namespace Volo.Abp.OpenIddict.Tokens; + +public class EfCoreMySqlOpenIddictTokenRepository : EfCoreOpenIddictTokenRepository +{ + public EfCoreMySqlOpenIddictTokenRepository( + IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + public async override Task PruneAsync(DateTime date, CancellationToken cancellationToken = default) + { + var dbContext = await GetDbContextAsync(); + var tokens = await (from token in dbContext.Set() + join authorization in dbContext.Set() + on token.AuthorizationId equals authorization.Id into tokenAuthorizations + from tokenAuthorization in tokenAuthorizations.DefaultIfEmpty() + where token.CreationDate < date + where (token.Status != OpenIddictConstants.Statuses.Inactive && token.Status != OpenIddictConstants.Statuses.Valid) || + (tokenAuthorization != null && tokenAuthorization.Status != OpenIddictConstants.Statuses.Valid) || + token.ExpirationDate < DateTime.UtcNow + select token) + .ToListAsync(GetCancellationToken(cancellationToken)); + + await DeleteManyAsync(tokens, cancellationToken: GetCancellationToken(cancellationToken)); + + return tokens.Count; + } +} \ No newline at end of file diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Configure.cs b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Configure.cs index d9818741c..3b0144e19 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Configure.cs +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Configure.cs @@ -45,6 +45,7 @@ using Volo.Abp.Json; using Volo.Abp.Json.SystemTextJson; using Volo.Abp.Localization; using Volo.Abp.MultiTenancy; +using Volo.Abp.OpenIddict.Tokens; using Volo.Abp.PermissionManagement; using Volo.Abp.Security.Claims; using Volo.Abp.SettingManagement; @@ -147,7 +148,7 @@ public partial class BackendAdminHttpApiHostModule options.IsDynamicPermissionStoreEnabled = true; // Rename IdentityServer.Client.ManagePermissions // See https://github.com/abpframework/abp/blob/dev/modules/identityserver/src/Volo.Abp.PermissionManagement.Domain.IdentityServer/Volo/Abp/PermissionManagement/IdentityServer/AbpPermissionManagementDomainIdentityServerModule.cs - options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = "AbpIdentityServer.Clients.ManagePermissions"; + options.ProviderPolicies[ClientPermissionValueProvider.ProviderName] = "AbpOpenIddict.Applications.ManagePermissions"; }); } @@ -179,6 +180,14 @@ public partial class BackendAdminHttpApiHostModule }); } + private void ConfigureBackgroundWorker() + { + Configure(options => + { + options.IsCleanupEnabled = false; + }); + } + private void ConfigureExceptionHandling() { // 自定义需要处理的异常 diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs index 2e09805f0..4dc958288 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs @@ -4,6 +4,7 @@ using LINGYUN.Abp.AspNetCore.Mvc.Localization; using LINGYUN.Abp.AspNetCore.Mvc.Wrapper; using LINGYUN.Abp.Auditing; using LINGYUN.Abp.AuditLogging.Elasticsearch; +using LINGYUN.Abp.BlobManagement.SettingManagement; using LINGYUN.Abp.CachingManagement; using LINGYUN.Abp.CachingManagement.StackExchangeRedis; using LINGYUN.Abp.Claims.Mapping; @@ -19,7 +20,6 @@ using LINGYUN.Abp.Identity.Session.AspNetCore; using LINGYUN.Abp.Localization.CultureMap; using LINGYUN.Abp.LocalizationManagement.EntityFrameworkCore; using LINGYUN.Abp.Logging.Serilog.Elasticsearch; -using LINGYUN.Abp.BlobManagement.SettingManagement; using LINGYUN.Abp.PermissionManagement; using LINGYUN.Abp.PermissionManagement.HttpApi; using LINGYUN.Abp.PermissionManagement.OrganizationUnits; @@ -49,11 +49,11 @@ using Volo.Abp.Autofac; using Volo.Abp.Caching.StackExchangeRedis; using Volo.Abp.FeatureManagement.EntityFrameworkCore; using Volo.Abp.Http.Client; -using Volo.Abp.IdentityServer.EntityFrameworkCore; using Volo.Abp.Modularity; +using Volo.Abp.OpenIddict.EntityFrameworkCore; using Volo.Abp.PermissionManagement.EntityFrameworkCore; using Volo.Abp.PermissionManagement.Identity; -using Volo.Abp.PermissionManagement.IdentityServer; +using Volo.Abp.PermissionManagement.OpenIddict; using Volo.Abp.SettingManagement.EntityFrameworkCore; using Volo.Abp.Swashbuckle; @@ -96,12 +96,12 @@ namespace LY.MicroService.BackendAdmin; typeof(AbpCachingManagementHttpApiModule), typeof(AbpCachingManagementStackExchangeRedisModule), typeof(AbpIdentityEntityFrameworkCoreModule),// 用户角色权限需要引用包 - typeof(AbpIdentityServerEntityFrameworkCoreModule), // 客户端权限需要引用包 + typeof(AbpOpenIddictEntityFrameworkCoreModule), // 客户端权限需要引用包 typeof(AbpPermissionManagementDomainOrganizationUnitsModule), // 组织机构权限管理 typeof(AbpSaasEntityFrameworkCoreModule), typeof(AbpSettingManagementEntityFrameworkCoreModule), typeof(AbpPermissionManagementDomainIdentityModule), - typeof(AbpPermissionManagementDomainIdentityServerModule), + typeof(AbpPermissionManagementDomainOpenIddictModule), typeof(AbpPermissionManagementEntityFrameworkCoreModule), typeof(AbpFeatureManagementEntityFrameworkCoreModule), typeof(AbpLocalizationManagementEntityFrameworkCoreModule), @@ -148,6 +148,7 @@ public partial class BackendAdminHttpApiHostModule : AbpModule ConfigureWrapper(); ConfigureLocalization(); + ConfigureBackgroundWorker(); ConfigureExceptionHandling(); ConfigureVirtualFileSystem(); ConfigureTextTemplating(); diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj index 5bb4076f2..ce2c960e8 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj @@ -34,17 +34,14 @@ - - + - + - - diff --git a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Settings/SystemGroupSettingDefinitionProvider.cs b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Settings/SystemGroupSettingDefinitionProvider.cs index ba6bfab92..3ab859411 100644 --- a/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Settings/SystemGroupSettingDefinitionProvider.cs +++ b/aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Settings/SystemGroupSettingDefinitionProvider.cs @@ -48,7 +48,8 @@ public class SystemGroupSettingDefinitionProvider : SettingDefinitionProvider DefaultValueSettingValueProvider.ProviderName, ConfigurationSettingValueProvider.ProviderName, GlobalSettingValueProvider.ProviderName, - TenantSettingValueProvider.ProviderName); + TenantSettingValueProvider.ProviderName, + UserSettingValueProvider.ProviderName); var timezoneSetting = context.GetOrNull(TimingSettingNames.TimeZone); if (timezoneSetting != null) @@ -74,7 +75,8 @@ public class SystemGroupSettingDefinitionProvider : SettingDefinitionProvider DefaultValueSettingValueProvider.ProviderName, ConfigurationSettingValueProvider.ProviderName, GlobalSettingValueProvider.ProviderName, - TenantSettingValueProvider.ProviderName); + TenantSettingValueProvider.ProviderName, + UserSettingValueProvider.ProviderName); } }