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
- SmiConnection.cs
- ClrPerspective.cs
- LinkGrep.cs
- XamlBrushSerializer.cs
- LoginView.cs
- MimePart.cs
- CompositeFontFamily.cs
- ListViewPagedDataSource.cs
- ZipIOExtraFieldPaddingElement.cs
- _UriTypeConverter.cs
- SoundPlayerAction.cs
- X509Certificate2Collection.cs
- BindValidationContext.cs
- SettingsPropertyValueCollection.cs
- URLBuilder.cs
- RepeatButtonAutomationPeer.cs
- SqlCommandBuilder.cs
- SoapConverter.cs
- SymmetricAlgorithm.cs
- BuildProvider.cs
- StringStorage.cs
- WeakReferenceEnumerator.cs
- XmlTextEncoder.cs
- WizardPanelChangingEventArgs.cs
- DataGridViewColumnHeaderCell.cs
- ReadOnlyDictionary.cs
- MarshalDirectiveException.cs
- XmlDataImplementation.cs
- Error.cs
- MemberDomainMap.cs
- ServicePointManagerElement.cs
- ExtenderProvidedPropertyAttribute.cs
- Walker.cs
- EndEvent.cs
- EventProvider.cs
- UrlMapping.cs
- ReverseQueryOperator.cs
- SslStream.cs
- Faults.cs
- XmlNodeChangedEventManager.cs
- PolicyLevel.cs
- LockedHandleGlyph.cs
- ModelItem.cs
- SqlNotificationEventArgs.cs
- WsdlWriter.cs
- TypeBuilder.cs
- TriggerCollection.cs
- XmlQueryOutput.cs
- x509utils.cs
- ProcessStartInfo.cs
- ClientSettingsProvider.cs
- AnnotationResource.cs
- HierarchicalDataTemplate.cs
- CodeLinePragma.cs
- KnownTypesHelper.cs
- TextShapeableCharacters.cs
- ComEventsSink.cs
- ExpressionVisitor.cs
- GridToolTip.cs
- SimpleType.cs
- ExceptionDetail.cs
- SafeProcessHandle.cs
- EntityDataSourceColumn.cs
- ConfigXmlWhitespace.cs
- StateItem.cs
- CompositionDesigner.cs
- NavigationHelper.cs
- EmptyEnumerator.cs
- PointLight.cs
- Panel.cs
- TextServicesProperty.cs
- DataGridViewLinkCell.cs
- MaterialGroup.cs
- DefaultPropertyAttribute.cs
- CalloutQueueItem.cs
- ProcessModule.cs
- ProxyWebPartConnectionCollection.cs
- Select.cs
- UnsafeNativeMethodsTablet.cs
- TableColumnCollectionInternal.cs
- Graphics.cs
- MapPathBasedVirtualPathProvider.cs
- FormatStringEditor.cs
- MissingManifestResourceException.cs
- ThemeableAttribute.cs
- AuthenticationModuleElementCollection.cs
- Validator.cs
- DataGridViewSortCompareEventArgs.cs
- ApplicationFileCodeDomTreeGenerator.cs
- StrokeCollection2.cs
- FindSimilarActivitiesVerb.cs
- JumpItem.cs
- CompressStream.cs
- WebServiceClientProxyGenerator.cs
- dataSvcMapFileLoader.cs
- TransformPattern.cs
- AutomationTextAttribute.cs
- RichTextBoxContextMenu.cs
- PerformanceCounterCategory.cs
- CryptoProvider.cs