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; ListwrappedKeyTokenAuthenticator; 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
- SafeNativeMethods.cs
- DrawingAttributeSerializer.cs
- SqlBulkCopy.cs
- StrongNameUtility.cs
- recordstatescratchpad.cs
- TransportReplyChannelAcceptor.cs
- Socket.cs
- ServiceDocumentFormatter.cs
- FixedSOMPageConstructor.cs
- SourceInterpreter.cs
- EntityDesignerUtils.cs
- MailDefinitionBodyFileNameEditor.cs
- StreamInfo.cs
- MimeTextImporter.cs
- DataGridTablesFactory.cs
- DescendantBaseQuery.cs
- SafeNativeMethodsMilCoreApi.cs
- ServiceDebugBehavior.cs
- AudioSignalProblemOccurredEventArgs.cs
- PaperSize.cs
- PeerNameResolver.cs
- XsltLoader.cs
- ThicknessKeyFrameCollection.cs
- InputMethod.cs
- SingleKeyFrameCollection.cs
- HijriCalendar.cs
- GridViewDesigner.cs
- WinEventTracker.cs
- WebControlsSection.cs
- DataServiceResponse.cs
- HtmlLinkAdapter.cs
- MimeTextImporter.cs
- TextBox.cs
- ListenerAdapter.cs
- XmlHierarchicalEnumerable.cs
- EntityViewContainer.cs
- SetIterators.cs
- PeekCompletedEventArgs.cs
- IntegerValidatorAttribute.cs
- BidPrivateBase.cs
- OLEDB_Util.cs
- xmlfixedPageInfo.cs
- AdapterUtil.cs
- ToolStripStatusLabel.cs
- SqlVersion.cs
- StateFinalizationDesigner.cs
- StreamingContext.cs
- HttpDebugHandler.cs
- EntitySqlQueryState.cs
- RoutedEvent.cs
- ColorAnimationBase.cs
- StrokeNodeData.cs
- AsyncCompletedEventArgs.cs
- ProxyManager.cs
- DataGridViewDataConnection.cs
- ExpressionBinding.cs
- _ConnectionGroup.cs
- ScrollBarAutomationPeer.cs
- OdbcHandle.cs
- ComplexTypeEmitter.cs
- StringSorter.cs
- DataSourceControlBuilder.cs
- DoubleAnimationClockResource.cs
- WebProxyScriptElement.cs
- PowerModeChangedEventArgs.cs
- unitconverter.cs
- FormsAuthenticationModule.cs
- CodeExpressionRuleDeclaration.cs
- TdsParameterSetter.cs
- WSSecurityPolicy11.cs
- UserPersonalizationStateInfo.cs
- SHA256Managed.cs
- PublisherMembershipCondition.cs
- PointLightBase.cs
- SAPICategories.cs
- CssStyleCollection.cs
- DispatcherFrame.cs
- RSAPKCS1KeyExchangeFormatter.cs
- SqlGatherConsumedAliases.cs
- XmlNamespaceManager.cs
- Pen.cs
- ListControlConvertEventArgs.cs
- ConfigurationLocationCollection.cs
- FontStyle.cs
- TimelineCollection.cs
- WorkItem.cs
- MouseActionConverter.cs
- DocumentAutomationPeer.cs
- TabRenderer.cs
- DataGridColumnCollection.cs
- RootBrowserWindow.cs
- SystemException.cs
- SQLDecimalStorage.cs
- AdPostCacheSubstitution.cs
- StyleSelector.cs
- BinaryReader.cs
- TextPointer.cs
- InputEventArgs.cs
- Size3DValueSerializer.cs
- AnnotationComponentChooser.cs