Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / DuplexSecurityProtocolFactory.cs / 1 / DuplexSecurityProtocolFactory.cs
//---------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security { using System.ServiceModel.Channels; using System.ServiceModel; using System.Runtime.InteropServices; sealed class DuplexSecurityProtocolFactory : SecurityProtocolFactory { SecurityProtocolFactory forwardProtocolFactory; SecurityProtocolFactory reverseProtocolFactory; bool requireSecurityOnBothDuplexDirections = true; public DuplexSecurityProtocolFactory() : base() { } public DuplexSecurityProtocolFactory(SecurityProtocolFactory forwardProtocolFactory, SecurityProtocolFactory reverseProtocolFactory) : this() { this.forwardProtocolFactory = forwardProtocolFactory; this.reverseProtocolFactory = reverseProtocolFactory; } public SecurityProtocolFactory ForwardProtocolFactory { get { return this.forwardProtocolFactory; } set { ThrowIfImmutable(); this.forwardProtocolFactory = value; } } SecurityProtocolFactory ProtocolFactoryForIncomingMessages { get { return this.ActAsInitiator ? this.ReverseProtocolFactory : this.ForwardProtocolFactory; } } SecurityProtocolFactory ProtocolFactoryForOutgoingMessages { get { return this.ActAsInitiator ? this.ForwardProtocolFactory : this.ReverseProtocolFactory; } } // If RequireSecurityOnBothDuplexDirections is set to false, // one or both among ForwardProtocolFactory and // ReverseProtocolFactory will be allowed to be null. The // message directions corresponding to the null // ProtocolFactory will have no security applied or verified. // This mode may be used for GetPolicy message exchanges, for // example. public bool RequireSecurityOnBothDuplexDirections { get { return this.requireSecurityOnBothDuplexDirections; } set { ThrowIfImmutable(); this.requireSecurityOnBothDuplexDirections = value; } } public SecurityProtocolFactory ReverseProtocolFactory { get { return this.reverseProtocolFactory; } set { ThrowIfImmutable(); this.reverseProtocolFactory = value; } } public override bool SupportsDuplex { get { return true; } } public override bool SupportsReplayDetection { get { return this.ForwardProtocolFactory != null && this.ForwardProtocolFactory.SupportsReplayDetection && this.ReverseProtocolFactory != null && this.ReverseProtocolFactory.SupportsReplayDetection; } } public override bool SupportsRequestReply { get { return false; } } public override EndpointIdentity GetIdentityOfSelf() { SecurityProtocolFactory factory = this.ProtocolFactoryForIncomingMessages; if (factory != null) { return factory.GetIdentityOfSelf(); } else { return base.GetIdentityOfSelf(); } } public override void OnAbort() { if (this.forwardProtocolFactory != null) { this.forwardProtocolFactory.Close(true, TimeSpan.Zero); } if (this.reverseProtocolFactory != null) { this.reverseProtocolFactory.Close(true, TimeSpan.Zero); } } public override void OnClose(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (this.forwardProtocolFactory != null) { this.forwardProtocolFactory.Close(false, timeoutHelper.RemainingTime()); } if (this.reverseProtocolFactory != null) { this.reverseProtocolFactory.Close(false, timeoutHelper.RemainingTime()); } // no need to the close the base as it has no settings. } protected override SecurityProtocol OnCreateSecurityProtocol(EndpointAddress target, Uri via, object listenerSecurityState, TimeSpan timeout) { SecurityProtocolFactory outgoingFactory = this.ProtocolFactoryForOutgoingMessages; SecurityProtocolFactory incomingFactory = this.ProtocolFactoryForIncomingMessages; TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); SecurityProtocol outgoing = outgoingFactory == null ? null : outgoingFactory.CreateSecurityProtocol(target, via, listenerSecurityState, false, timeoutHelper.RemainingTime()); SecurityProtocol incoming = incomingFactory == null ? null : incomingFactory.CreateSecurityProtocol(null, null, listenerSecurityState, false, timeoutHelper.RemainingTime()); return new DuplexSecurityProtocol(outgoing, incoming); } public override void OnOpen(TimeSpan timeout) { if (this.ForwardProtocolFactory != null && ReferenceEquals(this.ForwardProtocolFactory, this.ReverseProtocolFactory)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("ReverseProtocolFactory", SR.GetString(SR.SameProtocolFactoryCannotBeSetForBothDuplexDirections)); } if (this.forwardProtocolFactory != null) { this.forwardProtocolFactory.ListenUri = this.ListenUri; } if (this.reverseProtocolFactory != null) { this.reverseProtocolFactory.ListenUri = this.ListenUri; } TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); Open(this.ForwardProtocolFactory, this.ActAsInitiator, "ForwardProtocolFactory", timeoutHelper.RemainingTime()); Open(this.ReverseProtocolFactory, !this.ActAsInitiator, "ReverseProtocolFactory", timeoutHelper.RemainingTime()); // no need to the open the base as it has no settings. } void Open(SecurityProtocolFactory factory, bool actAsInitiator, string propertyName, TimeSpan timeout) { if (factory != null) { factory.Open(actAsInitiator, timeout); } else if (this.RequireSecurityOnBothDuplexDirections) { OnPropertySettingsError(propertyName, true); } } sealed class DuplexSecurityProtocol : SecurityProtocol { readonly SecurityProtocol outgoingProtocol; readonly SecurityProtocol incomingProtocol; public DuplexSecurityProtocol(SecurityProtocol outgoingProtocol, SecurityProtocol incomingProtocol) : base(incomingProtocol.SecurityProtocolFactory, null, null) { this.outgoingProtocol = outgoingProtocol; this.incomingProtocol = incomingProtocol; } public override void OnOpen(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); this.outgoingProtocol.Open(timeoutHelper.RemainingTime()); this.incomingProtocol.Open(timeoutHelper.RemainingTime()); } public override void OnClose(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); this.outgoingProtocol.Close(false, timeoutHelper.RemainingTime()); this.incomingProtocol.Close(false, timeoutHelper.RemainingTime()); } public override void OnAbort() { this.outgoingProtocol.Close(true, TimeSpan.Zero); this.incomingProtocol.Close(true, TimeSpan.Zero); } public override IAsyncResult BeginSecureOutgoingMessage(Message message, TimeSpan timeout, AsyncCallback callback, object state) { if (this.outgoingProtocol != null) { return this.outgoingProtocol.BeginSecureOutgoingMessage(message, timeout, callback, state); } else { return new TypedCompletedAsyncResult(message, callback, state); } } public override IAsyncResult BeginSecureOutgoingMessage(Message message, TimeSpan timeout, SecurityProtocolCorrelationState correlationState, AsyncCallback callback, object state) { if (this.outgoingProtocol != null) { return this.outgoingProtocol.BeginSecureOutgoingMessage(message, timeout, correlationState, callback, state); } else { return new TypedCompletedAsyncResult (message, null, callback, state); } } public override void EndSecureOutgoingMessage(IAsyncResult result, out Message message) { if (this.outgoingProtocol != null) { this.outgoingProtocol.EndSecureOutgoingMessage(result, out message); } else { message = TypedCompletedAsyncResult .End(result); } } public override void EndSecureOutgoingMessage(IAsyncResult result, out Message message, out SecurityProtocolCorrelationState newCorrelationState) { if (this.outgoingProtocol != null) { this.outgoingProtocol.EndSecureOutgoingMessage(result, out message, out newCorrelationState); } else { message = TypedCompletedAsyncResult .End(result, out newCorrelationState); } } public override void SecureOutgoingMessage(ref Message message, TimeSpan timeout) { if (this.outgoingProtocol != null) { this.outgoingProtocol.SecureOutgoingMessage(ref message, timeout); } } public override SecurityProtocolCorrelationState SecureOutgoingMessage(ref Message message, TimeSpan timeout, SecurityProtocolCorrelationState correlationState) { if (this.outgoingProtocol != null) { return this.outgoingProtocol.SecureOutgoingMessage(ref message, timeout, correlationState); } else { return null; } } public override void VerifyIncomingMessage(ref Message message, TimeSpan timeout) { if (this.incomingProtocol != null) { this.incomingProtocol.VerifyIncomingMessage(ref message, timeout); } } public override SecurityProtocolCorrelationState VerifyIncomingMessage(ref Message message, TimeSpan timeout, params SecurityProtocolCorrelationState[] correlationStates) { if (this.incomingProtocol != null) { return this.incomingProtocol.VerifyIncomingMessage(ref message, timeout, correlationStates); } else { return null; } } } } } // 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
- PassportPrincipal.cs
- TimelineCollection.cs
- ComplusEndpointConfigContainer.cs
- SqlRetyper.cs
- ServiceEndpointElementCollection.cs
- TextEditorCharacters.cs
- IncrementalReadDecoders.cs
- DataListGeneralPage.cs
- RIPEMD160Managed.cs
- Msmq4SubqueuePoisonHandler.cs
- HwndPanningFeedback.cs
- AssociationTypeEmitter.cs
- EventLogPermissionEntryCollection.cs
- StylusPoint.cs
- HttpWebRequest.cs
- ModelTreeEnumerator.cs
- CurrentChangedEventManager.cs
- CodeDOMUtility.cs
- Socket.cs
- EventHandlerList.cs
- HyperLinkField.cs
- EntityRecordInfo.cs
- BooleanAnimationBase.cs
- PlanCompiler.cs
- AssemblyResourceLoader.cs
- Primitive.cs
- TypeElementCollection.cs
- KoreanCalendar.cs
- DefaultTypeArgumentAttribute.cs
- RegistryExceptionHelper.cs
- SymbolMethod.cs
- LambdaCompiler.Statements.cs
- ExternalCalls.cs
- ReaderOutput.cs
- DateTimeConverter.cs
- MemoryMappedFileSecurity.cs
- XD.cs
- ValidationHelper.cs
- Oid.cs
- WebZone.cs
- input.cs
- FixedTextBuilder.cs
- PnrpPeerResolverBindingElement.cs
- ListChangedEventArgs.cs
- HWStack.cs
- SqlIdentifier.cs
- OlePropertyStructs.cs
- RightsManagementEncryptionTransform.cs
- TraceHelpers.cs
- RemotingService.cs
- CompareInfo.cs
- UpDownEvent.cs
- ExpressionBuilderCollection.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- storagemappingitemcollection.viewdictionary.cs
- WebPartHelpVerb.cs
- DataGridRowHeaderAutomationPeer.cs
- CodeMemberEvent.cs
- ConstNode.cs
- TrimSurroundingWhitespaceAttribute.cs
- ReflectionHelper.cs
- SHA256Managed.cs
- UnsafeNativeMethodsCLR.cs
- GifBitmapEncoder.cs
- WpfWebRequestHelper.cs
- StructuredProperty.cs
- cache.cs
- PointKeyFrameCollection.cs
- Ops.cs
- SqlDelegatedTransaction.cs
- EntityDesignerUtils.cs
- KnownAssemblyEntry.cs
- ProxySimple.cs
- Thumb.cs
- PermissionToken.cs
- CustomWebEventKey.cs
- CustomError.cs
- AttributeData.cs
- GeometryConverter.cs
- Table.cs
- CheckBoxList.cs
- DataRecordInternal.cs
- ProtocolImporter.cs
- VirtualPathData.cs
- Dump.cs
- LogicalMethodInfo.cs
- URIFormatException.cs
- PrePostDescendentsWalker.cs
- XmlUTF8TextReader.cs
- RolePrincipal.cs
- SafeRightsManagementQueryHandle.cs
- AdapterUtil.cs
- ColumnBinding.cs
- Int16Animation.cs
- XmlSchemaSimpleTypeList.cs
- CopyCodeAction.cs
- HitTestParameters.cs
- EasingKeyFrames.cs
- TdsEnums.cs
- MultipleViewProviderWrapper.cs