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
- SoapCodeExporter.cs
- TextViewBase.cs
- PixelFormat.cs
- CellTreeNodeVisitors.cs
- RectangleF.cs
- PropertyNames.cs
- Expression.cs
- Literal.cs
- BasicCellRelation.cs
- _ContextAwareResult.cs
- Int16.cs
- IsolatedStoragePermission.cs
- RotateTransform.cs
- EventHandlerList.cs
- ReferenceList.cs
- VisualStyleTypesAndProperties.cs
- WebControlParameterProxy.cs
- EntityDataSourceDesigner.cs
- Activator.cs
- TrackingParticipant.cs
- COM2PictureConverter.cs
- DataBoundLiteralControl.cs
- ProfileManager.cs
- DecoderNLS.cs
- InheritanceAttribute.cs
- MethodBuilderInstantiation.cs
- CompilerParameters.cs
- CompositeActivityValidator.cs
- CompilerHelpers.cs
- HiddenFieldPageStatePersister.cs
- TextSelectionHighlightLayer.cs
- BitmapEffectDrawing.cs
- JumpTask.cs
- PrintSchema.cs
- _NestedMultipleAsyncResult.cs
- Switch.cs
- SecurityRuntime.cs
- SQLSingle.cs
- DataStorage.cs
- OleStrCAMarshaler.cs
- EventToken.cs
- DPCustomTypeDescriptor.cs
- PageAsyncTaskManager.cs
- TrackPointCollection.cs
- PropertyPathWorker.cs
- IndexedString.cs
- LifetimeServices.cs
- WebOperationContext.cs
- ResourceDisplayNameAttribute.cs
- Facet.cs
- Int32Rect.cs
- EntityCommand.cs
- HttpStreamFormatter.cs
- ToolStripContentPanelRenderEventArgs.cs
- HtmlAnchor.cs
- TreeViewImageIndexConverter.cs
- TreeNode.cs
- NameValueFileSectionHandler.cs
- METAHEADER.cs
- LookupNode.cs
- ParenExpr.cs
- PointCollectionValueSerializer.cs
- HttpDictionary.cs
- SignatureToken.cs
- SspiHelper.cs
- WSSecurityOneDotZeroSendSecurityHeader.cs
- RestHandlerFactory.cs
- TemplateApplicationHelper.cs
- LiteralLink.cs
- DeclarationUpdate.cs
- XmlNamespaceMapping.cs
- AssemblyBuilder.cs
- URLString.cs
- SiteMapNodeItemEventArgs.cs
- ToolboxDataAttribute.cs
- DefaultSerializationProviderAttribute.cs
- WebPartTracker.cs
- MethodAccessException.cs
- WindowsStatusBar.cs
- SqlNotificationRequest.cs
- WebPartConnectionsDisconnectVerb.cs
- ReachFixedDocumentSerializer.cs
- RotateTransform.cs
- OdbcStatementHandle.cs
- ItemDragEvent.cs
- SQLResource.cs
- HttpCookie.cs
- sortedlist.cs
- LinearKeyFrames.cs
- MailWebEventProvider.cs
- CodeDirectoryCompiler.cs
- SerializationHelper.cs
- DictionaryBase.cs
- WebDescriptionAttribute.cs
- StateBag.cs
- TextProperties.cs
- HttpModuleCollection.cs
- OdbcTransaction.cs
- HttpsTransportBindingElement.cs
- listitem.cs