Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / MessageSecurityProtocolFactory.cs / 1 / MessageSecurityProtocolFactory.cs
//----------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.Collections.Generic;
using System.ServiceModel;
using System.IO;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Selectors;
using System.Security.Cryptography;
using System.ServiceModel.Channels;
using System.ServiceModel.Security.Tokens;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Net.Security;
abstract class MessageSecurityProtocolFactory : SecurityProtocolFactory
{
internal const MessageProtectionOrder defaultMessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
internal const bool defaultDoRequestSignatureConfirmation = false;
bool applyIntegrity = true;
bool applyConfidentiality = true;
bool doRequestSignatureConfirmation = defaultDoRequestSignatureConfirmation;
IdentityVerifier identityVerifier;
ChannelProtectionRequirements protectionRequirements = new ChannelProtectionRequirements();
MessageProtectionOrder messageProtectionOrder = defaultMessageProtectionOrder;
bool requireIntegrity = true;
bool requireConfidentiality = true;
List wrappedKeyTokenAuthenticator;
protected MessageSecurityProtocolFactory()
{
}
internal MessageSecurityProtocolFactory(MessageSecurityProtocolFactory factory)
: base(factory)
{
if (factory == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("factory");
this.applyIntegrity = factory.applyIntegrity;
this.applyConfidentiality = factory.applyConfidentiality;
this.identityVerifier = factory.identityVerifier;
this.protectionRequirements = new ChannelProtectionRequirements(factory.protectionRequirements);
this.messageProtectionOrder = factory.messageProtectionOrder;
this.requireIntegrity = factory.requireIntegrity;
this.requireConfidentiality = factory.requireConfidentiality;
this.doRequestSignatureConfirmation = factory.doRequestSignatureConfirmation;
}
public bool ApplyConfidentiality
{
get
{
return this.applyConfidentiality;
}
set
{
ThrowIfImmutable();
this.applyConfidentiality = value;
}
}
public bool ApplyIntegrity
{
get
{
return this.applyIntegrity;
}
set
{
ThrowIfImmutable();
this.applyIntegrity = value;
}
}
public bool DoRequestSignatureConfirmation
{
get
{
return this.doRequestSignatureConfirmation;
}
set
{
ThrowIfImmutable();
this.doRequestSignatureConfirmation = value;
}
}
public IdentityVerifier IdentityVerifier
{
get
{
return this.identityVerifier;
}
set
{
ThrowIfImmutable();
this.identityVerifier = value;
}
}
public ChannelProtectionRequirements ProtectionRequirements
{
get
{
return this.protectionRequirements;
}
}
public MessageProtectionOrder MessageProtectionOrder
{
get
{
return this.messageProtectionOrder;
}
set
{
ThrowIfImmutable();
this.messageProtectionOrder = value;
}
}
public bool RequireIntegrity
{
get
{
return this.requireIntegrity;
}
set
{
ThrowIfImmutable();
this.requireIntegrity = value;
}
}
public bool RequireConfidentiality
{
get
{
return this.requireConfidentiality;
}
set
{
ThrowIfImmutable();
this.requireConfidentiality = value;
}
}
internal List WrappedKeySecurityTokenAuthenticator
{
get
{
return this.wrappedKeyTokenAuthenticator;
}
}
protected virtual void ValidateCorrelationSecuritySettings()
{
if (this.ActAsInitiator && this.SupportsRequestReply)
{
bool savesCorrelationTokenOnRequest = this.ApplyIntegrity || this.ApplyConfidentiality;
bool needsCorrelationTokenOnReply = this.RequireIntegrity || this.RequireConfidentiality;
if (!savesCorrelationTokenOnRequest && needsCorrelationTokenOnReply)
{
OnPropertySettingsError("ApplyIntegrity", false);
}
}
}
public override void OnOpen(TimeSpan timeout)
{
base.OnOpen(timeout);
this.protectionRequirements.MakeReadOnly();
if (this.DetectReplays && !this.RequireIntegrity)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("RequireIntegrity", SR.GetString(SR.ForReplayDetectionToBeDoneRequireIntegrityMustBeSet));
}
if (this.DoRequestSignatureConfirmation)
{
if (!this.SupportsRequestReply)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SignatureConfirmationRequiresRequestReply));
}
if (!this.StandardsManager.SecurityVersion.SupportsSignatureConfirmation)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SecurityVersionDoesNotSupportSignatureConfirmation, this.StandardsManager.SecurityVersion));
}
}
this.wrappedKeyTokenAuthenticator = new List(1);
SecurityTokenAuthenticator authenticator = new NonValidatingSecurityTokenAuthenticator();
this.wrappedKeyTokenAuthenticator.Add(authenticator);
ValidateCorrelationSecuritySettings();
}
static MessagePartSpecification ExtractMessageParts(string action,
ScopedMessagePartSpecification scopedParts, bool isForSignature)
{
MessagePartSpecification parts = null;
if (scopedParts.TryGetParts(action, out parts))
{
return parts;
}
else if (scopedParts.TryGetParts(MessageHeaders.WildcardAction, out parts))
{
return parts;
}
// send back a fault indication that the action is unknown
SecurityVersion wss = MessageSecurityVersion.Default.SecurityVersion;
FaultCode subCode = new FaultCode(wss.InvalidSecurityFaultCode.Value, wss.HeaderNamespace.Value);
FaultCode senderCode = FaultCode.CreateSenderFaultCode(subCode);
FaultReason reason = new FaultReason(SR.GetString(SR.InvalidOrUnrecognizedAction, action), System.Globalization.CultureInfo.CurrentCulture);
MessageFault fault = MessageFault.CreateFault(senderCode, reason);
if (isForSignature)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.NoSignaturePartsSpecified, action), null, fault));
}
else
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MessageSecurityException(SR.GetString(SR.NoEncryptionPartsSpecified, action), null, fault));
}
}
internal MessagePartSpecification GetIncomingEncryptionParts(string action)
{
if (this.RequireConfidentiality)
{
//return ExtractMessageParts(action, (this.SecurityTokenManager is ClientCredentialsSecurityTokenManager) ? this.ProtectionRequirements.OutgoingEncryptionParts : this.ProtectionRequirements.IncomingEncryptionParts, false);
if ( this.IsDuplexReply )
return ExtractMessageParts(action, this.ProtectionRequirements.OutgoingEncryptionParts , false);
else
return ExtractMessageParts(action, (this.ActAsInitiator) ? this.ProtectionRequirements.OutgoingEncryptionParts : this.ProtectionRequirements.IncomingEncryptionParts, false);
}
else
{
return MessagePartSpecification.NoParts;
}
}
internal MessagePartSpecification GetIncomingSignatureParts(string action)
{
if (this.RequireIntegrity)
{
//return ExtractMessageParts(action, (this.SecurityTokenManager is ClientCredentialsSecurityTokenManager) ? this.ProtectionRequirements.OutgoingSignatureParts : this.ProtectionRequirements.IncomingSignatureParts, true);
if ( this.IsDuplexReply )
return ExtractMessageParts(action, this.ProtectionRequirements.OutgoingSignatureParts, true);
else
return ExtractMessageParts(action, (this.ActAsInitiator) ? this.ProtectionRequirements.OutgoingSignatureParts : this.ProtectionRequirements.IncomingSignatureParts, true);
}
else
{
return MessagePartSpecification.NoParts;
}
}
internal MessagePartSpecification GetOutgoingEncryptionParts(string action)
{
if (this.ApplyConfidentiality)
{
//return ExtractMessageParts(action, (this.SecurityTokenManager is ClientCredentialsSecurityTokenManager) ? this.ProtectionRequirements.IncomingEncryptionParts : this.ProtectionRequirements.OutgoingEncryptionParts, false);
if ( this.IsDuplexReply )
return ExtractMessageParts(action, this.ProtectionRequirements.OutgoingEncryptionParts, false);
else
return ExtractMessageParts(action, (this.ActAsInitiator) ? this.ProtectionRequirements.IncomingEncryptionParts : this.ProtectionRequirements.OutgoingEncryptionParts, false);
}
else
{
return MessagePartSpecification.NoParts;
}
}
internal MessagePartSpecification GetOutgoingSignatureParts(string action)
{
if (this.ApplyIntegrity)
{
//return ExtractMessageParts(action, (this.SecurityTokenManager is ClientCredentialsSecurityTokenManager) ? this.ProtectionRequirements.IncomingSignatureParts : this.ProtectionRequirements.OutgoingSignatureParts, true);
if ( this.IsDuplexReply )
return ExtractMessageParts(action, this.ProtectionRequirements.OutgoingSignatureParts, true);
else
return ExtractMessageParts(action, (this.ActAsInitiator) ? this.ProtectionRequirements.IncomingSignatureParts : this.ProtectionRequirements.OutgoingSignatureParts, true);
}
else
{
return MessagePartSpecification.NoParts;
}
}
}
}
// 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
- SqlTrackingWorkflowInstance.cs
- ParameterBinding.cs
- AttributeExtensions.cs
- CircleEase.cs
- ObjectSecurity.cs
- ListViewUpdatedEventArgs.cs
- PolicyStatement.cs
- NamespaceCollection.cs
- odbcmetadatacollectionnames.cs
- SqlDataAdapter.cs
- glyphs.cs
- BrowserInteropHelper.cs
- BackgroundWorker.cs
- FrameworkElementFactory.cs
- AssemblyEvidenceFactory.cs
- DecimalStorage.cs
- SimpleWorkerRequest.cs
- NamespaceTable.cs
- SelectionProviderWrapper.cs
- VersionPair.cs
- ListViewInsertedEventArgs.cs
- DependencyPropertyKind.cs
- ToolStripMenuItem.cs
- WebBrowserEvent.cs
- EncodingStreamWrapper.cs
- DataSourceCollectionBase.cs
- Vector3DConverter.cs
- XmlValueConverter.cs
- SmtpTransport.cs
- DropShadowBitmapEffect.cs
- OdbcConnectionOpen.cs
- DesignerWidgets.cs
- AsyncOperation.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- SiteMapNodeItem.cs
- ChildrenQuery.cs
- StringConverter.cs
- XmlNodeComparer.cs
- ResXDataNode.cs
- SerialPort.cs
- PrintEvent.cs
- CroppedBitmap.cs
- ExclusiveCanonicalizationTransform.cs
- EntryIndex.cs
- Rectangle.cs
- EventPrivateKey.cs
- DictionaryEntry.cs
- TaskFactory.cs
- initElementDictionary.cs
- LayoutEvent.cs
- EventBindingService.cs
- _UncName.cs
- SqlCacheDependencyDatabaseCollection.cs
- DrawingContextDrawingContextWalker.cs
- VirtualPathProvider.cs
- DesignerSerializerAttribute.cs
- ThreadPool.cs
- SafeEventLogWriteHandle.cs
- PartBasedPackageProperties.cs
- GPRECT.cs
- XPathNavigatorKeyComparer.cs
- SemanticResolver.cs
- XmlMembersMapping.cs
- XmlILTrace.cs
- AddInContractAttribute.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- PointLightBase.cs
- mactripleDES.cs
- FileUpload.cs
- RadioButton.cs
- ReaderContextStackData.cs
- BoundPropertyEntry.cs
- TypedDataSetSchemaImporterExtension.cs
- GetPageCompletedEventArgs.cs
- ColorPalette.cs
- StdValidatorsAndConverters.cs
- AmbientProperties.cs
- DataBindingList.cs
- HttpHandlersSection.cs
- ImageSource.cs
- Facet.cs
- ParameterModifier.cs
- MD5CryptoServiceProvider.cs
- SoapEnvelopeProcessingElement.cs
- SapiAttributeParser.cs
- ColorBuilder.cs
- DbDataReader.cs
- ListViewInsertionMark.cs
- SocketConnection.cs
- DbDataAdapter.cs
- XamlRtfConverter.cs
- TouchesOverProperty.cs
- ValidatingPropertiesEventArgs.cs
- XPathNode.cs
- RSAOAEPKeyExchangeFormatter.cs
- TextBox.cs
- ProfilePropertyNameValidator.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- DynamicValueConverter.cs
- ErrorEventArgs.cs