Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / HttpTransportSecurity.cs / 1 / HttpTransportSecurity.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.Net; using System.Net.Security; public sealed class HttpTransportSecurity { internal const HttpClientCredentialType DefaultClientCredentialType = HttpClientCredentialType.None; internal const HttpProxyCredentialType DefaultProxyCredentialType = HttpProxyCredentialType.None; internal const string DefaultRealm = System.ServiceModel.Channels.HttpTransportDefaults.Realm; HttpClientCredentialType clientCredentialType; HttpProxyCredentialType proxyCredentialType; string realm; internal HttpTransportSecurity() { this.clientCredentialType = DefaultClientCredentialType; this.proxyCredentialType = DefaultProxyCredentialType; this.realm = DefaultRealm; } public HttpClientCredentialType ClientCredentialType { get { return this.clientCredentialType; } set { if (!HttpClientCredentialTypeHelper.IsDefined(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); } this.clientCredentialType = value; } } public HttpProxyCredentialType ProxyCredentialType { get { return this.proxyCredentialType; } set { if (!HttpProxyCredentialTypeHelper.IsDefined(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); } this.proxyCredentialType = value; } } public string Realm { get { return this.realm; } set { this.realm = value; } } internal void ConfigureTransportProtectionOnly(HttpsTransportBindingElement https) { DisableAuthentication(https); https.RequireClientCertificate = false; } void ConfigureAuthentication(HttpTransportBindingElement http) { http.AuthenticationScheme = HttpClientCredentialTypeHelper.MapToAuthenticationScheme(this.clientCredentialType); http.ProxyAuthenticationScheme = HttpProxyCredentialTypeHelper.MapToAuthenticationScheme(this.proxyCredentialType); http.Realm = this.Realm; } static void ConfigureAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity) { transportSecurity.clientCredentialType = HttpClientCredentialTypeHelper.MapToClientCredentialType(http.AuthenticationScheme); transportSecurity.proxyCredentialType = HttpProxyCredentialTypeHelper.MapToProxyCredentialType(http.ProxyAuthenticationScheme); transportSecurity.Realm = http.Realm; } void DisableAuthentication(HttpTransportBindingElement http) { http.AuthenticationScheme = AuthenticationSchemes.Anonymous; http.ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous; http.Realm = DefaultRealm; } static bool IsDisabledAuthentication(HttpTransportBindingElement http) { return http.AuthenticationScheme == AuthenticationSchemes.Anonymous && http.ProxyAuthenticationScheme == AuthenticationSchemes.Anonymous && http.Realm == DefaultRealm; } internal void ConfigureTransportProtectionAndAuthentication(HttpsTransportBindingElement https) { ConfigureAuthentication(https); https.RequireClientCertificate = (this.clientCredentialType == HttpClientCredentialType.Certificate); } internal static void ConfigureTransportProtectionAndAuthentication(HttpsTransportBindingElement https, HttpTransportSecurity transportSecurity) { ConfigureAuthentication(https, transportSecurity); if (https.RequireClientCertificate) transportSecurity.ClientCredentialType = HttpClientCredentialType.Certificate; } internal void ConfigureTransportAuthentication(HttpTransportBindingElement http) { if (this.clientCredentialType == HttpClientCredentialType.Certificate) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CertificateUnsupportedForHttpTransportCredentialOnly))); } ConfigureAuthentication(http); } internal static bool IsConfiguredTransportAuthentication(HttpTransportBindingElement http, HttpTransportSecurity transportSecurity) { if (HttpClientCredentialTypeHelper.MapToClientCredentialType(http.AuthenticationScheme) == HttpClientCredentialType.Certificate) return false; ConfigureAuthentication(http, transportSecurity); return true; } internal void DisableTransportAuthentication(HttpTransportBindingElement http) { DisableAuthentication(http); } internal static bool IsDisabledTransportAuthentication(HttpTransportBindingElement http) { return IsDisabledAuthentication(http); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BaseWebProxyFinder.cs
- OleDbErrorCollection.cs
- TableTextElementCollectionInternal.cs
- ConfigurationPropertyCollection.cs
- UnsettableComboBox.cs
- QilXmlWriter.cs
- SubclassTypeValidator.cs
- Int32CollectionValueSerializer.cs
- TemplatePagerField.cs
- Region.cs
- HtmlInputFile.cs
- ResourceIDHelper.cs
- MsmqProcessProtocolHandler.cs
- GridProviderWrapper.cs
- DataKey.cs
- GridSplitter.cs
- NamedObject.cs
- RotateTransform.cs
- PackageProperties.cs
- X509CertificateStore.cs
- AutomationTextAttribute.cs
- TextTrailingCharacterEllipsis.cs
- MembershipSection.cs
- SHA512Managed.cs
- HtmlInputCheckBox.cs
- Rotation3D.cs
- _LocalDataStore.cs
- ButtonBaseAutomationPeer.cs
- StrokeIntersection.cs
- LayoutEvent.cs
- PropertyGridCommands.cs
- Point3DCollection.cs
- FormViewModeEventArgs.cs
- FixUpCollection.cs
- ModifierKeysConverter.cs
- StaticFileHandler.cs
- _TimerThread.cs
- BaseComponentEditor.cs
- ContextBase.cs
- HostProtectionException.cs
- Baml2006KeyRecord.cs
- ColorBlend.cs
- InheritedPropertyDescriptor.cs
- XPathBinder.cs
- SHA1.cs
- Single.cs
- PopupControlService.cs
- Misc.cs
- DbConnectionPoolGroupProviderInfo.cs
- SrgsElementFactory.cs
- HtmlTableCellCollection.cs
- ListenerElementsCollection.cs
- RefreshPropertiesAttribute.cs
- DescriptionAttribute.cs
- DeclarativeCatalogPart.cs
- CommonXSendMessage.cs
- DefaultMergeHelper.cs
- ResXResourceSet.cs
- XmlSerializerVersionAttribute.cs
- Site.cs
- ListMarkerLine.cs
- InvariantComparer.cs
- SecondaryIndex.cs
- WriteableBitmap.cs
- StylusLogic.cs
- RootBuilder.cs
- XmlBinaryReaderSession.cs
- CaseInsensitiveOrdinalStringComparer.cs
- PeerPresenceInfo.cs
- SeverityFilter.cs
- ProxyWebPart.cs
- WinEventTracker.cs
- SmtpException.cs
- SmiSettersStream.cs
- PathTooLongException.cs
- Block.cs
- StringValidator.cs
- XsdCachingReader.cs
- JsonDataContract.cs
- SSmlParser.cs
- ContentElement.cs
- ErrorFormatterPage.cs
- OracleLob.cs
- CacheEntry.cs
- DocumentOrderQuery.cs
- HwndHost.cs
- LongMinMaxAggregationOperator.cs
- TagElement.cs
- ConditionCollection.cs
- uribuilder.cs
- SelectingProviderEventArgs.cs
- Native.cs
- DSASignatureFormatter.cs
- DataGridItemAttachedStorage.cs
- IUnknownConstantAttribute.cs
- SafeMILHandle.cs
- SerializationInfo.cs
- DiscoveryDocumentSerializer.cs
- ReadOnlyHierarchicalDataSourceView.cs
- UIServiceHelper.cs