private void SetAccountUserName(FederationSettings registration, IEnvironment env)
        {
            EnsureEnvironmentParameter(env, "ServiceAccountName", registration.DelegationUserName, false);

        }
 private void EnsureAccountCredentials(FederationSettings registration, IEnvironment env)
 {
     SetAccountUserName(registration, env);
     SetAccountPassword(registration, env);
 }
 private void SetAccountPassword(FederationSettings registration, IEnvironment env)
 {
     EnsureEnvironmentParameter(env, "ServiceAccountPassword", registration.DelegationPassword, true);
 }
 private void EnsureSubstitutionParameters(FederationSettings registration, IEnvironment env)
 {
     var val = registration.FederationServerUrl;
     EnsureAccountCredentials(registration, env);
     EnsureSubstitutionParameter(env, "IssuerActAsAddress", val);
     EnsureSubstitutionParameter(env, "IssuerAddress", val);
     EnsureSubstitutionParameter(env, "IssuerMetadataAddress", val);
     val = registration.FederationNamespace;
     EnsureSubstitutionParameter(env, "IssuerName", val);
     val = registration.PassiveFederationEndpoint;
     EnsureSubstitutionParameter(env, "StsAddress", val);
     val = registration.Thumbprint;
     EnsureSubstitutionParameter(env, "Thumbprint", val);
     val = registration.WebApplicationUrl;
     if (!val.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) val = "https://" + val;
     EnsureSubstitutionParameter(env, "Realm", val);
     EnsureSubstitutionParameter(env, "Audience", "{0}");
     EnsureSubstitutionParameter(env, "CertificateValidationMode", "None");
     EnsureSubstitutionParameter(env, "EnforceCertificateValidation", "false");
     EnsureSubstitutionParameter(env, "RequireHttps", "false");
 }
 private void SetServiceHostAddresses(FederationSettings registration, IEnvironment env)
 {
     if (registration.ServiceHostRootUrl.IsNull())
     {
         return;
     }
     foreach (var sh in registration.ServiceHostRootUrl)
     {
         EnsureSubstitutionParameter(env, string.Format("{0}_Address", sh.Key), sh.Value);
     }
 }
 private void UpdateOtherSettings(FederationSettings registration, IEnvironment env)
 {
     foreach (var serviceHostSettings in registration.OtherSettings)
     {
         var serviceHost = env.ConfigSet.ServiceHosts.SingleOrDefault(sh => sh.Name == serviceHostSettings.Key);
         foreach (var item in serviceHostSettings.Value)
         {
             var shParam = serviceHost.Parameters.SingleOrDefault(p => p.Name == item.Key);
             if (shParam.IsNull()) shParam = serviceHost.CreateParameter(Repository, item.Key, false, true);
             if (shParam.Value != item.Value) shParam.ItemValue = "{0}";
             var envParam = env.SubstitutionParameters.SingleOrDefault(p => p.Name == string.Format("{0}_{1}", serviceHost.Name, shParam.Name));
             if (envParam.IsNull())
                 envParam = env.CreateSubstitutionParameters(Repository, string.Format("{0}_{1}", serviceHost.Name, shParam.Name));
             if (envParam.Value != item.Value) envParam.ItemValue = item.Value;
             Repository.SaveChanges();
         }
     }
 }
 private IEnvironment EnsureEnvironment(string id, FederationSettings registration)
 {
     var configSet = GetConfigsetInternal(id);
     var env = configSet.Environments.SingleOrDefault(e => e.Name == registration.Environment);
     if (env.IsNull())
     {
         env = configSet.CreateEnvironment(Repository, registration.Environment);
         Repository.SaveChanges();
     }
     return env;
 }
 public void ConfigureEnvironment(string id, FederationSettings registration)
 {
     var env = EnsureEnvironment(id, registration);
     EnsureSubstitutionParameters(registration, env);
     SetServiceHostAddresses(registration, env);
     UpdateOtherSettings(registration, env);
 }