Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / SymmetricSecurityProtocolFactory.cs / 1 / SymmetricSecurityProtocolFactory.cs
//---------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Security { using System.Collections.Generic; using System.ServiceModel; using System.Collections.ObjectModel; using System.IdentityModel.Tokens; using System.IdentityModel.Selectors; using System.ServiceModel.Channels; using System.ServiceModel.Security.Tokens; class SymmetricSecurityProtocolFactory : MessageSecurityProtocolFactory { // server side per-listener objects SecurityTokenAuthenticator recipientSymmetricTokenAuthenticator; SecurityTokenProvider recipientAsymmetricTokenProvider; ReadOnlyCollectionrecipientOutOfBandTokenResolverList; SecurityTokenParameters tokenParameters; SecurityTokenParameters protectionTokenParameters; public SymmetricSecurityProtocolFactory() : base() { } internal SymmetricSecurityProtocolFactory(MessageSecurityProtocolFactory factory) : base(factory) { } public SecurityTokenParameters SecurityTokenParameters { get { return this.tokenParameters; } set { ThrowIfImmutable(); this.tokenParameters = value; } } public SecurityTokenProvider RecipientAsymmetricTokenProvider { get { return this.recipientAsymmetricTokenProvider; } } public SecurityTokenAuthenticator RecipientSymmetricTokenAuthenticator { get { return this.recipientSymmetricTokenAuthenticator; } } public ReadOnlyCollection RecipientOutOfBandTokenResolverList { get { return this.recipientOutOfBandTokenResolverList; } } public override EndpointIdentity GetIdentityOfSelf() { EndpointIdentity identity = null; if (this.SecurityTokenManager is IEndpointIdentityProvider) { SecurityTokenRequirement requirement = CreateRecipientSecurityTokenRequirement(); this.SecurityTokenParameters.InitializeSecurityTokenRequirement(requirement); identity = ((IEndpointIdentityProvider)this.SecurityTokenManager).GetIdentityOfSelf(requirement); } else { identity = base.GetIdentityOfSelf(); } return identity; } public override T GetProperty () { if (typeof(T) == typeof(Collection )) { Collection result = base.GetProperty >(); if (this.recipientSymmetricTokenAuthenticator is ISecurityContextSecurityTokenCacheProvider) { result.Add(((ISecurityContextSecurityTokenCacheProvider)this.recipientSymmetricTokenAuthenticator).TokenCache); } return (T)(object)(result); } else { return base.GetProperty (); } } public override void OnClose(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (!this.ActAsInitiator) { if (this.recipientSymmetricTokenAuthenticator != null) { SecurityUtils.CloseTokenAuthenticatorIfRequired(this.recipientSymmetricTokenAuthenticator, timeoutHelper.RemainingTime()); } if (this.recipientAsymmetricTokenProvider != null) { SecurityUtils.CloseTokenProviderIfRequired(this.recipientAsymmetricTokenProvider, timeoutHelper.RemainingTime()); } } base.OnClose(timeoutHelper.RemainingTime()); } public override void OnAbort() { if (!this.ActAsInitiator) { if (this.recipientSymmetricTokenAuthenticator != null) { SecurityUtils.AbortTokenAuthenticatorIfRequired(this.recipientSymmetricTokenAuthenticator); } if (this.recipientAsymmetricTokenProvider != null) { SecurityUtils.AbortTokenProviderIfRequired(this.recipientAsymmetricTokenProvider); } } base.OnAbort(); } protected override SecurityProtocol OnCreateSecurityProtocol(EndpointAddress target, Uri via, object listenerSecurityState, TimeSpan timeout) { return new SymmetricSecurityProtocol(this, target, via); } RecipientServiceModelSecurityTokenRequirement CreateRecipientTokenRequirement() { RecipientServiceModelSecurityTokenRequirement requirement = CreateRecipientSecurityTokenRequirement(); this.SecurityTokenParameters.InitializeSecurityTokenRequirement(requirement); requirement.KeyUsage = (this.SecurityTokenParameters.HasAsymmetricKey) ? SecurityKeyUsage.Exchange : SecurityKeyUsage.Signature; return requirement; } public override void OnOpen(TimeSpan timeout) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); base.OnOpen(timeoutHelper.RemainingTime()); if (this.tokenParameters == null) { OnPropertySettingsError("SecurityTokenParameters", true); } if (!this.ActAsInitiator) { SecurityTokenRequirement recipientTokenRequirement = CreateRecipientTokenRequirement(); SecurityTokenResolver resolver = null; if (this.SecurityTokenParameters.HasAsymmetricKey) { this.recipientAsymmetricTokenProvider = this.SecurityTokenManager.CreateSecurityTokenProvider(recipientTokenRequirement); } else { this.recipientSymmetricTokenAuthenticator = this.SecurityTokenManager.CreateSecurityTokenAuthenticator(recipientTokenRequirement, out resolver); } if (this.RecipientSymmetricTokenAuthenticator != null && this.RecipientAsymmetricTokenProvider != null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.OnlyOneOfEncryptedKeyOrSymmetricBindingCanBeSelected))); } if (resolver != null) { Collection tmp = new Collection (); tmp.Add(resolver); this.recipientOutOfBandTokenResolverList = new ReadOnlyCollection (tmp); } else { this.recipientOutOfBandTokenResolverList = EmptyReadOnlyCollection .Instance; } if (this.RecipientAsymmetricTokenProvider != null) { Open("RecipientAsymmetricTokenProvider", true, this.RecipientAsymmetricTokenProvider, timeoutHelper.RemainingTime()); } else { Open("RecipientSymmetricTokenAuthenticator", true, this.RecipientSymmetricTokenAuthenticator, timeoutHelper.RemainingTime()); } } if (this.tokenParameters.RequireDerivedKeys) { this.ExpectKeyDerivation = true; } if (this.tokenParameters.HasAsymmetricKey) { this.protectionTokenParameters = new WrappedKeySecurityTokenParameters(); this.protectionTokenParameters.RequireDerivedKeys = this.SecurityTokenParameters.RequireDerivedKeys; } else { this.protectionTokenParameters = this.tokenParameters; } } internal SecurityTokenParameters GetProtectionTokenParameters() { return this.protectionTokenParameters; } } } // 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
- HebrewNumber.cs
- BinarySecretSecurityToken.cs
- TextBlockAutomationPeer.cs
- BatchWriter.cs
- UniqueEventHelper.cs
- BitmapEffectOutputConnector.cs
- DebugHandleTracker.cs
- ObjectSpanRewriter.cs
- Model3DCollection.cs
- WorkflowRuntimeServiceElementCollection.cs
- DataPagerFieldItem.cs
- AssemblySettingAttributes.cs
- ConfigurationSection.cs
- KeyBinding.cs
- PolyQuadraticBezierSegment.cs
- InvokeFunc.cs
- TableRowGroupCollection.cs
- XmlCharCheckingReader.cs
- IRCollection.cs
- HttpCookiesSection.cs
- ExponentialEase.cs
- AvTraceFormat.cs
- MailAddressCollection.cs
- SrgsOneOf.cs
- TemplateBuilder.cs
- CapabilitiesPattern.cs
- SelectionEditingBehavior.cs
- LinqDataSourceStatusEventArgs.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- Column.cs
- SettingsSection.cs
- DebugHandleTracker.cs
- DrawingServices.cs
- Trace.cs
- CommandManager.cs
- SafeMarshalContext.cs
- ShadowGlyph.cs
- XmlSerializerAssemblyAttribute.cs
- DeviceSpecificDialogCachedState.cs
- PropertyChangedEventArgs.cs
- ReferenceConverter.cs
- UnsafeNativeMethodsMilCoreApi.cs
- ConfigurationConverterBase.cs
- CodeNamespaceCollection.cs
- _NetworkingPerfCounters.cs
- CollectionAdapters.cs
- TypeListConverter.cs
- CLRBindingWorker.cs
- CollaborationHelperFunctions.cs
- SecurityRuntime.cs
- CommandConverter.cs
- ListViewContainer.cs
- SmiRecordBuffer.cs
- PreviewControlDesigner.cs
- UntypedNullExpression.cs
- UpdateManifestForBrowserApplication.cs
- Action.cs
- EncodingFallbackAwareXmlTextWriter.cs
- URLString.cs
- SecurityContext.cs
- XmlSubtreeReader.cs
- externdll.cs
- BitmapEffectGroup.cs
- JsonReaderDelegator.cs
- coordinator.cs
- DataServiceHostWrapper.cs
- XmlDocumentFragment.cs
- Pair.cs
- TextSelectionHelper.cs
- ByteStorage.cs
- TypeValidationEventArgs.cs
- BStrWrapper.cs
- PeerContact.cs
- AffineTransform3D.cs
- XsdBuilder.cs
- SkinBuilder.cs
- CommentEmitter.cs
- PriorityRange.cs
- RealizationContext.cs
- WebPartEditorCancelVerb.cs
- HttpModuleAction.cs
- MergePropertyDescriptor.cs
- UserNamePasswordValidator.cs
- AttributeData.cs
- TabPanel.cs
- EntityClassGenerator.cs
- DataGridItemEventArgs.cs
- PeerNameRecordCollection.cs
- PersistNameAttribute.cs
- SqlDataSourceStatusEventArgs.cs
- PasswordTextContainer.cs
- ProgressBarAutomationPeer.cs
- XmlSchemaFacet.cs
- DomNameTable.cs
- LinkConverter.cs
- DataReceivedEventArgs.cs
- PolicyChain.cs
- BitmapImage.cs
- TemplateXamlTreeBuilder.cs
- HttpClientCertificate.cs