Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / SslStreamSecurityBindingElement.cs / 1 / SslStreamSecurityBindingElement.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.ServiceModel.Security.Tokens; using System.Xml; public class SslStreamSecurityBindingElement : StreamUpgradeBindingElement, ITransportTokenAssertionProvider, IPolicyExportExtension { IdentityVerifier identityVerifier; bool requireClientCertificate; public SslStreamSecurityBindingElement() { this.requireClientCertificate = TransportDefaults.RequireClientCertificate; } protected SslStreamSecurityBindingElement(SslStreamSecurityBindingElement elementToBeCloned) : base(elementToBeCloned) { this.identityVerifier = elementToBeCloned.identityVerifier; this.requireClientCertificate = elementToBeCloned.requireClientCertificate; } public IdentityVerifier IdentityVerifier { get { if (this.identityVerifier == null) { this.identityVerifier = IdentityVerifier.CreateDefault(); } return this.identityVerifier; } set { if (value == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); } this.identityVerifier = value; } } public bool RequireClientCertificate { get { return this.requireClientCertificate; } set { this.requireClientCertificate = value; } } 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 BindingElement Clone() { return new SslStreamSecurityBindingElement(this); } public override T GetProperty (BindingContext context) { if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } if (typeof(T) == typeof(ISecurityCapabilities)) { return (T)(object)new SecurityCapabilities(this.RequireClientCertificate, true, this.RequireClientCertificate, ProtectionLevel.EncryptAndSign, ProtectionLevel.EncryptAndSign); } else if (typeof(T) == typeof(IdentityVerifier)) { return (T)(object)this.IdentityVerifier; } else { return context.GetInnerProperty (); } } public override StreamUpgradeProvider BuildClientStreamUpgradeProvider(BindingContext context) { return SslStreamSecurityUpgradeProvider.CreateClientProvider(this, context); } public override StreamUpgradeProvider BuildServerStreamUpgradeProvider(BindingContext context) { return SslStreamSecurityUpgradeProvider.CreateServerProvider(this, context); } internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { XmlElement assertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), TransportPolicyConstants.SslTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace, true); if (assertion != null) { SslStreamSecurityBindingElement sslBindingElement = new SslStreamSecurityBindingElement(); XmlReader reader = new XmlNodeReader(assertion); reader.ReadStartElement(); sslBindingElement.RequireClientCertificate = reader.IsStartElement( TransportPolicyConstants.RequireClientCertificateName, TransportPolicyConstants.DotNetFramingNamespace); if (sslBindingElement.RequireClientCertificate) { reader.ReadElementString(); } policyContext.BindingElements.Add(sslBindingElement); } } #region ITransportTokenAssertionProvider Members public XmlElement GetTransportTokenAssertion() { XmlDocument document = new XmlDocument(); XmlElement assertion = document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix, TransportPolicyConstants.SslTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace); if (this.requireClientCertificate) { assertion.AppendChild(document.CreateElement(TransportPolicyConstants.DotNetFramingPrefix, TransportPolicyConstants.RequireClientCertificateName, TransportPolicyConstants.DotNetFramingNamespace)); } 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; } SslStreamSecurityBindingElement ssl = b as SslStreamSecurityBindingElement; if (ssl == null) { return false; } return this.requireClientCertificate == ssl.requireClientCertificate; } } } // 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
- sqlser.cs
- SessionSwitchEventArgs.cs
- Substitution.cs
- InkPresenter.cs
- XmlIncludeAttribute.cs
- ScriptingProfileServiceSection.cs
- MultiSelectRootGridEntry.cs
- RowVisual.cs
- Vector3DCollectionConverter.cs
- SlipBehavior.cs
- MetadataHelper.cs
- PropertyItem.cs
- CollectionDataContractAttribute.cs
- GroupItem.cs
- ToolStripItemImageRenderEventArgs.cs
- DllNotFoundException.cs
- InvokeWebServiceDesigner.cs
- contentDescriptor.cs
- PropertyGeneratedEventArgs.cs
- ToolboxItemSnapLineBehavior.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- ServiceHostingEnvironment.cs
- KeyPullup.cs
- WebPartCloseVerb.cs
- QueryCacheEntry.cs
- Privilege.cs
- MemberHolder.cs
- ListSortDescription.cs
- NavigationProgressEventArgs.cs
- AxisAngleRotation3D.cs
- FixedPageAutomationPeer.cs
- RuntimeIdentifierPropertyAttribute.cs
- SystemFonts.cs
- RuntimeArgument.cs
- ProcessHostFactoryHelper.cs
- XamlPoint3DCollectionSerializer.cs
- Visual3D.cs
- XamlTypeMapperSchemaContext.cs
- SQLCharsStorage.cs
- DataComponentMethodGenerator.cs
- SpAudioStreamWrapper.cs
- Annotation.cs
- JournalEntryStack.cs
- WebHttpDispatchOperationSelectorData.cs
- SchemaConstraints.cs
- BitmapCodecInfo.cs
- CodePropertyReferenceExpression.cs
- FrameworkRichTextComposition.cs
- AutomationEventArgs.cs
- relpropertyhelper.cs
- DetailsViewPageEventArgs.cs
- ValueType.cs
- DescendantOverDescendantQuery.cs
- QilReference.cs
- WebZone.cs
- LogReservationCollection.cs
- WebEventTraceProvider.cs
- CodeArrayIndexerExpression.cs
- EntityDesignerUtils.cs
- TemplateKey.cs
- BitmapSource.cs
- XmlArrayAttribute.cs
- ValidatorCompatibilityHelper.cs
- Identity.cs
- ProcessHostServerConfig.cs
- TypeConverterMarkupExtension.cs
- StaticContext.cs
- PostBackOptions.cs
- InvalidFilterCriteriaException.cs
- AdornerHitTestResult.cs
- MappingMetadataHelper.cs
- RSAOAEPKeyExchangeDeformatter.cs
- ProjectionQueryOptionExpression.cs
- MetaForeignKeyColumn.cs
- LogEntryHeaderSerializer.cs
- StrokeNodeOperations2.cs
- HostingPreferredMapPath.cs
- ListViewHitTestInfo.cs
- MergablePropertyAttribute.cs
- ChildrenQuery.cs
- SiteMapNode.cs
- PointAnimationUsingPath.cs
- CapabilitiesPattern.cs
- ApplicationFileCodeDomTreeGenerator.cs
- XslTransform.cs
- SecurityUtils.cs
- ExceptionUtil.cs
- HttpContextServiceHost.cs
- CheckBoxAutomationPeer.cs
- BufferedGraphicsManager.cs
- XMLSyntaxException.cs
- SqlConnectionPoolProviderInfo.cs
- CommandPlan.cs
- EntityDataSourceColumn.cs
- XMLUtil.cs
- UrlMappingCollection.cs
- WsatAdminException.cs
- DataGridViewTextBoxColumn.cs
- CategoryEditor.cs
- DialogDivider.cs