Some checks failed
Build Test Deploy / docs (push) Has been cancelled
Build Test Deploy / deploy (push) Has been cancelled
Build Test Deploy / build-test (push) Has been cancelled
Build Test Deploy / authority-container (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
95 lines
3.8 KiB
C#
95 lines
3.8 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using MongoDB.Driver;
|
|
using StellaOps.Authority.Plugins.Abstractions;
|
|
using StellaOps.Authority.Plugin.Standard.Bootstrap;
|
|
using StellaOps.Authority.Plugin.Standard.Security;
|
|
using StellaOps.Authority.Plugin.Standard.Storage;
|
|
using StellaOps.Authority.Storage.Mongo.Stores;
|
|
using StellaOps.Cryptography;
|
|
using StellaOps.Cryptography.DependencyInjection;
|
|
|
|
namespace StellaOps.Authority.Plugin.Standard;
|
|
|
|
internal sealed class StandardPluginRegistrar : IAuthorityPluginRegistrar
|
|
{
|
|
public string PluginType => "standard";
|
|
|
|
public void Register(AuthorityPluginRegistrationContext context)
|
|
{
|
|
if (context is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(context));
|
|
}
|
|
|
|
var pluginName = context.Plugin.Manifest.Name;
|
|
|
|
context.Services.AddSingleton<StandardClaimsEnricher>();
|
|
context.Services.AddSingleton<IClaimsEnricher>(sp => sp.GetRequiredService<StandardClaimsEnricher>());
|
|
|
|
context.Services.AddStellaOpsCrypto();
|
|
|
|
var configPath = context.Plugin.Manifest.ConfigPath;
|
|
|
|
context.Services.AddOptions<StandardPluginOptions>(pluginName)
|
|
.Bind(context.Plugin.Configuration)
|
|
.PostConfigure(options =>
|
|
{
|
|
options.Normalize(configPath);
|
|
options.Validate(pluginName);
|
|
})
|
|
.ValidateOnStart();
|
|
|
|
context.Services.AddSingleton(sp =>
|
|
{
|
|
var database = sp.GetRequiredService<IMongoDatabase>();
|
|
var optionsMonitor = sp.GetRequiredService<IOptionsMonitor<StandardPluginOptions>>();
|
|
var pluginOptions = optionsMonitor.Get(pluginName);
|
|
var cryptoProvider = sp.GetRequiredService<ICryptoProvider>();
|
|
var passwordHasher = new CryptoPasswordHasher(pluginOptions, cryptoProvider);
|
|
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
|
|
|
|
return new StandardUserCredentialStore(
|
|
pluginName,
|
|
database,
|
|
pluginOptions,
|
|
passwordHasher,
|
|
loggerFactory.CreateLogger<StandardUserCredentialStore>());
|
|
});
|
|
|
|
context.Services.AddSingleton(sp =>
|
|
{
|
|
var clientStore = sp.GetRequiredService<IAuthorityClientStore>();
|
|
var revocationStore = sp.GetRequiredService<IAuthorityRevocationStore>();
|
|
var timeProvider = sp.GetRequiredService<TimeProvider>();
|
|
return new StandardClientProvisioningStore(pluginName, clientStore, revocationStore, timeProvider);
|
|
});
|
|
|
|
context.Services.AddSingleton<IIdentityProviderPlugin>(sp =>
|
|
{
|
|
var store = sp.GetRequiredService<StandardUserCredentialStore>();
|
|
var clientProvisioningStore = sp.GetRequiredService<StandardClientProvisioningStore>();
|
|
var loggerFactory = sp.GetRequiredService<ILoggerFactory>();
|
|
return new StandardIdentityProviderPlugin(
|
|
context.Plugin,
|
|
store,
|
|
clientProvisioningStore,
|
|
sp.GetRequiredService<StandardClaimsEnricher>(),
|
|
loggerFactory.CreateLogger<StandardIdentityProviderPlugin>());
|
|
});
|
|
|
|
context.Services.AddSingleton<IClientProvisioningStore>(sp =>
|
|
sp.GetRequiredService<StandardClientProvisioningStore>());
|
|
|
|
context.Services.AddSingleton<IHostedService>(sp =>
|
|
new StandardPluginBootstrapper(
|
|
pluginName,
|
|
sp.GetRequiredService<IOptionsMonitor<StandardPluginOptions>>(),
|
|
sp.GetRequiredService<StandardUserCredentialStore>(),
|
|
sp.GetRequiredService<ILogger<StandardPluginBootstrapper>>()));
|
|
}
|
|
}
|