From fe97d413a6746c81422bf7256c068e9b96be3166 Mon Sep 17 00:00:00 2001 From: PascalSenn Date: Thu, 20 Jun 2024 10:47:40 +0200 Subject: [PATCH] Remove data conenction cache --- .../IUserDataConnectorDataRepository.cs | 16 ------ .../DataConnector/UserDataConnectorService.cs | 54 +------------------ .../MongoStoreServiceCollectionExtensions.cs | 3 -- .../UserDataConnectorDataRepository.cs | 46 ---------------- 4 files changed, 1 insertion(+), 118 deletions(-) delete mode 100644 src/IdentityServer/src/Abstractions/Stores/IUserDataConnectorDataRepository.cs delete mode 100644 src/IdentityServer/src/Store.Mongo/UserDataConnectorDataRepository.cs diff --git a/src/IdentityServer/src/Abstractions/Stores/IUserDataConnectorDataRepository.cs b/src/IdentityServer/src/Abstractions/Stores/IUserDataConnectorDataRepository.cs deleted file mode 100644 index e7f58ae..0000000 --- a/src/IdentityServer/src/Abstractions/Stores/IUserDataConnectorDataRepository.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Threading; -using System.Threading.Tasks; -using IdOps.IdentityServer.DataConnector; - -namespace IdOps.IdentityServer.Storage -{ - public interface IUserDataConnectorDataRepository - { - Task GetAsync( - string key, - string connector, - CancellationToken cancellationToken); - - Task SaveAsync(UserDataConnectorData data, CancellationToken cancellationToken); - } -} diff --git a/src/IdentityServer/src/IdentityServer.Core/DataConnector/UserDataConnectorService.cs b/src/IdentityServer/src/IdentityServer.Core/DataConnector/UserDataConnectorService.cs index d43fd1d..af61ddd 100644 --- a/src/IdentityServer/src/IdentityServer.Core/DataConnector/UserDataConnectorService.cs +++ b/src/IdentityServer/src/IdentityServer.Core/DataConnector/UserDataConnectorService.cs @@ -20,7 +20,6 @@ public class UserDataConnectorService : IUserDataConnectorService { private readonly ILogger _logger; private readonly IEnumerable _connectors; - private readonly IUserDataConnectorDataRepository _repository; private readonly IEventService _eventService; private static readonly Dictionary ProfileTypeMap @@ -34,12 +33,10 @@ private static readonly Dictionary ProfileTypeMap public UserDataConnectorService( ILogger logger, IEnumerable connectors, - IUserDataConnectorDataRepository repository, IEventService eventService) { _logger = logger; _connectors = connectors; - _repository = repository; _eventService = eventService; } @@ -108,7 +105,7 @@ private async Task> LoadDataAsync( IUserDataConnector? connector = _connectors .Single(x => x.Name == options.Name); - var timeOutToken = new CancellationTokenSource(Debugger.IsAttached ? 300000 : 5000); + var timeOutToken = new CancellationTokenSource(300000); CancellationTokenSource cts = CancellationTokenSource.CreateLinkedTokenSource( cancellationToken, @@ -121,58 +118,9 @@ private async Task> LoadDataAsync( activity?.EnrichDataConnectorResult(result); - if (result.Success && result.Executed && result.CacheKey != null) - { - try - { - await SaveDataAsync(options, result, context.Subject, cancellationToken); - } - catch (Exception ex) - { - _logger.DataConnectorSaveDataFailed(connector.Name); - activity?.RecordException(ex); - } - } - else if (!result.Success && result.CacheKey != null) - { - UserDataConnectorData? storedData = await _repository.GetAsync( - result.CacheKey, - connector.Name, - cancellationToken); - - if (storedData != null) - { - claims = storedData.Claims.Select(x => new Claim(x.Type, x.Value)); - } - else - { - throw result.Error; - } - } - return claims; } - private async Task SaveDataAsync( - DataConnectorOptions options, - UserDataConnectorResult result, - string subject, - CancellationToken cancellationToken) - { - await _repository.SaveAsync(new UserDataConnectorData - { - Claims = result.Claims.Select(x => new ClaimData - { - Type = x.Type, - Value = x.Value - }), - Key = result.CacheKey!, - SubjectId = subject, - Connector = options.Name, - LastModifiedAt = DateTime.UtcNow - }, cancellationToken); - } - private bool ShouldExecute(DataConnectorOptions options, string caller) { return options.Enabled && diff --git a/src/IdentityServer/src/Store.Mongo/MongoStoreServiceCollectionExtensions.cs b/src/IdentityServer/src/Store.Mongo/MongoStoreServiceCollectionExtensions.cs index 28a4f5c..1050dcb 100644 --- a/src/IdentityServer/src/Store.Mongo/MongoStoreServiceCollectionExtensions.cs +++ b/src/IdentityServer/src/Store.Mongo/MongoStoreServiceCollectionExtensions.cs @@ -51,9 +51,6 @@ public static IServiceCollection AddMongoStores( services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton< - IUserDataConnectorDataRepository, - UserDataConnectorDataRepository>(); return services; } diff --git a/src/IdentityServer/src/Store.Mongo/UserDataConnectorDataRepository.cs b/src/IdentityServer/src/Store.Mongo/UserDataConnectorDataRepository.cs deleted file mode 100644 index cc41679..0000000 --- a/src/IdentityServer/src/Store.Mongo/UserDataConnectorDataRepository.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using IdOps.IdentityServer.DataConnector; -using MongoDB.Driver; -using MongoDB.Driver.Linq; - -namespace IdOps.IdentityServer.Storage.Mongo -{ - public class UserDataConnectorDataRepository : IUserDataConnectorDataRepository - { - private readonly IIdentityStoreDbContext _dbContext; - - public UserDataConnectorDataRepository(IIdentityStoreDbContext dbContext) - { - _dbContext = dbContext; - } - - public async Task GetAsync( - string key, - string connector, - CancellationToken cancellationToken) - { - return await _dbContext.ConnectorData.AsQueryable() - .Where(x => x.Key == key && x.Connector == connector) - .FirstOrDefaultAsync(cancellationToken); - } - - public async Task SaveAsync( - UserDataConnectorData data, - CancellationToken cancellationToken) - { - FilterDefinition filter = - Builders.Filter - .Eq(x => x.Key, data.Key) & - Builders.Filter - .Eq(x => x.Connector, data.Connector); - - await _dbContext.ConnectorData.ReplaceOneAsync( - filter, - data, - options: new ReplaceOptions { IsUpsert = true }, - cancellationToken); - } - } -}