Browse Source

fix: The token cleanup operation failed to be repaired.

pull/1512/head
colin 3 months ago
parent
commit
65ec7ced26
  1. 6
      aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/AuthServerMigrationsEntityFrameworkCoreModule.cs
  2. 39
      aspnet-core/migrations/LY.MicroService.AuthServer.EntityFrameworkCore/Volo/Abp/OpenIddict/Tokens/EfCoreMySqlOpenIddictTokenRepository.cs
  3. 11
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.Configure.cs
  4. 11
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/BackendAdminHttpApiHostModule.cs
  5. 7
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj
  6. 6
      aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/Settings/SystemGroupSettingDefinitionProvider.cs

6
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<OpenIddictDbContext>(options =>
{
options.AddRepository<OpenIddictToken, EfCoreMySqlOpenIddictTokenRepository>();
});
}
}

39
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<IOpenIddictDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async override Task<long> PruneAsync(DateTime date, CancellationToken cancellationToken = default)
{
var dbContext = await GetDbContextAsync();
var tokens = await (from token in dbContext.Set<OpenIddictToken>()
join authorization in dbContext.Set<OpenIddictAuthorization>()
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;
}
}

11
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<TokenCleanupOptions>(options =>
{
options.IsCleanupEnabled = false;
});
}
private void ConfigureExceptionHandling()
{
// 自定义需要处理的异常

11
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();

7
aspnet-core/services/LY.MicroService.BackendAdmin.HttpApi.Host/LY.MicroService.BackendAdmin.HttpApi.Host.csproj

@ -34,17 +34,14 @@
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="Volo.Abp.Autofac" />
<PackageReference Include="Volo.Abp.FeatureManagement.Application" />
<PackageReference Include="Volo.Abp.FeatureManagement.EntityFrameworkCore" />
<PackageReference Include="Volo.Abp.FeatureManagement.HttpApi" />
<PackageReference Include="Volo.Abp.Http.Client" />
<PackageReference Include="Volo.Abp.IdentityServer.EntityFrameworkCore" />
<PackageReference Include="Volo.Abp.OpenIddict.EntityFrameworkCore" />
<PackageReference Include="Volo.Abp.PermissionManagement.Application" />
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.Identity" />
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.IdentityServer" />
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.OpenIddict" />
<PackageReference Include="Volo.Abp.PermissionManagement.HttpApi" />
<PackageReference Include="Volo.Abp.Swashbuckle" />
<PackageReference Include="Volo.Abp.SettingManagement.EntityFrameworkCore" />
<PackageReference Include="Volo.Abp.PermissionManagement.EntityFrameworkCore" />
</ItemGroup>
<ItemGroup>

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

Loading…
Cancel
Save