internal HttpStream(Uri dataSourceUri, bool acceptCompressedResponses, DataType desiredRequestType, DataType desiredResponseType, CookieContainer cookieContainer, int timeoutMs, ConnectionInfo connectionInfo) : base(desiredRequestType, desiredResponseType) { try { this.webSite = dataSourceUri; this.hasASAzureHeaders = false; this.connectionInfo = connectionInfo; if (connectionInfo.IsInternalASAzure) { this.hasASAzureHeaders = true; } if (connectionInfo.IsAsAzure) { this.aadTokenHolder = connectionInfo.AadTokenHolder; this.xmlaServerHeader = connectionInfo.AsAzureServerName; this.hasASAzureHeaders = true; } else if (connectionInfo.IntegratedSecurity == IntegratedSecurity.Federated) { if (string.IsNullOrEmpty(connectionInfo.IdentityProvider) || string.Compare(connectionInfo.IdentityProvider, "MsoID", CultureInfo.InvariantCulture, CompareOptions.OrdinalIgnoreCase) != 0) { throw new NotSupportedException(XmlaSR.ConnectionString_InvalidIdentityProviderForIntegratedSecurityFederated); } this.authorizationHeader = "MsoID " + MsoIDAuthenticationProvider.Instance.Authenticate(connectionInfo.UserID, connectionInfo.Password); } else if (connectionInfo.UserID == null) { this.logonWindowsIdentity = WindowsIdentity.GetCurrent(); this.credentials = CredentialCache.DefaultCredentials; this.connectionSecureGroupName = this.logonWindowsIdentity.User.ToString(); } else { this.credentials = new NetworkCredential(connectionInfo.UserID, connectionInfo.Password); SHA1Managed sHA1Managed = new SHA1Managed(); byte[] bytes = sHA1Managed.ComputeHash(Encoding.UTF8.GetBytes(connectionInfo.Password)); this.connectionSecureGroupName = connectionInfo.UserID.Replace(";", ";;") + ";:" + Encoding.Default.GetString(bytes).Replace(";", ";;"); } if (!string.IsNullOrEmpty(connectionInfo.ClientCertificateThumbprint)) { this.clientCertificate = CertUtils.LoadCertificateByThumbprint(connectionInfo.ClientCertificateThumbprint, true); } this.acceptCompressedResponses = acceptCompressedResponses; this.applicationName = connectionInfo.ApplicationName; this.cookieContainer = cookieContainer; this.timeoutMs = timeoutMs; this.routingTokenAccessor = new HttpStream.RoutingTokenAccessor(connectionInfo); this.allowAutoRedirect = connectionInfo.AllowAutoRedirect; } catch (UriFormatException innerException) { throw new XmlaStreamException(innerException); } }
private void InitializeCredentialsHandle(ConnectionInfo connectionInfo) { string sspi = connectionInfo.Sspi; if (connectionInfo.ImpersonationLevel == ImpersonationLevel.Anonymous) { if (this.m_isSchannel) { if (string.IsNullOrEmpty(connectionInfo.Certificate)) { this.m_CredentialsHandle = new CredentialsContext(null); return; } throw new AdomdConnectionException(XmlaSR.Authentication_Sspi_SchannelAnonymousAmbiguity, null, ConnectionExceptionCause.AuthenticationFailed); } else { IntPtr currentThread = UnsafeNclNativeMethods.GetCurrentThread(); if (!UnsafeNclNativeMethods.ImpersonateAnonymousToken(currentThread)) { uint lastError = UnsafeNclNativeMethods.GetLastError(); throw new Win32Exception((int)lastError); } try { this.m_CredentialsHandle = new CredentialsContext(sspi, CredentialUse.Outgoing); return; } finally { if (!UnsafeNclNativeMethods.RevertToSelf()) { Process.GetCurrentProcess().Kill(); } } } } if (this.m_isSchannel) { string certificate = connectionInfo.Certificate; if (string.IsNullOrEmpty(certificate)) { this.m_CredentialsHandle = new CredentialsContext(null); return; } this.m_CredentialsHandle = new CredentialsContext(CertUtils.LoadCertificateByThumbprint(certificate, true)); return; } else { this.m_CredentialsHandle = new CredentialsContext(sspi, CredentialUse.Outgoing); } }