public ActionResult Edit()
        {
            var context = new Context();

            if (!Request.IsAjaxRequest())
            {
                var log  = new SysLogModel(context: context);
                var html = TenantUtilities.Editor(
                    context: context,
                    ss: SiteSettingsUtilities.TenantsSiteSettings(context: context),
                    tenantId: context.TenantId,
                    clearSessions: true);
                ViewBag.HtmlBody = html;
                log.Finish(context: context, responseSize: html.Length);
                return(View());
            }
            else
            {
                var log  = new SysLogModel(context: context);
                var json = TenantUtilities.EditorJson(
                    context: context,
                    ss: SiteSettingsUtilities.TenantsSiteSettings(context: context),
                    tenantId: context.TenantId);
                log.Finish(context: context, responseSize: json.Length);
                return(Content(json));
            }
        }
        public string Update(Context context)
        {
            var log  = new SysLogModel(context: context);
            var json = TenantUtilities.Update(
                context: context,
                ss: SiteSettingsUtilities.TenantsSiteSettings(context: context),
                tenantId: context.TenantId);

            log.Finish(context: context, responseSize: json.Length);
            return(json);
        }
 public string Edit(Context context)
 {
     if (!context.Ajax)
     {
         var log  = new SysLogModel(context: context);
         var html = TenantUtilities.Editor(
             context: context,
             ss: SiteSettingsUtilities.TenantsSiteSettings(context: context),
             tenantId: context.TenantId,
             clearSessions: true);
         log.Finish(context: context, responseSize: html.Length);
         return(html);
     }
     else
     {
         var log  = new SysLogModel(context: context);
         var json = TenantUtilities.EditorJson(
             context: context,
             ss: SiteSettingsUtilities.TenantsSiteSettings(context: context),
             tenantId: context.TenantId);
         log.Finish(context: context, responseSize: json.Length);
         return(json);
     }
 }
Ejemplo n.º 4
0
        public static string SetIdpConfiguration(Context context, int tenantId, bool startup = false)
        {
            var contractSettings = TenantUtilities.GetContractSettings(context, tenantId);

            if (contractSettings == null ||
                contractSettings.SamlCompanyCode.IsNullOrEmpty() ||
                contractSettings.SamlLoginUrl.IsNullOrEmpty() ||
                contractSettings.SamlThumbprint.IsNullOrEmpty())
            {
                return(null);
            }
            if (!FindCert(context, contractSettings.SamlThumbprint))
            {
                return(null);
            }
            try
            {
                var section  = (SustainsysSaml2Section)ConfigurationManager.GetSection("sustainsys.saml2");
                var loginUrl = contractSettings.SamlLoginUrl;
                var idp      = loginUrl.TrimEnd(new[] { '/' }).Substring(0, loginUrl.LastIndexOf('/') + 1);
                if (processing)
                {
                    System.Threading.Thread.Sleep(300);
                }
                if (processing == false)
                {
                    processing = true;
                    try
                    {
                        IdentityProviderElement newProvider = null;
                        CertificateElement      newCert     = null;
                        var provider = section.IdentityProviders.FirstOrDefault(p => p.EntityId == idp);
                        if (provider != null)
                        {
                            string signOnUrl = provider.SignOnUrl.ToString();
                            string findValue = provider.SigningCertificate.FindValue;
                            if (signOnUrl == contractSettings.SamlLoginUrl &&
                                findValue == contractSettings.SamlThumbprint)
                            {
                                return($"~/Saml2/SignIn?idp={idp}");
                            }
                            else
                            {
                                newProvider = provider;
                                newCert     = provider.SigningCertificate;
                                WriteIdPSettings(contractSettings?.SamlLoginUrl, contractSettings?.SamlThumbprint, idp, newProvider, newCert);
                                try
                                {
                                    var spOptions = new SPOptions(SustainsysSaml2Section.Current);
                                    var options   = new Options(spOptions);
                                    SustainsysSaml2Section.Current.IdentityProviders.RegisterIdentityProviders(options);
                                    SustainsysSaml2Section.Current.Federations.RegisterFederations(options);
                                    var optionsFromConfiguration = typeof(Options).GetField("optionsFromConfiguration",
                                                                                            System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
                                    optionsFromConfiguration.SetValue(null, new Lazy <Options>(() => options, true));
                                    Sustainsys.Saml2.Mvc.Saml2Controller.Options = Options.FromConfiguration;
                                }
                                catch
                                {
                                    WriteIdPSettings(signOnUrl, findValue, idp, newProvider, newCert);
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            newProvider = new IdentityProviderElement();
                            newCert     = new CertificateElement();
                            WriteIdPSettings(contractSettings?.SamlLoginUrl, contractSettings?.SamlThumbprint, idp, newProvider, newCert);
                            AddIdP(section, newProvider);
                            if (startup == false)
                            {
                                var spOptions = new SPOptions(SustainsysSaml2Section.Current);
                                var options   = new Options(spOptions);
                                SustainsysSaml2Section.Current.IdentityProviders.RegisterIdentityProviders(options);
                                SustainsysSaml2Section.Current.Federations.RegisterFederations(options);
                                var optionsFromConfiguration = typeof(Options).GetField("optionsFromConfiguration",
                                                                                        System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
                                optionsFromConfiguration.SetValue(null, new Lazy <Options>(() => options, true));
                                Sustainsys.Saml2.Mvc.Saml2Controller.Options = Options.FromConfiguration;
                            }
                        }
                    }
                    finally
                    {
                        processing = false;
                    }
                }
                return($"~/Saml2/SignIn?idp={idp}");
            }
            catch (System.Exception e)
            {
                new SysLogModel(context, e);
                return(null);
            }
        }