Added skoruba api integration

This commit is contained in:
2026-10-04 14:31:06 +02:00
parent b3957f4af4
commit 06539236a1
151 changed files with 317 additions and 242 deletions
@@ -1,6 +1,7 @@
using PostFundManagement.Domain.Abstractions;
using PostFundManagement.Domain.Security;
using PostFundManagement.Domain.Security.Configuration;
using PostFundManagement.Domain.Attributes;
using PostFundManagement.Domain.Configuration.Security;
using PostFundManagement.Infrastructure.Security;
namespace PostFundManagement.Application.Extensions;
@@ -1,13 +1,53 @@
using PostFundManagement.Application.Interceptors;
using PostFundManagement.Application.Services.Shared;
using PostFundManagement.Domain.Security.Configuration;
using PostFundManagement.Domain.Abstractions;
using PostFundManagement.Domain.Configuration.Security;
using PostFundManagement.Domain.Extensions;
using PostFundManagement.Domain.Security.Sdk;
using PostFundManagement.Infrastructure.Database;
using PostFundManagement.Infrastructure.Security;
using static PostFundManagement.Domain.Extensions.Constants;
namespace PostFundManagement.Application.Extensions;
public static class Security
{
public static IServiceCollection AddSkorubaApiService(this IServiceCollection services, IConfiguration configuration)
{
var configSection = configuration.GetSection(nameof(MachineIdentitySettings));
var authOptions = new MachineIdentitySettings();
configSection.Bind(authOptions);
services.Configure<MachineIdentitySettings>(configSection);
if (string.IsNullOrWhiteSpace(authOptions.Authority))
return services;
if (!authOptions.Authority.EndsWith('/')) authOptions.Authority += "/";
services.AddClientCredentialsTokenManagement()
.AddClient(SkorubaCredentialClient, client =>
{
client.TokenEndpoint = new Uri($"{authOptions.Authority}connect/token");
client.ClientId = ClientId.Parse(authOptions.ClientId!);
client.ClientSecret = ClientSecret.Parse(authOptions.ClientSecret!);
client.Scope = Duende.AccessTokenManagement.Scope.ParseOrDefault(authOptions.Scope);
});
services.AddHttpClient(SkorubaHttpClient, client =>
{
client.BaseAddress = new Uri(configuration.GetConnectionString("SkorubaApi")!);
}).AddClientCredentialsTokenHandler(ClientCredentialsClientName.Parse(SkorubaCredentialClient));
services.AddScoped<AuditInterceptor>();
services.AddScoped<LoggingInterceptor>();
services.AddSingleton<ProxyGenerator>();
services.AddLoggedAuditedServiceScoped<ISkorubaUserService, SkorubaUserService>();
return services;
}
public static IServiceCollection AddSecurityApiSdk(this IServiceCollection services, IConfiguration configuration)
{
var configSection = configuration.GetSection(nameof(SecurityClientSettings));
@@ -0,0 +1,78 @@
using PostFundManagement.Application.Interceptors;
namespace PostFundManagement.Application.Extensions;
public static class ServiceExtensionTools
{
public static IServiceCollection AddLoggedCachedServiceScoped<TInterface, TImplementation, TCacheDecorator>(this IServiceCollection services)
where TInterface : class
where TImplementation : class, TInterface
where TCacheDecorator : class, TInterface
{
services.AddScoped<TImplementation>();
services.AddScoped<TCacheDecorator>();
services.AddScoped(provider =>
{
var proxyGenerator = provider.GetRequiredService<ProxyGenerator>();
var loggingInterceptor = provider.GetRequiredService<LoggingInterceptor>();
var actual = provider.GetRequiredService<TImplementation>();
var cached = ActivatorUtilities.CreateInstance<TCacheDecorator>(provider, actual);
return proxyGenerator.CreateInterfaceProxyWithTarget<TInterface>(cached,
loggingInterceptor.ToInterceptor());
});
return services;
}
public static IServiceCollection AddLoggedAuditedCachedServiceScoped<TInterface, TImplementation, TCacheDecorator>(this IServiceCollection services)
where TInterface : class
where TImplementation : class, TInterface
where TCacheDecorator : class, TInterface
{
services.AddScoped<TImplementation>();
services.AddScoped<TCacheDecorator>();
services.AddScoped(provider =>
{
var proxyGenerator = provider.GetRequiredService<ProxyGenerator>();
var auditInterceptor = provider.GetRequiredService<AuditInterceptor>();
var loggingInterceptor = provider.GetRequiredService<LoggingInterceptor>();
var actual = provider.GetRequiredService<TImplementation>();
var cached = ActivatorUtilities.CreateInstance<TCacheDecorator>(provider, actual);
return proxyGenerator.CreateInterfaceProxyWithTarget<TInterface>(cached,
loggingInterceptor.ToInterceptor(),
auditInterceptor.ToInterceptor());
});
return services;
}
public static IServiceCollection AddLoggedAuditedServiceScoped<TInterface, TImplementation>(this IServiceCollection services)
where TInterface : class
where TImplementation : class, TInterface
{
services.AddScoped<TImplementation>();
services.AddScoped(provider =>
{
var proxyGenerator = provider.GetRequiredService<ProxyGenerator>();
var auditInterceptor = provider.GetRequiredService<AuditInterceptor>();
var loggingInterceptor = provider.GetRequiredService<LoggingInterceptor>();
var actual = provider.GetRequiredService<TImplementation>();
return proxyGenerator.CreateInterfaceProxyWithTarget<TInterface>(actual,
loggingInterceptor.ToInterceptor(),
auditInterceptor.ToInterceptor());
});
return services;
}
}
@@ -15,56 +15,6 @@ namespace PostFundManagement.Application.Extensions;
public static class Services
{
public static IServiceCollection AddLoggedCachedServiceScoped<TInterface, TImplementation, TCacheDecorator>(this IServiceCollection services)
where TInterface : class
where TImplementation : class, TInterface
where TCacheDecorator : class, TInterface
{
services.AddScoped<TImplementation>();
services.AddScoped<TCacheDecorator>();
services.AddScoped(sp =>
{
var proxyGenerator = sp.GetRequiredService<ProxyGenerator>();
var loggingInterceptor = sp.GetRequiredService<LoggingInterceptor>();
var actual = sp.GetRequiredService<TImplementation>();
var cached = ActivatorUtilities.CreateInstance<TCacheDecorator>(sp, actual);
return proxyGenerator.CreateInterfaceProxyWithTarget<TInterface>(cached,
loggingInterceptor.ToInterceptor());
});
return services;
}
public static IServiceCollection AddLoggedAuditedCachedServiceScoped<TInterface, TImplementation, TCacheDecorator>(this IServiceCollection services)
where TInterface : class
where TImplementation : class, TInterface
where TCacheDecorator : class, TInterface
{
services.AddScoped<TImplementation>();
services.AddScoped<TCacheDecorator>();
services.AddScoped(sp =>
{
var proxyGenerator = sp.GetRequiredService<ProxyGenerator>();
var auditInterceptor = sp.GetRequiredService<AuditInterceptor>();
var loggingInterceptor = sp.GetRequiredService<LoggingInterceptor>();
var actual = sp.GetRequiredService<TImplementation>();
var cached = ActivatorUtilities.CreateInstance<TCacheDecorator>(sp, actual);
return proxyGenerator.CreateInterfaceProxyWithTarget<TInterface>(cached,
loggingInterceptor.ToInterceptor(),
auditInterceptor.ToInterceptor());
});
return services;
}
public static IServiceCollection AddRegisterServicesWithCaching(this IServiceCollection services, IConfiguration configuration)
{
services.AddScoped<AuditInterceptor>();