Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / WindowsStreamSecurityBindingElement.cs / 1 / WindowsStreamSecurityBindingElement.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.Collections.Generic; using System.ServiceModel.Description; using System.Net.Security; using System.ServiceModel; using System.ServiceModel.Security; using System.Xml; public class WindowsStreamSecurityBindingElement : StreamUpgradeBindingElement, ITransportTokenAssertionProvider, IPolicyExportExtension { ProtectionLevel protectionLevel; public WindowsStreamSecurityBindingElement() : base() { this.protectionLevel = ConnectionOrientedTransportDefaults.ProtectionLevel; } protected WindowsStreamSecurityBindingElement(WindowsStreamSecurityBindingElement elementToBeCloned) : base(elementToBeCloned) { this.protectionLevel = elementToBeCloned.protectionLevel; } public ProtectionLevel ProtectionLevel { get { return this.protectionLevel; } set { ProtectionLevelHelper.Validate(value); this.protectionLevel = value; } } public override BindingElement Clone() { return new WindowsStreamSecurityBindingElement(this); } public override IChannelFactoryBuildChannelFactory (BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } #pragma warning suppress 56506 // [....], BindingContext.BindingParameters cannot be null context.BindingParameters.Add(this); return context.BuildInnerChannelFactory (); } public override bool CanBuildChannelFactory (BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } #pragma warning suppress 56506 // [....], BindingContext.BindingParameters cannot be null context.BindingParameters.Add(this); return context.CanBuildInnerChannelFactory (); } public override IChannelListener BuildChannelListener (BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } #pragma warning suppress 56506 // [....], BindingContext.BindingParameters cannot be null context.BindingParameters.Add(this); return context.BuildInnerChannelListener (); } public override bool CanBuildChannelListener (BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } #pragma warning suppress 56506 // [....], BindingContext.BindingParameters cannot be null context.BindingParameters.Add(this); return context.CanBuildInnerChannelListener (); } public override StreamUpgradeProvider BuildClientStreamUpgradeProvider(BindingContext context) { return new WindowsStreamSecurityUpgradeProvider(this, context, true); } public override StreamUpgradeProvider BuildServerStreamUpgradeProvider(BindingContext context) { return new WindowsStreamSecurityUpgradeProvider(this, context, false); } public override T GetProperty (BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (typeof(T) == typeof(ISecurityCapabilities)) { return (T)(object)new SecurityCapabilities(true, true, true, protectionLevel, protectionLevel); } else if (typeof(T) == typeof(IdentityVerifier)) { return (T)(object)IdentityVerifier.CreateDefault(); } else { return context.GetInnerProperty (); } } internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { XmlElement assertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), TransportPolicyConstants.WindowsTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace, true); if (assertion != null) { WindowsStreamSecurityBindingElement windowsBindingElement = new WindowsStreamSecurityBindingElement(); XmlReader reader = new XmlNodeReader(assertion); reader.ReadStartElement(); string protectionLevelString = null; if (reader.IsStartElement( TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace) && !reader.IsEmptyElement) { protectionLevelString = reader.ReadElementContentAsString(); } if (string.IsNullOrEmpty(protectionLevelString)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException( SR.GetString(SR.ExpectedElementMissing, TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace))); } windowsBindingElement.ProtectionLevel = (ProtectionLevel)Enum.Parse(typeof(ProtectionLevel), protectionLevelString); policyContext.BindingElements.Add(windowsBindingElement); } } #region ITransportTokenAssertionProvider Members public XmlElement GetTransportTokenAssertion() { XmlDocument document = new XmlDocument(); XmlElement assertion = document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix, TransportPolicyConstants.WindowsTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace); XmlElement protectionLevelElement = document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix, TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace); protectionLevelElement.AppendChild(document.CreateTextNode(this.ProtectionLevel.ToString())); assertion.AppendChild(protectionLevelElement); return assertion; } #endregion void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) { if (exporter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exporter"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } SecurityBindingElement.ExportPolicy(exporter, context); } internal override bool IsMatch(BindingElement b) { if (b == null) { return false; } WindowsStreamSecurityBindingElement security = b as WindowsStreamSecurityBindingElement; if (security == null) { return false; } if (this.protectionLevel != security.protectionLevel) { return false; } 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
- ClaimSet.cs
- StyleCollection.cs
- ListParagraph.cs
- OuterGlowBitmapEffect.cs
- CurrentChangingEventArgs.cs
- Size3D.cs
- EventLevel.cs
- SmtpSection.cs
- FindCriteria11.cs
- RowsCopiedEventArgs.cs
- FigureParagraph.cs
- DataControlReferenceCollection.cs
- X509CertificateChain.cs
- HandlerBase.cs
- ProfilePropertySettingsCollection.cs
- NetworkInformationPermission.cs
- SqlCacheDependencySection.cs
- DefaultPropertiesToSend.cs
- DataGridCaption.cs
- OrderPreservingPipeliningSpoolingTask.cs
- IfElseDesigner.xaml.cs
- _ConnectOverlappedAsyncResult.cs
- SafeSystemMetrics.cs
- SQLSingle.cs
- ActiveXHost.cs
- DataGridViewCheckBoxColumn.cs
- _FixedSizeReader.cs
- TabletCollection.cs
- PackagingUtilities.cs
- RectangleHotSpot.cs
- ContentPresenter.cs
- WpfWebRequestHelper.cs
- DataSet.cs
- FontUnit.cs
- TreeNodeMouseHoverEvent.cs
- TypeLibConverter.cs
- DecoderFallback.cs
- FreezableDefaultValueFactory.cs
- ServiceBuildProvider.cs
- Int64Converter.cs
- SwitchElementsCollection.cs
- ResourcePermissionBaseEntry.cs
- IgnoreDeviceFilterElementCollection.cs
- Label.cs
- InfoCardRSACryptoProvider.cs
- DecoderFallback.cs
- AlphabeticalEnumConverter.cs
- ObjectViewEntityCollectionData.cs
- DiscoveryClientReferences.cs
- ItemChangedEventArgs.cs
- Margins.cs
- DeflateStream.cs
- InternalException.cs
- ResXResourceWriter.cs
- MenuEventArgs.cs
- StatementContext.cs
- SingleObjectCollection.cs
- NativeMethods.cs
- FixedDocument.cs
- CompressStream.cs
- RegexCapture.cs
- FixedSOMTableRow.cs
- returneventsaver.cs
- NativeCppClassAttribute.cs
- EncryptedKeyIdentifierClause.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- GroupBoxAutomationPeer.cs
- UInt32Converter.cs
- OperationExecutionFault.cs
- TrackPoint.cs
- UseLicense.cs
- Calendar.cs
- SqlBooleanizer.cs
- VersionPair.cs
- Request.cs
- SqlUdtInfo.cs
- FormsAuthenticationUserCollection.cs
- DataPager.cs
- DirectoryGroupQuery.cs
- DiscreteKeyFrames.cs
- ObjectQuery.cs
- TcpChannelListener.cs
- CustomActivityDesigner.cs
- NativeMethods.cs
- CustomLineCap.cs
- EntityDataSourceWizardForm.cs
- HMAC.cs
- CommandManager.cs
- StructuredTypeInfo.cs
- DragStartedEventArgs.cs
- JapaneseLunisolarCalendar.cs
- FieldBuilder.cs
- Vector3DCollectionConverter.cs
- LassoHelper.cs
- PackageRelationshipCollection.cs
- TimeSpanValidatorAttribute.cs
- ZipIOExtraFieldZip64Element.cs
- SafeRegistryHandle.cs
- DBConnection.cs
- CultureSpecificStringDictionary.cs