/// <summary>Updates the sso options.</summary> public void UpdateSSOOptions(SSOOptionsDTO options) { if (options == null) throw new ArgumentNullException("options"); const string sql = @" IF EXISTS (SELECT * FROM dbo.SSOOptions so) BEGIN IF (LEN(@IDPCertificate) > 0) UPDATE dbo.SSOOptions SET IsEnabled = @isEnabled, AllowSSOApproval = @allowSSOApproval, SAMLVersion = @SAMLVersion, Issuer = @issuer, IdPTargetUrl = @IdPTargetUrl, IdPLogoutUrl = @IdPLogoutUrl, IDPCertificate = @IDPCertificate ELSE UPDATE dbo.SSOOptions SET IsEnabled = @isEnabled, AllowSSOApproval = @allowSSOApproval, SAMLVersion = @SAMLVersion, Issuer = @issuer, IdPTargetUrl = @IdPTargetUrl, IdPLogoutUrl = @IdPLogoutUrl END ELSE BEGIN INSERT dbo.SSOOptions ( IsEnabled, AllowSSOApproval, SAMLVersion, Issuer, IdPTargetUrl, IdPLogoutUrl, IdPCertificate ) VALUES ( @isEnabled, @allowSSOApproval, @SAMLVersion, @issuer, @IdPTargetUrl, @IdPLogoutUrl, @IdPCertificate ) END "; using (var cmd = new SqlCommand(sql)) { cmd.Parameters.AddWithValue("@IsEnabled", options.IsEnabled); cmd.Parameters.AddWithValue("@allowSSOApproval", options.AllowSSOApproval); cmd.Parameters.AddWithValue("@SAMLVersion", options.SAMLVersion); cmd.Parameters.AddWithValue("@issuer", options.Issuer); cmd.Parameters.AddWithValue("@IdPTargetUrl", options.IdPTargetUrl); cmd.Parameters.AddWithValue("@IdPLogoutUrl", options.IdPLogoutUrl); cmd.Parameters.AddWithValue("@IdPCertificate", options.Certificate); Database.Execute(cmd); } }
/// <summary>Fetches the sso options for Control Panel.</summary> public SSOOptionsDTO FetchSSOOptionsChild() { const string sql = @" SELECT TOP 1 IsEnabled, AllowSSOApproval, SAMLVersion, Issuer, IdPTargetUrl, IdPLogoutUrl, CASE LEN(sso.IDPCertificate) WHEN 0 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END AS HasNoSSOCertificate FROM dbo.SSOOptions ORDER BY Id DESC"; SSOOptionsDTO dto = null; Database.GetDataReader( sql, reader => { if (reader == null) throw new DataAccessException(Resources.FailedToRetrieveSystemOptions); if (reader.Read()) { dto = new SSOOptionsDTO { IsEnabled = reader.GetBoolean(0), AllowSSOApproval = reader.GetBoolean(1), SAMLVersion = reader.GetString(2), Issuer = reader.GetString(3), IdPTargetUrl = reader.GetString(4), IdPLogoutUrl = reader.GetString(5), HasNoCertificate = reader.GetBoolean(6) }; } }); return dto; }