Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / WSHttpSecurity.cs / 1 / WSHttpSecurity.cs
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel
{
using System.Diagnostics;
using System.Net.Security;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
public sealed class WSHttpSecurity
{
internal const SecurityMode DefaultMode = SecurityMode.Message;
SecurityMode mode;
HttpTransportSecurity transportSecurity;
NonDualMessageSecurityOverHttp messageSecurity;
internal WSHttpSecurity()
: this(DefaultMode, GetDefaultHttpTransportSecurity(), new NonDualMessageSecurityOverHttp())
{
}
internal WSHttpSecurity(SecurityMode mode, HttpTransportSecurity transportSecurity, NonDualMessageSecurityOverHttp messageSecurity)
{
this.mode = mode;
this.transportSecurity = transportSecurity == null ? GetDefaultHttpTransportSecurity() : transportSecurity;
this.messageSecurity = messageSecurity == null ? new NonDualMessageSecurityOverHttp() : messageSecurity;
}
internal static HttpTransportSecurity GetDefaultHttpTransportSecurity()
{
HttpTransportSecurity transportSecurity = new HttpTransportSecurity();
transportSecurity.ClientCredentialType = HttpClientCredentialType.Windows;
return transportSecurity;
}
public SecurityMode Mode
{
get { return this.mode; }
set
{
if (!SecurityModeHelper.IsDefined(value))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value"));
}
this.mode = value;
}
}
public HttpTransportSecurity Transport
{
get { return this.transportSecurity; }
}
public NonDualMessageSecurityOverHttp Message
{
get { return this.messageSecurity; }
}
internal void ApplyTransportSecurity(HttpsTransportBindingElement https)
{
if (this.mode == SecurityMode.TransportWithMessageCredential)
{
this.transportSecurity.ConfigureTransportProtectionOnly(https);
}
else
{
this.transportSecurity.ConfigureTransportProtectionAndAuthentication(https);
}
}
internal static void ApplyTransportSecurity(HttpsTransportBindingElement transport, HttpTransportSecurity transportSecurity)
{
HttpTransportSecurity.ConfigureTransportProtectionAndAuthentication(transport, transportSecurity);
}
internal SecurityBindingElement CreateMessageSecurity(bool isReliableSessionEnabled, MessageSecurityVersion version)
{
if (this.mode == SecurityMode.Message || this.mode == SecurityMode.TransportWithMessageCredential)
{
return this.messageSecurity.CreateSecurityBindingElement(this.Mode == SecurityMode.TransportWithMessageCredential, isReliableSessionEnabled, version);
}
else
{
return null;
}
}
internal static bool TryCreate(SecurityBindingElement sbe, UnifiedSecurityMode mode, HttpTransportSecurity transportSecurity, bool isReliableSessionEnabled, out WSHttpSecurity security)
{
security = null;
NonDualMessageSecurityOverHttp messageSecurity = null;
SecurityMode securityMode = SecurityMode.None;
if (sbe != null)
{
mode &= UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential;
securityMode = SecurityModeHelper.ToSecurityMode(mode);
DiagnosticUtility.DebugAssert(SecurityModeHelper.IsDefined(securityMode), string.Format("Invalid SecurityMode value: {0}.", mode.ToString()));
if (!MessageSecurityOverHttp.TryCreate(sbe, securityMode == SecurityMode.TransportWithMessageCredential, isReliableSessionEnabled, out messageSecurity))
{
return false;
}
}
else
{
mode &= ~(UnifiedSecurityMode.Message | UnifiedSecurityMode.TransportWithMessageCredential);
securityMode = SecurityModeHelper.ToSecurityMode(mode);
}
DiagnosticUtility.DebugAssert(SecurityModeHelper.IsDefined(securityMode), string.Format("Invalid SecurityMode value: {0}.", securityMode.ToString()));
security = new WSHttpSecurity(securityMode, transportSecurity, messageSecurity);
return true;
}
}
}
// 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
- HelpEvent.cs
- DelegatingTypeDescriptionProvider.cs
- MeasureData.cs
- ButtonAutomationPeer.cs
- CachedBitmap.cs
- StringUtil.cs
- ManagedFilter.cs
- Int32Animation.cs
- ArithmeticException.cs
- PositiveTimeSpanValidatorAttribute.cs
- ApplicationSecurityInfo.cs
- CharStorage.cs
- MetaForeignKeyColumn.cs
- OleDbMetaDataFactory.cs
- FieldToken.cs
- BlurBitmapEffect.cs
- DispatcherHooks.cs
- XmlSchemaNotation.cs
- RegisteredArrayDeclaration.cs
- EntityModelSchemaGenerator.cs
- ClientSponsor.cs
- ApplicationId.cs
- IntersectQueryOperator.cs
- HostedImpersonationContext.cs
- EdmProperty.cs
- HwndHost.cs
- Margins.cs
- SecurityUtils.cs
- MaskedTextBoxTextEditor.cs
- UnmanagedMemoryStream.cs
- SpellerHighlightLayer.cs
- figurelengthconverter.cs
- ZipFileInfo.cs
- RemoteWebConfigurationHost.cs
- SystemIPInterfaceStatistics.cs
- QilXmlWriter.cs
- ReaderOutput.cs
- ListViewGroupItemCollection.cs
- GridViewRowEventArgs.cs
- MexTcpBindingElement.cs
- SerialErrors.cs
- TemplateBindingExpressionConverter.cs
- EventMappingSettings.cs
- ByteStream.cs
- TextSearch.cs
- CookieParameter.cs
- FixedMaxHeap.cs
- ControlBindingsConverter.cs
- ProgressBarHighlightConverter.cs
- Material.cs
- RotationValidation.cs
- Panel.cs
- XmlTextReaderImpl.cs
- DataContractAttribute.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- JumpTask.cs
- BaseInfoTable.cs
- HatchBrush.cs
- TextTabProperties.cs
- SortAction.cs
- RecognitionResult.cs
- PerfCounterSection.cs
- TextParagraphView.cs
- WmpBitmapDecoder.cs
- DesignerTransaction.cs
- EmitterCache.cs
- SelectedCellsCollection.cs
- AutomationIdentifierGuids.cs
- DataGridItemCollection.cs
- LongPath.cs
- ResolveRequestResponseAsyncResult.cs
- RoleManagerSection.cs
- AttributeCollection.cs
- RowSpanVector.cs
- ComboBoxAutomationPeer.cs
- GridItemProviderWrapper.cs
- XmlBinaryReaderSession.cs
- ConfigXmlWhitespace.cs
- localization.cs
- RSAPKCS1SignatureDeformatter.cs
- WriteableBitmap.cs
- FormsIdentity.cs
- SourceElementsCollection.cs
- InternalsVisibleToAttribute.cs
- UnsafeNativeMethods.cs
- ZoneButton.cs
- ThrowHelper.cs
- GACIdentityPermission.cs
- ZipIOCentralDirectoryBlock.cs
- MonthChangedEventArgs.cs
- TreeView.cs
- TextEditorCharacters.cs
- MapPathBasedVirtualPathProvider.cs
- ContainerSelectorActiveEvent.cs
- dataSvcMapFileLoader.cs
- DataGridColumnHeadersPresenter.cs
- HttpListener.cs
- RawStylusInput.cs
- DataError.cs
- Rotation3DAnimationBase.cs