ComponentSpace

Forums



Dynamically adding configurations after startup


Dynamically adding configurations after startup

Author
Message
Florin Cumpanasu
Florin Cumpanasu
New Member
New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)

Group: Forum Members
Posts: 2, Visits: 8
Hi all,

My question is also posted on StackOverflow: https://stackoverflow.com/questions/57972901/somponentspace-saml

I need to add provider configurations from database after startup. 
There is no useful documentation on this topic. 
Here are few suggestions I found and tried with no success.

A post on their forum is suggesting to inject ComponentSpace.Saml2.Configuration.SamlConfigurations in my controller. The problem is that SamlConfigurations is null althow I already have working configurations loaded at startup.https://componentspace.com/Forums/7950/
I can access the database as early as in app Configure from Startup.cs. But the saml has already been added in ConfigureServices using services.AddSaml, and there is no obvious way to update this.

Kind regards!
Florin
ComponentSpace
ComponentSpace
ComponentSpace Development
ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)

Group: Administrators
Posts: 3.2K, Visits: 11K
Hi Florin,

The recommended approach is to implement the ISamlConfigurationResolver interface as described in the Configuration Guide.
https://www.componentspace.com/Forums/8234/Configuration-Guide

The section "SAML Configuration Options" outlines the alternatives and recommendations for when to use each approach.

The section "Implementing ISamlConfigurationResolver" describes this interface and includes a couple of example implementations.
You would store your SAML configuration in a custom database. Your implementation of ISamlConfigurationResolver would retrieve information from this database as requested. Configuration is requested on demand as part of a SAML SSO or SLO flow.

Note that the current version of the documentation suggests using services.TryAddScoped to specify your implementation. This requires you to do this prior to calling services.AddSaml otherwise the default ISamlConfigurationResolver implementation that reads from appsettings.json is still active. A better approach is to call services.AddScoped<ISamlConfigurationResolver, YourSamlConfigurationResolver>();

Regarding the approach you tried, you can specify the SamlConfigurations programmatically. If you take a look at the ExampleIdentityProvider and ExampleServiceProvider projects we ship, their Startup classes include a ConfigureSaml method. Instead of calling services.AddSaml(Configuration.GetSection("SAML")), which adds the SAML configuration from the appsettinsg.json, you would call services.AddSaml(config => ConfigureSaml(config)).

However, I think for your scenario it's better to implement ISamlConfigurationResolver.

Regards
ComponentSpace Development
Florin Cumpanasu
Florin Cumpanasu
New Member
New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)New Member (3 reputation)

Group: Forum Members
Posts: 2, Visits: 8
ComponentSpace - 9/17/2019
Hi Florin,

The recommended approach is to implement the ISamlConfigurationResolver interface as described in the Configuration Guide.
https://www.componentspace.com/Forums/8234/Configuration-Guide

The section "SAML Configuration Options" outlines the alternatives and recommendations for when to use each approach.

The section "Implementing ISamlConfigurationResolver" describes this interface and includes a couple of example implementations.
You would store your SAML configuration in a custom database. Your implementation of ISamlConfigurationResolver would retrieve information from this database as requested. Configuration is requested on demand as part of a SAML SSO or SLO flow.

Note that the current version of the documentation suggests using services.TryAddScoped to specify your implementation. This requires you to do this prior to calling services.AddSaml otherwise the default ISamlConfigurationResolver implementation that reads from appsettings.json is still active. A better approach is to call services.AddScoped<ISamlConfigurationResolver, YourSamlConfigurationResolver>();

Regarding the approach you tried, you can specify the SamlConfigurations programmatically. If you take a look at the ExampleIdentityProvider and ExampleServiceProvider projects we ship, their Startup classes include a ConfigureSaml method. Instead of calling services.AddSaml(Configuration.GetSection("SAML")), which adds the SAML configuration from the appsettinsg.json, you would call services.AddSaml(config => ConfigureSaml(config)).

However, I think for your scenario it's better to implement ISamlConfigurationResolver.

Hi all,

I was using "Programmatically Specifying Configuration" and I notice that the configurations are recreated for every login with AD FS request.
Can you tell me if this is exected and if I can avoid reloading configurations once the service is started?

Beste regards!
ComponentSpace
ComponentSpace
ComponentSpace Development
ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)ComponentSpace Development (4.4K reputation)

Group: Administrators
Posts: 3.2K, Visits: 11K
I'm not sure what you mean. The "Programmatically Specifying Configuration" section of the Configuration Guide explains how to specify the SAML configuration once at application startup with services.AddSaml is called. The configuration is not reloaded or recreated.


Regards
ComponentSpace Development
GO


Similar Topics


Execution: 0.000. 2 queries. Compression Enabled.
Login
Existing Account
Email Address:


Password:


Select a Forum....












Forums, Documentation & Knowledge Base - ComponentSpace


Search