private void CreateLinkedReport(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode , HttpClientCredentialType ReportHttpClientCredentialType , string ReportFolder, string ReportName , string LinkedReportPath , ReportingService2010.Property[] LinkedReportProperties , XElement xLinkedReportParameters //, string ParameterLanguage ) { string serviceUrl; string execUrl; BasicHttpBinding basicHttpBinding; ConfigureReportServerBinding(ReportServerPath, ReportMode, ReportHttpClientCredentialType, out serviceUrl, out execUrl, out basicHttpBinding); using (ReportingService2010.ReportingService2010SoapClient rsService = new ReportingService2010.ReportingService2010SoapClient(basicHttpBinding, new EndpointAddress(serviceUrl))) { ReportingService2010.TrustedUserHeader trusteduserHeader; ReportExecution2005.TrustedUserHeader userHeader; GetHeaders(UserName, UserPassword, rsService, null, out trusteduserHeader, out userHeader); ReportingService2010.SearchCondition condition = new ReportingService2010.SearchCondition(); condition.Condition = ReportingService2010.ConditionEnum.Equals; condition.ConditionSpecified = true; condition.Name = "Name"; ReportingService2010.SearchCondition[] conditions = new ReportingService2010.SearchCondition[1]; conditions[0] = condition; ReportingService2010.CatalogItem[] foundItems = null; condition.Values = new string[] { ReportName.TrimStart('/').TrimEnd('/') }; rsService.FindItems(trusteduserHeader , "/" + ReportFolder.TrimStart('/').TrimEnd('/') , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundItems); if (foundItems != null && foundItems.Count() > 0) { foreach (var item in foundItems) { if (item.Path == "/" + ReportFolder.TrimStart('/').TrimEnd('/') + "/" + ReportName) { string parentReportPath = item.Path; try { string linkedReportName = LinkedReportPath.Substring(LinkedReportPath.LastIndexOf('/') + 1).TrimStart('/').TrimEnd('/'); string linkedReportFolderPath = LinkedReportPath.Substring(0, LinkedReportPath.LastIndexOf('/')).TrimEnd('/'); CheckLinkedFolderExists(rsService, trusteduserHeader, condition, conditions, linkedReportFolderPath); ReportingService2010.CatalogItem[] foundLinkedItems = null; condition.Values = new string[] { linkedReportName }; rsService.FindItems(trusteduserHeader , linkedReportFolderPath , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundLinkedItems); if (foundLinkedItems == null || (foundLinkedItems != null && foundLinkedItems.Count() == 0)) { rsService.CreateLinkedItem(trusteduserHeader , linkedReportName , linkedReportFolderPath , parentReportPath , LinkedReportProperties); } if (xLinkedReportParameters != null) { //// List of properties to copy from parent to linked reports. ??? //var requestedProperties = new ReportingService2010.Property[] { // new ReportingService2010.Property { Name = "PageHeight" }, // new ReportingService2010.Property { Name = "PageWidth" }, // new ReportingService2010.Property { Name = "TopMargin" }, // new ReportingService2010.Property { Name = "BottomMargin" }, // new ReportingService2010.Property { Name = "LeftMargin" }, // new ReportingService2010.Property { Name = "RightMargin" } //}; IEnumerable<XElement> linkedReportParams = xLinkedReportParameters.Descendants("Param"); if (linkedReportParams.Count() > 0) { List<ReportingService2010.ItemParameter> ItemParamsList = new List<ReportingService2010.ItemParameter>(); foreach (var linkedReportParam in linkedReportParams) { string defaultValues = linkedReportParam.Attribute("DefaultValues").Value; if (!string.IsNullOrEmpty(defaultValues)) { ReportingService2010.ItemParameter[] parentReportParams = null; rsService.GetItemParameters(trusteduserHeader , parentReportPath , null , false, null, null, out parentReportParams); bool paramExists = false; ReportingService2010.ItemParameter ip = new ReportingService2010.ItemParameter(); ip.Name = linkedReportParam.Attribute("Name").Value; foreach (var parentReportParam in parentReportParams) { if (parentReportParam.Name == ip.Name) { ip.AllowBlank = parentReportParam.AllowBlank; ip.MultiValue = parentReportParam.MultiValue; ip.Nullable = parentReportParam.Nullable; ip.Prompt = parentReportParam.Prompt; ip.PromptUser = parentReportParam.PromptUser; ip.PromptUserSpecified = parentReportParam.PromptUserSpecified; paramExists = true; break; } } if (paramExists) { ip.DefaultValues = defaultValues.Split(','); if (linkedReportParam.Attribute("Hide") != null && linkedReportParam.Attribute("Hide").Value.ToLower() == "true") { //hide the paramerter using combination of parameters. There is no Hide property which reflects UI Hide checkbox ip.PromptUser = false; ip.PromptUserSpecified = false; ip.Prompt = null; } ItemParamsList.Add(ip); } } } rsService.SetItemParameters(trusteduserHeader, LinkedReportPath, ItemParamsList.ToArray()); } } } catch (SoapException ex) { LogMessage("Not able to create linked report " + LinkedReportPath + " Error: " + ex.Message); throw; } break; } } } } }
private void GetReportData(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, ReportExecution2005.ParameterValue[] Parameters, string ParameterLanguage, string RenderFormat, out byte[] bytes) { bytes = null; string serviceUrl; string execUrl; BasicHttpBinding basicHttpBinding; ConfigureReportServerBinding(ReportServerPath, ReportMode, ReportHttpClientCredentialType, out serviceUrl, out execUrl, out basicHttpBinding); using (ReportingService2010.ReportingService2010SoapClient rsService = new ReportingService2010.ReportingService2010SoapClient(basicHttpBinding, new EndpointAddress(serviceUrl))) using (ReportExecution2005.ReportExecutionServiceSoapClient rsExec = new ReportExecution2005.ReportExecutionServiceSoapClient(basicHttpBinding, new EndpointAddress(execUrl))) { ReportingService2010.TrustedUserHeader trusteduserHeader; ReportExecution2005.TrustedUserHeader userHeader; GetHeaders(UserName, UserPassword, rsService, rsExec, out trusteduserHeader, out userHeader); ReportingService2010.SearchCondition condition = new ReportingService2010.SearchCondition(); condition.Condition = ReportingService2010.ConditionEnum.Equals; condition.ConditionSpecified = true; condition.Name = "Name"; ReportingService2010.SearchCondition[] conditions = new ReportingService2010.SearchCondition[1]; conditions[0] = condition; ReportingService2010.CatalogItem[] foundItems = null; condition.Values = new string[] { ReportName }; rsService.FindItems(trusteduserHeader , "/" + ReportFolder.TrimStart('/').TrimEnd('/') , ReportingService2010.BooleanOperatorEnum.And , new ReportingService2010.Property[0] , conditions , out foundItems); if (foundItems != null && foundItems.Count() > 0) { foreach (var item in foundItems) { if (item.Path == "/" + ReportFolder.TrimStart('/').TrimEnd('/') + "/" + ReportName) { ///Exporting to XML is not supported in SQL Server Express ///http://msdn.microsoft.com/en-us/library/cc645993.aspx string format = RenderFormat.ToUpper(); string historyID = null; string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; string encoding; string mimeType; string extension; string[] streamIDs = null; ReportExecution2005.Warning[] warnings = null; ReportExecution2005.ServerInfoHeader execServerHeader = new ReportExecution2005.ServerInfoHeader(); ReportExecution2005.ExecutionInfo execInfo = new ReportExecution2005.ExecutionInfo(); rsExec.LoadReport(userHeader, item.Path, historyID, out execServerHeader, out execInfo); ReportExecution2005.ExecutionHeader execHeader = new ReportExecution2005.ExecutionHeader(); execHeader.ExecutionID = execInfo.ExecutionID; rsExec.SetExecutionParameters(execHeader, userHeader, Parameters, ParameterLanguage, out execInfo); execServerHeader = rsExec.Render(execHeader, userHeader, format, devInfo, out bytes, out extension, out mimeType, out encoding, out warnings, out streamIDs); break; } } } } }
public HttpTransportSecurity() { this.clientCredentialType = DefaultClientCredentialType; this.proxyCredentialType = DefaultProxyCredentialType; this.realm = DefaultRealm; this.extendedProtectionPolicy = ChannelBindingUtility.DefaultPolicy; }
public UserNameWSTrustBinding(SecurityMode securityMode) : base(securityMode) { if (SecurityMode.Message == securityMode) { _clientCredentialType = HttpClientCredentialType.None; } }
/// <summary> /// Constructor /// </summary> /// <param name="securityMode"></param> public CertificateWSTrustBinding(SecurityMode securityMode) : base(securityMode) { if (SecurityMode.Message == securityMode) { _clientCredentialType = HttpClientCredentialType.None; } }
public UserNameWSTrustBinding(SecurityMode securityMode) : base(securityMode) { if (SecurityMode.Message == securityMode) { this._clientCredentialType = HttpClientCredentialType.None; } }
public static HttpClientCredentialType ClientCredentialTypeFromAuthenticationScheme(AuthenticationSchemes oneAuthScheme) { const HttpClientCredentialType none = HttpClientCredentialType.None; switch (oneAuthScheme) { case AuthenticationSchemes.Digest: return(HttpClientCredentialType.Digest); case AuthenticationSchemes.Negotiate: case AuthenticationSchemes.IntegratedWindowsAuthentication: return(HttpClientCredentialType.Windows); case (AuthenticationSchemes.Negotiate | AuthenticationSchemes.Digest): case (AuthenticationSchemes.Ntlm | AuthenticationSchemes.Digest): case (AuthenticationSchemes.IntegratedWindowsAuthentication | AuthenticationSchemes.Digest): return(none); case AuthenticationSchemes.Ntlm: return(HttpClientCredentialType.Ntlm); case AuthenticationSchemes.Basic: return(HttpClientCredentialType.Basic); case AuthenticationSchemes.Anonymous: return(HttpClientCredentialType.None); } return(none); }
internal static AuthenticationSchemes MapToAuthenticationScheme( HttpClientCredentialType clientCredentialType ) { switch (clientCredentialType) { case HttpClientCredentialType.None: case HttpClientCredentialType.Certificate: return(AuthenticationSchemes.Anonymous); case HttpClientCredentialType.Basic: return(AuthenticationSchemes.Basic); case HttpClientCredentialType.Digest: return(AuthenticationSchemes.Digest); case HttpClientCredentialType.Ntlm: return(AuthenticationSchemes.Ntlm); case HttpClientCredentialType.Windows: return(AuthenticationSchemes.Negotiate); } Contract.Assert(false, "Invalid clientCredentialType " + clientCredentialType); return(AuthenticationSchemes.Anonymous); }
internal static AuthenticationSchemes MapToAuthenticationScheme(HttpClientCredentialType clientCredentialType) { AuthenticationSchemes result; switch (clientCredentialType) { case HttpClientCredentialType.Certificate: // fall through to None case case HttpClientCredentialType.None: result = AuthenticationSchemes.Anonymous; break; case HttpClientCredentialType.Basic: result = AuthenticationSchemes.Basic; break; case HttpClientCredentialType.Digest: result = AuthenticationSchemes.Digest; break; case HttpClientCredentialType.Ntlm: result = AuthenticationSchemes.Ntlm; break; case HttpClientCredentialType.Windows: result = AuthenticationSchemes.Negotiate; break; case HttpClientCredentialType.InheritedFromHost: result = AuthenticationSchemes.None; break; default: Fx.Assert("unsupported client credential type"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } return result; }
protected void InitializeAllDefaultSettings <R, I, D>( bool startRestWebService, WcfRestWebServiceAppSettings settings, WebHttpSecurityMode webHttpSecurityMode, HttpClientCredentialType httpClientCredentialType, UserNamePasswordValidator userNamePasswordValidator, Type userLinqToSqlType, Type serverActionLinqToSqlType, Type serverErrorLinqToSqlType, bool logSettings, out string restWebServiceUrl, out string restWebServiceStartedLogMessage) where R : WcfRestServiceWindows where I : IWcfRestServiceWindows where D : DataContext { base.InitializeAllDefaultSettings( settings, logSettings); base.InitializeDatabaseSettings <D>( settings, userLinqToSqlType, serverActionLinqToSqlType, serverErrorLinqToSqlType); InitializeRestWebServiceServiceHost <R, I>( startRestWebService, settings, webHttpSecurityMode, httpClientCredentialType, userNamePasswordValidator, out restWebServiceUrl, out restWebServiceStartedLogMessage); }
private XmlRpcHttpSecurity(XmlRpcHttpSecurityMode mode, HttpClientCredentialType clientCredentialType, HttpProxyCredentialType proxyCredentialType, string realm) { this.Mode = mode; this.ClientCredentialType = clientCredentialType; this.ProxyCredentialType = proxyCredentialType; this.Realm = realm; }
protected HttpClientCredentialType GetCredentialMode() { HttpClientCredentialType credentialMode = HttpClientCredentialType.Basic; Enum.TryParse <HttpClientCredentialType>(_config[$"{BASE_WS_CONFIG}:CredentialMode"], out credentialMode); return(credentialMode); }
public HttpTransportSecurity() { _clientCredentialType = DefaultClientCredentialType; _proxyCredentialType = DefaultProxyCredentialType; Realm = DefaultRealm; _extendedProtectionPolicy = ChannelBindingUtility.DefaultPolicy; }
internal static bool IsDefined(HttpClientCredentialType value) { if ((((value != HttpClientCredentialType.None) && (value != HttpClientCredentialType.Basic)) && ((value != HttpClientCredentialType.Digest) && (value != HttpClientCredentialType.Ntlm))) && (value != HttpClientCredentialType.Windows)) { return(value == HttpClientCredentialType.Certificate); } return(true); }
internal static bool IsDefined(HttpClientCredentialType value) { if ((((value != HttpClientCredentialType.None) && (value != HttpClientCredentialType.Basic)) && ((value != HttpClientCredentialType.Digest) && (value != HttpClientCredentialType.Ntlm))) && (value != HttpClientCredentialType.Windows)) { return (value == HttpClientCredentialType.Certificate); } return true; }
internal static bool IsDefined(HttpClientCredentialType value) { return (value == HttpClientCredentialType.None || value == HttpClientCredentialType.Basic || value == HttpClientCredentialType.Digest || value == HttpClientCredentialType.Ntlm || value == HttpClientCredentialType.Windows || value == HttpClientCredentialType.Certificate || value == HttpClientCredentialType.InheritedFromHost); }
internal static bool IsDefined(HttpClientCredentialType value) { return(value == HttpClientCredentialType.None || value == HttpClientCredentialType.Basic || value == HttpClientCredentialType.Digest || value == HttpClientCredentialType.Ntlm || value == HttpClientCredentialType.Windows || value == HttpClientCredentialType.Certificate || value == HttpClientCredentialType.InheritedFromHost); }
private static bool IsHttpClientCredentialTypeDefined(HttpClientCredentialType value) { if (value != HttpClientCredentialType.None && value != HttpClientCredentialType.Basic && value != HttpClientCredentialType.Digest && value != HttpClientCredentialType.Ntlm && value != HttpClientCredentialType.Windows) { return(value == HttpClientCredentialType.Certificate); } return(true); }
public UserNameWSTrustBinding(SecurityMode mode, HttpClientCredentialType clientCredentialType) : base(mode) { if (!IsHttpClientCredentialTypeDefined(clientCredentialType)) { throw new ArgumentOutOfRangeException("clientCredentialType"); } if (((SecurityMode.Transport == mode) && (HttpClientCredentialType.Digest != clientCredentialType)) && (HttpClientCredentialType.Basic != clientCredentialType)) { throw new InvalidOperationException("ID3225"); } this._clientCredentialType = clientCredentialType; }
/// <summary>Perform the actual detection of authentication scheme and credential type in WCF event handler.</summary> protected override void OnOpening() { base.OnOpening(); ServiceEndpoint se = this.Description.Endpoints.FirstOrDefault(); if (se != null) { WebHttpBinding whb = se.Binding as WebHttpBinding; if (whb != null) { this._credentialType = whb.Security.Transport.ClientCredentialType; switch (this._credentialType) { case HttpClientCredentialType.Basic: this._authenticationScheme = AuthenticationSchemes.Basic; break; case HttpClientCredentialType.Digest: this._authenticationScheme = AuthenticationSchemes.Digest; break; case HttpClientCredentialType.Ntlm: this._authenticationScheme = AuthenticationSchemes.Ntlm; break; case HttpClientCredentialType.Windows: this._authenticationScheme = AuthenticationSchemes.Negotiate; break; default: break; } // We've successfully determined the authentication scheme, now we'll // abort the open process to avoid touching system resources. throw this._exception; } } // base.OnOpening() should fail before we ever get here, but even when it doesn't // we want to alert users of problems creating the default endpoints. // DEVNOTE(wbasheer): Use localized error strings. throw new CommunicationException(Resource.Communication_NoDefaultAuthenticationScheme); }
public void SecurityMode2() { var modes = new HttpClientCredentialType [] { HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate }; foreach (var m in modes) { var b = new BasicHttpBinding(); b.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; // gives WS-Security message security. b.Security.Transport.ClientCredentialType = m; var bec = b.CreateBindingElements(); Assert.AreEqual(3, bec.Count, "#1." + m); Assert.IsTrue(bec [0] is TransportSecurityBindingElement, "#2." + m); Assert.IsTrue(bec [2] is HttpsTransportBindingElement, "#3." + m); var tbe = (HttpsTransportBindingElement)bec [2]; Assert.IsFalse(tbe.RequireClientCertificate, "#4." + m); } }
public void SecurityMode3() { var modes = new HttpClientCredentialType [] { HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows }; var auths = new AuthenticationSchemes [] { AuthenticationSchemes.Anonymous, AuthenticationSchemes.Basic, AuthenticationSchemes.Digest, AuthenticationSchemes.Ntlm, AuthenticationSchemes.Negotiate }; // specifically, none->anonymous, and windows->negotiate for (int i = 0; i < modes.Length; i++) { var m = modes [i]; var b = new BasicHttpBinding(); b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; // gives WS-Security message security. b.Security.Transport.ClientCredentialType = m; var bec = b.CreateBindingElements(); Assert.AreEqual(2, bec.Count, "#1." + m); Assert.IsTrue(bec [1] is HttpTransportBindingElement, "#2." + m); var tbe = (HttpTransportBindingElement)bec [1]; Assert.AreEqual(auths [i], tbe.AuthenticationScheme, "#3." + m); } }
public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithX509CertificateValidator_Works( string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType ) { // Arrange GC.KeepAlive(mode); // Mark parameter as used. See xUnit1026, [Theory] method doesn't use all parameters. HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { X509CertificateValidator = new Mock <X509CertificateValidator>().Object }; config.ClientCredentialType = clientCredentialType; // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); }
public void HttpSelfHostConfiguration_ClientCredentialType_PropagatesToHttpBinding( string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType ) { // Arrange HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { ClientCredentialType = clientCredentialType }; // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); Assert.Equal(clientCredentialType, binding.Security.Transport.ClientCredentialType); Assert.Equal(mode, binding.Security.Mode); }
public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithUsernamePasswordValidator_Works( string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType ) { // Arrange GC.KeepAlive(mode); // Mark parameter as used. See xUnit1026, [Theory] method doesn't use all parameters. HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { UserNamePasswordValidator = new CustomUsernamePasswordValidator() }; config.ClientCredentialType = clientCredentialType; // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); }
protected BasicHttpBinding GetBinding(BasicHttpSecurityMode httpMode, HttpClientCredentialType credentialMode) { var binding = new BasicHttpBinding(httpMode); binding.OpenTimeout = binding.CloseTimeout = binding.SendTimeout = binding.ReceiveTimeout = TimeSpan.FromMinutes(1); binding.MaxReceivedMessageSize = int.MaxValue; //20971520; binding.MaxBufferPoolSize = binding.MaxBufferSize = int.MaxValue; //20971520; binding.ReaderQuotas.MaxArrayLength = binding.ReaderQuotas.MaxStringContentLength = binding.ReaderQuotas.MaxBytesPerRead = binding.ReaderQuotas.MaxNameTableCharCount = 2097152; binding.TextEncoding = System.Text.Encoding.UTF8; binding.Security.Transport.ClientCredentialType = credentialMode; //binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Ntlm; binding.TransferMode = TransferMode.Buffered; binding.AllowCookies = false; return(binding); }
internal static AuthenticationSchemes MapToAuthenticationScheme(HttpClientCredentialType clientCredentialType) { switch (clientCredentialType) { case HttpClientCredentialType.None: case HttpClientCredentialType.Certificate: return AuthenticationSchemes.Anonymous; case HttpClientCredentialType.Basic: return AuthenticationSchemes.Basic; case HttpClientCredentialType.Digest: return AuthenticationSchemes.Digest; case HttpClientCredentialType.Ntlm: return AuthenticationSchemes.Ntlm; case HttpClientCredentialType.Windows: return AuthenticationSchemes.Negotiate; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); }
internal static AuthenticationSchemes MapToAuthenticationScheme(HttpClientCredentialType clientCredentialType) { switch (clientCredentialType) { case HttpClientCredentialType.None: case HttpClientCredentialType.Certificate: return(AuthenticationSchemes.Anonymous); case HttpClientCredentialType.Basic: return(AuthenticationSchemes.Basic); case HttpClientCredentialType.Digest: return(AuthenticationSchemes.Digest); case HttpClientCredentialType.Ntlm: return(AuthenticationSchemes.Ntlm); case HttpClientCredentialType.Windows: return(AuthenticationSchemes.Negotiate); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); }
internal static AuthenticationSchemes MapToAuthenticationScheme(HttpClientCredentialType clientCredentialType) { AuthenticationSchemes result; switch (clientCredentialType) { case HttpClientCredentialType.Certificate: // fall through to None case case HttpClientCredentialType.None: result = AuthenticationSchemes.Anonymous; break; case HttpClientCredentialType.Basic: result = AuthenticationSchemes.Basic; break; case HttpClientCredentialType.Digest: result = AuthenticationSchemes.Digest; break; case HttpClientCredentialType.Ntlm: result = AuthenticationSchemes.Ntlm; break; case HttpClientCredentialType.Windows: result = AuthenticationSchemes.Negotiate; break; case HttpClientCredentialType.InheritedFromHost: result = AuthenticationSchemes.None; break; default: Fx.Assert("unsupported client credential type"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } return(result); }
internal static AuthenticationSchemes MapToAuthenticationScheme(HttpClientCredentialType clientCredentialType) { switch (clientCredentialType) { case HttpClientCredentialType.None: case HttpClientCredentialType.Certificate: return AuthenticationSchemes.Anonymous; case HttpClientCredentialType.Basic: return AuthenticationSchemes.Basic; case HttpClientCredentialType.Digest: return AuthenticationSchemes.Digest; case HttpClientCredentialType.Ntlm: return AuthenticationSchemes.Ntlm; case HttpClientCredentialType.Windows: return AuthenticationSchemes.Negotiate; } Fx.Assert(false, "Invalid clientCredentialType " + clientCredentialType); return AuthenticationSchemes.Anonymous; }
public void SecurityMode() { // hmm, against my expectation, those modes does not give Http(s)TransportBindingElement property differences.. var modes = new HttpClientCredentialType [] { HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate }; foreach (var m in modes) { var b = new BasicHttpBinding(); b.Security.Mode = BasicHttpSecurityMode.Transport; b.Security.Transport.ClientCredentialType = m; var bec = b.CreateBindingElements(); Assert.AreEqual(2, bec.Count, "#1." + m); Assert.IsTrue(bec [1] is HttpsTransportBindingElement, "#2." + m); var tbe = (HttpsTransportBindingElement)bec [1]; if (m == HttpClientCredentialType.Certificate) { Assert.IsTrue(tbe.RequireClientCertificate, "#3." + m); } else { Assert.IsFalse(tbe.RequireClientCertificate, "#3." + m); } } }
public static void BasicHttpsBinding ( TestContext context, MetadataSet doc, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, TestLabel label) { label.EnterScope ("basicHttpsBinding"); BasicHttpBinding_inner ( context, doc, security, encoding, clientCred, authScheme, true, label); label.LeaveScope (); }
static void BasicHttpBinding_inner ( TestContext context, MetadataSet doc, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, bool isHttps, TestLabel label) { var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); bool hasPolicyXml; switch (security) { case BasicHttpSecurityMode.None: if (isHttps) throw new InvalidOperationException (); hasPolicyXml = encoding == WSMessageEncoding.Mtom; break; case BasicHttpSecurityMode.Message: case BasicHttpSecurityMode.Transport: case BasicHttpSecurityMode.TransportWithMessageCredential: if (encoding == WSMessageEncoding.Mtom) throw new InvalidOperationException (); hasPolicyXml = true; break; case BasicHttpSecurityMode.TransportCredentialOnly: if (isHttps) throw new InvalidOperationException (); hasPolicyXml = true; break; default: throw new InvalidOperationException (); } label.LeaveScope (); WS.SoapBinding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.SoapBinding) soap = (WS.SoapBinding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label); label.LeaveScope (); label.EnterScope ("policy-xml"); if (!hasPolicyXml) Assert.That (xml, Is.Null, label.Get ()); else { Assert.That (xml, Is.Not.Null, label.Get ()); var assertions = AssertPolicy (sd, xml, label); Assert.That (assertions, Is.Not.Null, label.Get ()); if (clientCred == HttpClientCredentialType.Ntlm) AssertPolicy (assertions, NtlmAuthenticationQName, label); if (encoding == WSMessageEncoding.Mtom) AssertPolicy (assertions, MtomEncodingQName, label); switch (security) { case BasicHttpSecurityMode.Message: AssertPolicy (assertions, AsymmetricBindingQName, label); AssertPolicy (assertions, Wss10QName, label); break; case BasicHttpSecurityMode.Transport: AssertPolicy (assertions, TransportBindingQName, label); break; case BasicHttpSecurityMode.TransportWithMessageCredential: AssertPolicy (assertions, SignedSupportingQName, label); AssertPolicy (assertions, TransportBindingQName, label); AssertPolicy (assertions, Wss10QName, label); break; default: break; } Assert.That (assertions.Count, Is.EqualTo (0), label.Get ()); } label.LeaveScope (); label.EnterScope ("services"); Assert.That (sd.Services, Is.Not.Null, label.Get ()); Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ()); var service = sd.Services [0]; Assert.That (service.Ports, Is.Not.Null, label.Get ()); Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ()); var port = service.Ports [0]; label.EnterScope ("port"); Assert.That (port.Extensions, Is.Not.Null, label.Get ()); Assert.That (port.Extensions.Count, Is.EqualTo (1), label.Get ()); WS.SoapAddressBinding soap_addr_binding = null; foreach (var extension in port.Extensions) { if (extension is WS.SoapAddressBinding) soap_addr_binding = (WS.SoapAddressBinding)extension; else Assert.Fail (label.Get ()); } Assert.That (soap_addr_binding, Is.Not.Null, label.Get ()); label.LeaveScope (); label.LeaveScope (); // wsdl var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); string scheme; if ((security == BasicHttpSecurityMode.Transport) || (security == BasicHttpSecurityMode.TransportWithMessageCredential)) scheme = "https"; else scheme = "http"; CheckBasicHttpBinding ( bindings [0], scheme, security, encoding, clientCred, authScheme, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); var uri = isHttps ? MetadataSamples.HttpsUri : MetadataSamples.HttpUri; CheckEndpoint (endpoints [0], uri, label); label.LeaveScope (); }
private bool IsValidForTransportSecurity(HttpClientCredentialType value) { HttpClientCredentialType[] allowedTypesForTransport = { HttpClientCredentialType.Digest, HttpClientCredentialType.Basic }; if (SecurityMode.Transport == base.SecurityMode) { return !allowedTypesForTransport.Contains(value); } else { return true; } }
public static void CheckBasicHttpBinding ( Binding binding, string scheme, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, TestLabel label) { label.EnterScope ("http"); if (security == BasicHttpSecurityMode.Message) { Assert.That (binding, Is.InstanceOfType (typeof(CustomBinding)), label.Get ()); } else { Assert.That (binding, Is.InstanceOfType (typeof(BasicHttpBinding)), label.Get ()); var basicHttp = (BasicHttpBinding)binding; Assert.That (basicHttp.EnvelopeVersion, Is.EqualTo (EnvelopeVersion.Soap11), label.Get ()); Assert.That (basicHttp.MessageVersion, Is.EqualTo (MessageVersion.Soap11), label.Get ()); Assert.That (basicHttp.Scheme, Is.EqualTo (scheme), label.Get ()); Assert.That (basicHttp.TransferMode, Is.EqualTo (TransferMode.Buffered), label.Get ()); Assert.That (basicHttp.MessageEncoding, Is.EqualTo (encoding), label.Get ()); Assert.That (basicHttp.Security, Is.Not.Null, label.Get ()); Assert.That (basicHttp.Security.Mode, Is.EqualTo (security), label.Get ()); Assert.That (basicHttp.Security.Transport.ClientCredentialType, Is.EqualTo (clientCred), label.Get ()); Assert.That (basicHttp.Security.Message.AlgorithmSuite, Is.EqualTo (SecurityAlgorithmSuite.Basic256), label.Get ()); } label.EnterScope ("elements"); var elements = binding.CreateBindingElements (); Assert.That (elements, Is.Not.Null, label.Get ()); if ((security == BasicHttpSecurityMode.Message) || (security == BasicHttpSecurityMode.TransportWithMessageCredential)) Assert.That (elements.Count, Is.EqualTo (3), label.Get ()); else Assert.That (elements.Count, Is.EqualTo (2), label.Get ()); TextMessageEncodingBindingElement textElement = null; TransportSecurityBindingElement securityElement = null; HttpTransportBindingElement transportElement = null; AsymmetricSecurityBindingElement asymmSecurityElement = null; MtomMessageEncodingBindingElement mtomElement = null; foreach (var element in elements) { if (element is TextMessageEncodingBindingElement) textElement = (TextMessageEncodingBindingElement)element; else if (element is HttpTransportBindingElement) transportElement = (HttpTransportBindingElement)element; else if (element is TransportSecurityBindingElement) securityElement = (TransportSecurityBindingElement)element; else if (element is AsymmetricSecurityBindingElement) asymmSecurityElement = (AsymmetricSecurityBindingElement)element; else if (element is MtomMessageEncodingBindingElement) mtomElement = (MtomMessageEncodingBindingElement)element; else Assert.Fail (string.Format ( "Unknown element: {0}", element.GetType ()), label.Get ()); } label.EnterScope ("text"); if (encoding == WSMessageEncoding.Text) { Assert.That (textElement, Is.Not.Null, label.Get ()); Assert.That (textElement.WriteEncoding, Is.InstanceOfType (typeof(UTF8Encoding)), label.Get ()); } else { Assert.That (textElement, Is.Null, label.Get ()); } label.LeaveScope (); label.EnterScope ("mtom"); if (encoding == WSMessageEncoding.Mtom) { Assert.That (mtomElement, Is.Not.Null, label.Get ()); } else { Assert.That (mtomElement, Is.Null, label.Get ()); } label.LeaveScope (); label.EnterScope ("security"); if (security == BasicHttpSecurityMode.TransportWithMessageCredential) { Assert.That (securityElement, Is.Not.Null, label.Get ()); Assert.That (securityElement.SecurityHeaderLayout, Is.EqualTo (SecurityHeaderLayout.Lax), label.Get ()); } else { Assert.That (securityElement, Is.Null, label.Get ()); } label.LeaveScope (); label.EnterScope ("asymmetric"); if (security == BasicHttpSecurityMode.Message) { Assert.That (asymmSecurityElement, Is.Not.Null, label.Get ()); } else { Assert.That (asymmSecurityElement, Is.Null, label.Get ()); } label.LeaveScope (); label.EnterScope ("transport"); Assert.That (transportElement, Is.Not.Null, label.Get ()); Assert.That (transportElement.Realm, Is.Empty, label.Get ()); Assert.That (transportElement.Scheme, Is.EqualTo (scheme), label.Get ()); Assert.That (transportElement.TransferMode, Is.EqualTo (TransferMode.Buffered), label.Get ()); label.EnterScope ("auth"); Assert.That (transportElement.AuthenticationScheme, Is.EqualTo (authScheme), label.Get ()); label.LeaveScope (); // auth label.LeaveScope (); // transport label.LeaveScope (); // elements label.LeaveScope (); // http }
public void HttpSelfHostConfiguration_WrongClientCredentialType_WithUsernamePasswordValidator_Throws(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType) { // Arrange HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { UserNamePasswordValidator = new CustomUsernamePasswordValidator() }; config.ClientCredentialType = clientCredentialType; Assert.Throws<InvalidOperationException>(() => { // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); }); }
private static void ConfigureReportServerBinding(string ReportServerPath, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, out string serviceUrl, out string execUrl, out BasicHttpBinding basicHttpBinding) { serviceUrl = string.Empty; execUrl = string.Empty; if (ReportMode == ReportServerMode.Native) // for example http://licalhost/ReportServer/ { serviceUrl = ReportServerPath.TrimEnd('/') + @"/reportservice2010.asmx"; execUrl = ReportServerPath.TrimEnd('/') + @"/ReportExecution2005.asmx"; } else if (ReportMode == ReportServerMode.SharePoint) // for example http://mysharepointserver.local/_vti_bin/ReportServer/ { serviceUrl = ReportServerPath.TrimEnd('/') + @"/_vti_bin/ReportServer/reportservice2010.asmx"; execUrl = ReportServerPath.TrimEnd('/') + @"/_vti_bin/ReportServer/ReportExecution2005.asmx"; } basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); basicHttpBinding.TransferMode = TransferMode.Buffered; basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; basicHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; basicHttpBinding.Security.Transport.ClientCredentialType = ReportHttpClientCredentialType; //Windows|Ntlm basicHttpBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName; basicHttpBinding.MaxReceivedMessageSize = 2147483646L; ////basicHttpBinding.AllowCookies = true; basicHttpBinding.SendTimeout = TimeSpan.MaxValue; //basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; }
static CredentialTypeEx ConvertCredentials(HttpClientCredentialType credentials) { switch(credentials) { case HttpClientCredentialType.Basic: case HttpClientCredentialType.Digest: { return CredentialTypeEx.Username; } case HttpClientCredentialType.Certificate: { return CredentialTypeEx.Certificate; } case HttpClientCredentialType.None: { return CredentialTypeEx.None; } case HttpClientCredentialType.Ntlm: case HttpClientCredentialType.Windows: { return CredentialTypeEx.Windows; } default: { throw new InvalidOperationException("Unknown credentials type"); } } }
public void SecurityMode () { // hmm, against my expectation, those modes does not give Http(s)TransportBindingElement property differences.. var modes = new HttpClientCredentialType [] {HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate}; foreach (var m in modes) { var b = new BasicHttpBinding (); b.Security.Mode = BasicHttpSecurityMode.Transport; b.Security.Transport.ClientCredentialType = m; var bec = b.CreateBindingElements (); Assert.AreEqual (2, bec.Count, "#1." + m); Assert.IsTrue (bec [1] is HttpsTransportBindingElement, "#2." + m); var tbe = (HttpsTransportBindingElement) bec [1]; if (m == HttpClientCredentialType.Certificate) Assert.IsTrue (tbe.RequireClientCertificate, "#3." + m); else Assert.IsFalse (tbe.RequireClientCertificate, "#3." + m); } }
public static void BasicHttpsBinding ( TestContext context, MetadataSet doc, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, TestLabel label) { label.EnterScope ("basicHttpsBinding"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); Assert.That (sd.Extensions, Is.Not.Null, label.Get ()); Assert.That (sd.Extensions.Count, Is.EqualTo (1), label.Get ()); Assert.That (sd.Extensions [0], Is.InstanceOfType (typeof(XmlElement)), label.Get ()); label.EnterScope ("extensions"); var extension = (XmlElement)sd.Extensions [0]; Assert.That (extension.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (extension.LocalName, Is.EqualTo ("Policy"), label.Get ()); label.LeaveScope (); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); label.LeaveScope (); WS.SoapBinding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.SoapBinding) soap = (WS.SoapBinding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label); if (context.CheckPolicyXml) { label.EnterScope ("policy-xml"); Assert.That (xml, Is.Not.Null, label.Get ()); Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ()); label.LeaveScope (); } label.LeaveScope (); // wsdl var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); CheckBasicHttpBinding ( bindings [0], "https", security, encoding, clientCred, authScheme, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); CheckEndpoint (endpoints [0], MetadataSamples.HttpsUri, label); label.LeaveScope (); label.LeaveScope (); }
public void SecurityMode3 () { var modes = new HttpClientCredentialType [] {HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows}; var auths = new AuthenticationSchemes [] { AuthenticationSchemes.Anonymous, AuthenticationSchemes.Basic, AuthenticationSchemes.Digest, AuthenticationSchemes.Ntlm, AuthenticationSchemes.Negotiate }; // specifically, none->anonymous, and windows->negotiate for (int i = 0; i < modes.Length; i++) { var m = modes [i]; var b = new BasicHttpBinding (); b.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; // gives WS-Security message security. b.Security.Transport.ClientCredentialType = m; var bec = b.CreateBindingElements (); Assert.AreEqual (2, bec.Count, "#1." + m); Assert.IsTrue (bec [1] is HttpTransportBindingElement, "#2." + m); var tbe = (HttpTransportBindingElement) bec [1]; Assert.AreEqual (auths [i], tbe.AuthenticationScheme, "#3." + m); } }
public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithX509CertificateValidator_Works(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType) { // Arrange HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { X509CertificateValidator = new Mock<X509CertificateValidator>().Object }; config.ClientCredentialType = clientCredentialType; // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); }
public void HttpSelfHostConfiguration_WrongClientCredentialType_WithX509CertificateValidator_Throws(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType) { // Arrange HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { X509CertificateValidator = new Mock<X509CertificateValidator>().Object }; config.ClientCredentialType = clientCredentialType; Assert.Throws<InvalidOperationException>(() => { // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); }); }
public void HttpSelfHostConfiguration_CorrectClientCredentialType_WithUsernamePasswordValidator_Works(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType) { // Arrange HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { UserNamePasswordValidator = new CustomUsernamePasswordValidator() }; config.ClientCredentialType = clientCredentialType; // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); }
public void ConfigurationService(BasicHttpSecurityMode basicHttpSecurityMode, HttpClientCredentialType httpClientCredentialType, string Uri, TimeSpan tiempoCierre, TimeSpan tiempoRespuesta) { BasicHttpBinding = new BasicHttpBinding(basicHttpSecurityMode); BasicHttpBinding.Security.Transport.ClientCredentialType = httpClientCredentialType; BasicHttpBinding.CloseTimeout = tiempoCierre; BasicHttpBinding.ReceiveTimeout = tiempoRespuesta; EndpointAddress = new EndpointAddress(new Uri(Uri)); }
private void Render(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, List<KeyValuePair<string, string>> ReportParameters, string ParameterLanguage, string RenderFormat, string RenderPath) { ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[ReportParameters.Count()]; int index = 0; string paramString = string.Empty; foreach (var item in ReportParameters) { parameters[index] = new ReportExecution2005.ParameterValue(); parameters[index].Name = item.Key; parameters[index].Value = item.Value; index++; paramString = paramString + item.Key + "=" + item.Value + "&"; } string cachedKey = ReportServerPath + @"/" + ReportFolder + @"/" + ReportName + @"?" + paramString; if (cachedFiles.ContainsKey(cachedKey)) //load report from cache { RenderPath = cachedFiles[cachedKey]; if (!string.IsNullOrEmpty(RenderPath) && File.Exists(RenderPath)) { return; } } byte[] bytes; GetReportData(ReportServerPath, UserName, UserPassword, ReportMode, ReportHttpClientCredentialType, ReportFolder, ReportName, parameters, ParameterLanguage, RenderFormat, out bytes); if (bytes != null && !string.IsNullOrEmpty(RenderPath)) { try { string folderName = RenderPath.Substring(0, RenderPath.LastIndexOf('\\') + 1); string fileName = CleanFileName(RenderPath.Substring(RenderPath.LastIndexOf('\\') + 1)); using (FileStream fs = File.Create(folderName + fileName)) { fs.Write(bytes, 0, bytes.Length); fs.Close(); } cachedFiles[cachedKey] = RenderPath; } catch (IOException ex) { LogMessage("Not able to create file " + RenderPath + ". Error: " + ex.Message); throw; } } }
private bool IsHttpClientCredentialTypeDefined(HttpClientCredentialType value) { HttpClientCredentialType[] knownTypes = { HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate }; return knownTypes.Contains(value); }
private void Render(string ReportServerPath, string UserName, string UserPassword, ReportServerMode ReportMode, HttpClientCredentialType ReportHttpClientCredentialType, string ReportFolder, string ReportName, List<KeyValuePair<string, string>> ReportParameters, string ParameterLanguage, out XElement xDocument) { xDocument = null; ReportExecution2005.ParameterValue[] parameters = new ReportExecution2005.ParameterValue[ReportParameters.Count()]; int index = 0; string paramString = string.Empty; foreach (var item in ReportParameters) { parameters[index] = new ReportExecution2005.ParameterValue(); parameters[index].Name = item.Key; parameters[index].Value = item.Value; index++; paramString = paramString + item.Key + "=" + item.Value + "&"; } string cachedKey = ReportServerPath.TrimEnd('/') + @"/" + ReportFolder.TrimStart('/').TrimEnd('/') + @"/" + ReportName + @"?" + paramString; if (cachedReports.ContainsKey(cachedKey)) //load report from cache { xDocument = cachedReports[cachedKey]; return; } byte[] bytes; GetReportData(ReportServerPath, UserName, UserPassword, ReportMode, ReportHttpClientCredentialType, ReportFolder, ReportName, parameters, ParameterLanguage, "XML", out bytes); if (bytes != null) { using (MemoryStream ms = new MemoryStream(bytes)) { XNamespace test = XNamespace.Get(ReportName); XNamespace xsi = XNamespace.Get(@"http://www.w3.org/2001/XMLSchema-instance"); XmlReader reader = XmlReader.Create(ms); xDocument = StripNS(XElement.Load(reader, LoadOptions.None)); xDocument.Attributes().Remove(); xDocument = new XElement("Report" , new XAttribute(XNamespace.Xmlns + "test", ReportName) //blank.NamespaceName , new XAttribute(XNamespace.Xmlns + "xsi", xsi) , xDocument.Nodes()); } cachedReports[cachedKey] = xDocument; } }
public void SecurityMode2 () { var modes = new HttpClientCredentialType [] {HttpClientCredentialType.None, HttpClientCredentialType.Basic, HttpClientCredentialType.Digest, HttpClientCredentialType.Ntlm, HttpClientCredentialType.Windows, HttpClientCredentialType.Certificate}; foreach (var m in modes) { var b = new BasicHttpBinding (); b.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential; // gives WS-Security message security. b.Security.Transport.ClientCredentialType = m; var bec = b.CreateBindingElements (); Assert.AreEqual (3, bec.Count, "#1." + m); Assert.IsTrue (bec [0] is TransportSecurityBindingElement, "#2." + m); Assert.IsTrue (bec [2] is HttpsTransportBindingElement, "#3." + m); var tbe = (HttpsTransportBindingElement) bec [2]; Assert.IsFalse (tbe.RequireClientCertificate, "#4." + m); } }
public void HttpSelfHostConfiguration_ClientCredentialType_PropagatesToHttpBinding(string address, HttpBindingSecurityMode mode, HttpClientCredentialType clientCredentialType) { // Arrange HttpBinding binding = new HttpBinding(); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(address) { ClientCredentialType = clientCredentialType }; // Act BindingParameterCollection parameters = config.ConfigureBinding(binding); Assert.Equal(clientCredentialType, binding.Security.Transport.ClientCredentialType); Assert.Equal(mode, binding.Security.Mode); }
public HttpTransportSecurity() { _clientCredentialType = DefaultClientCredentialType; _realm = DefaultRealm; }
public static void BasicHttpBinding ( TestContext context, MetadataSet doc, BasicHttpSecurityMode security, WSMessageEncoding encoding, HttpClientCredentialType clientCred, AuthenticationSchemes authScheme, TestLabel label) { label.EnterScope ("basicHttpBinding"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); label.EnterScope ("bindings"); Assert.That (sd.Bindings.Count, Is.EqualTo (1), label.Get ()); var binding = sd.Bindings [0]; Assert.That (binding.ExtensibleAttributes, Is.Null, label.Get ()); Assert.That (binding.Extensions, Is.Not.Null, label.Get ()); bool hasPolicyXml; switch (security) { case BasicHttpSecurityMode.None: hasPolicyXml = encoding == WSMessageEncoding.Mtom; break; case BasicHttpSecurityMode.Message: case BasicHttpSecurityMode.Transport: case BasicHttpSecurityMode.TransportWithMessageCredential: if (encoding == WSMessageEncoding.Mtom) throw new InvalidOperationException (); hasPolicyXml = true; break; case BasicHttpSecurityMode.TransportCredentialOnly: hasPolicyXml = true; break; default: throw new InvalidOperationException (); } label.LeaveScope (); WS.SoapBinding soap = null; XmlElement xml = null; foreach (var ext in binding.Extensions) { if (ext is WS.SoapBinding) soap = (WS.SoapBinding)ext; else if (ext is XmlElement) xml = (XmlElement)ext; } CheckSoapBinding (soap, WS.SoapBinding.HttpTransport, label); label.LeaveScope (); label.EnterScope ("policy-xml"); if (!hasPolicyXml) Assert.That (xml, Is.Null, label.Get ()); else if (context.CheckPolicyXml) { Assert.That (xml, Is.Not.Null, label.Get ()); Assert.That (xml.NamespaceURI, Is.EqualTo (WspNamespace), label.Get ()); Assert.That (xml.LocalName, Is.EqualTo ("PolicyReference"), label.Get ()); } label.LeaveScope (); var importer = new WsdlImporter (doc); label.EnterScope ("bindings"); var bindings = importer.ImportAllBindings (); CheckImportErrors (importer, label); Assert.That (bindings, Is.Not.Null, label.Get ()); Assert.That (bindings.Count, Is.EqualTo (1), label.Get ()); string scheme; if ((security == BasicHttpSecurityMode.Transport) || (security == BasicHttpSecurityMode.TransportWithMessageCredential)) scheme = "https"; else scheme = "http"; CheckBasicHttpBinding ( bindings [0], scheme, security, encoding, clientCred, authScheme, label); label.LeaveScope (); label.EnterScope ("endpoints"); var endpoints = importer.ImportAllEndpoints (); CheckImportErrors (importer, label); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (1), label.Get ()); CheckEndpoint (endpoints [0], MetadataSamples.HttpUri, label); label.LeaveScope (); label.LeaveScope (); }