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
- DispatcherSynchronizationContext.cs
- LinkDescriptor.cs
- Comparer.cs
- MouseActionConverter.cs
- DateTimeSerializationSection.cs
- Vector3DAnimation.cs
- DeclarativeCatalogPart.cs
- DeviceOverridableAttribute.cs
- VectorValueSerializer.cs
- CultureSpecificStringDictionary.cs
- SystemResourceKey.cs
- CompositionTarget.cs
- NotImplementedException.cs
- PagesSection.cs
- WindowsRegion.cs
- ObjectQueryExecutionPlan.cs
- UnsafeCollabNativeMethods.cs
- ComEventsInfo.cs
- IChannel.cs
- CompiledRegexRunnerFactory.cs
- CSharpCodeProvider.cs
- WebPartCancelEventArgs.cs
- OutputCacheProfile.cs
- DataStreams.cs
- ProgressBar.cs
- PackagingUtilities.cs
- SmiConnection.cs
- ReadOnlyMetadataCollection.cs
- DynamicDataRouteHandler.cs
- ZipIOLocalFileBlock.cs
- StringUtil.cs
- Point3D.cs
- OracleLob.cs
- PersistenceProviderBehavior.cs
- ConfigurationValue.cs
- CodeExpressionCollection.cs
- EnterpriseServicesHelper.cs
- HighlightComponent.cs
- FileFormatException.cs
- EntityViewGenerationConstants.cs
- SerializationStore.cs
- Serializer.cs
- PingOptions.cs
- FolderBrowserDialog.cs
- UnsafeNativeMethods.cs
- FactoryId.cs
- XmlReader.cs
- CornerRadiusConverter.cs
- ProcessInfo.cs
- Separator.cs
- ProviderSettingsCollection.cs
- DesignerVerb.cs
- DetailsViewUpdateEventArgs.cs
- PerformanceCounterCategory.cs
- AuthorizationSection.cs
- ConnectionStringEditor.cs
- DirtyTextRange.cs
- GeneralTransformGroup.cs
- TextFormatterHost.cs
- KnownTypeDataContractResolver.cs
- PropertyChangedEventManager.cs
- LinqTreeNodeEvaluator.cs
- DataGridViewColumn.cs
- SecurityRuntime.cs
- FreezableDefaultValueFactory.cs
- RubberbandSelector.cs
- SHA1.cs
- newitemfactory.cs
- HttpHandlerAction.cs
- TypeResolver.cs
- DataProtection.cs
- Calendar.cs
- CounterCreationData.cs
- x509utils.cs
- TableItemProviderWrapper.cs
- Help.cs
- OperationResponse.cs
- HtmlElementEventArgs.cs
- FieldNameLookup.cs
- ButtonAutomationPeer.cs
- NetStream.cs
- SharedPersonalizationStateInfo.cs
- WeakHashtable.cs
- FontCacheLogic.cs
- IndexedWhereQueryOperator.cs
- InfoCardAsymmetricCrypto.cs
- WmiEventSink.cs
- AutomationPatternInfo.cs
- Utils.cs
- PerspectiveCamera.cs
- AppPool.cs
- PeerCollaborationPermission.cs
- SiteMapHierarchicalDataSourceView.cs
- PeekCompletedEventArgs.cs
- ViewCellSlot.cs
- DataSvcMapFileSerializer.cs
- AnnotationHelper.cs
- StylusLogic.cs
- XmlDocumentSchema.cs
- ComboBoxDesigner.cs