Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / BasicHttpMessageSecurity.cs / 1 / BasicHttpMessageSecurity.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System.Net.Security; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.ServiceModel.Security.Tokens; public sealed class BasicHttpMessageSecurity { internal const BasicHttpMessageCredentialType DefaultClientCredentialType = BasicHttpMessageCredentialType.UserName; BasicHttpMessageCredentialType clientCredentialType; SecurityAlgorithmSuite algorithmSuite; internal BasicHttpMessageSecurity() { clientCredentialType = DefaultClientCredentialType; algorithmSuite = SecurityAlgorithmSuite.Default; } public BasicHttpMessageCredentialType ClientCredentialType { get { return this.clientCredentialType; } set { if (!BasicHttpMessageCredentialTypeHelper.IsDefined(value)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value")); } this.clientCredentialType = value; } } public SecurityAlgorithmSuite AlgorithmSuite { get { return this.algorithmSuite; } set { if (value == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value"); } this.algorithmSuite = value; } } // if any changes are made to this method, please reflect them in the corresponding TryCrete() method internal SecurityBindingElement CreateMessageSecurity(bool isSecureTransportMode) { SecurityBindingElement result; if (isSecureTransportMode) { MessageSecurityVersion version = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; switch (this.clientCredentialType) { case BasicHttpMessageCredentialType.Certificate: result = SecurityBindingElement.CreateCertificateOverTransportBindingElement(version); break; case BasicHttpMessageCredentialType.UserName: result = SecurityBindingElement.CreateUserNameOverTransportBindingElement(); result.MessageSecurityVersion = version; break; default: DiagnosticUtility.DebugAssert("Unsupported basic http message credential type"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException()); } } else { if (this.clientCredentialType != BasicHttpMessageCredentialType.Certificate) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.BasicHttpMessageSecurityRequiresCertificate))); } result = SecurityBindingElement.CreateMutualCertificateBindingElement(MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10, true); } result.DefaultAlgorithmSuite = this.AlgorithmSuite; result.SecurityHeaderLayout = SecurityHeaderLayout.Lax; result.SetKeyDerivation(false); result.DoNotEmitTrust = true; return result; } // This method reverses the CreateMessageSecurity(bool) method internal static bool TryCreate(SecurityBindingElement sbe, out BasicHttpMessageSecurity security, out bool isSecureTransportMode) { DiagnosticUtility.DebugAssert(null != sbe, string.Empty); security = null; isSecureTransportMode = false; if (sbe.DoNotEmitTrust == false) return false; if (!sbe.IsSetKeyDerivation(false)) return false; if (sbe.SecurityHeaderLayout != SecurityHeaderLayout.Lax) return false; if (sbe.MessageSecurityVersion != MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10) return false; BasicHttpMessageCredentialType credentialType; if (!SecurityBindingElement.IsMutualCertificateBinding(sbe, true)) { isSecureTransportMode = true; if (SecurityBindingElement.IsCertificateOverTransportBinding(sbe)) { credentialType = BasicHttpMessageCredentialType.Certificate; } else if (SecurityBindingElement.IsUserNameOverTransportBinding(sbe)) { credentialType = BasicHttpMessageCredentialType.UserName; } else { return false; } } else { credentialType = BasicHttpMessageCredentialType.Certificate; } security = new BasicHttpMessageSecurity(); security.ClientCredentialType = credentialType; security.AlgorithmSuite = sbe.DefaultAlgorithmSuite; 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
- SqlClientPermission.cs
- VisualStyleRenderer.cs
- XmlCharacterData.cs
- TableParaClient.cs
- ConvertersCollection.cs
- SqlPersistenceWorkflowInstanceDescription.cs
- ContentDisposition.cs
- RegionInfo.cs
- Int16.cs
- SqlCacheDependency.cs
- Pair.cs
- DateTimeOffset.cs
- TextShapeableCharacters.cs
- UnsafeNativeMethods.cs
- smtpconnection.cs
- MetadataResolver.cs
- AVElementHelper.cs
- StorageMappingFragment.cs
- SecurityTokenInclusionMode.cs
- EndpointDispatcher.cs
- BitmapEffectGroup.cs
- TextDataBindingHandler.cs
- SerializableAttribute.cs
- FontConverter.cs
- DataRecordInternal.cs
- DataGridCellItemAutomationPeer.cs
- SystemNetHelpers.cs
- Blend.cs
- QueryCacheManager.cs
- SqlProviderServices.cs
- XamlValidatingReader.cs
- UniqueConstraint.cs
- WorkflowMarkupSerializationException.cs
- _TimerThread.cs
- OdbcPermission.cs
- RemotingException.cs
- CheckPair.cs
- DataViewListener.cs
- IOThreadTimer.cs
- ImageCollectionCodeDomSerializer.cs
- OperandQuery.cs
- MarkupWriter.cs
- AutomationPropertyInfo.cs
- UIElementAutomationPeer.cs
- ArgIterator.cs
- EpmContentSerializerBase.cs
- InteropBitmapSource.cs
- BitmapSource.cs
- ObjectListCommandsPage.cs
- UriParserTemplates.cs
- Shape.cs
- WebPartDisplayModeCancelEventArgs.cs
- TerminatorSinks.cs
- InteropBitmapSource.cs
- ReachDocumentPageSerializer.cs
- ListViewItem.cs
- XmlSchema.cs
- HandoffBehavior.cs
- SmtpFailedRecipientsException.cs
- SmiEventStream.cs
- BitmapMetadata.cs
- ComUdtElementCollection.cs
- ListControlDataBindingHandler.cs
- PointAnimationUsingPath.cs
- SatelliteContractVersionAttribute.cs
- WebServiceParameterData.cs
- RequiredFieldValidator.cs
- SchemaSetCompiler.cs
- NamedPipeChannelFactory.cs
- UIElement3D.cs
- Clause.cs
- SqlParameter.cs
- FontFamilyValueSerializer.cs
- CurrencyWrapper.cs
- DiscoveryClientChannelFactory.cs
- ExtensionQuery.cs
- XmlSerializationWriter.cs
- ParserExtension.cs
- WaitHandle.cs
- TableCellAutomationPeer.cs
- ExtensionDataObject.cs
- XmlQueryContext.cs
- StylusDevice.cs
- FieldBuilder.cs
- AppDomainAttributes.cs
- BasicKeyConstraint.cs
- InvalidOperationException.cs
- Pkcs7Signer.cs
- Control.cs
- EntityDataSourceDataSelection.cs
- RenderData.cs
- ClientSponsor.cs
- DictionarySectionHandler.cs
- HttpRawResponse.cs
- CodeVariableDeclarationStatement.cs
- SmtpReplyReader.cs
- RtfNavigator.cs
- ProtocolsConfigurationEntry.cs
- Facet.cs
- NumberFormatInfo.cs