Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / NegotiationTokenProvider.cs / 1 / NegotiationTokenProvider.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Security
{
using System.IdentityModel.Claims;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.IdentityModel.Policy;
using System.ServiceModel.Security.Tokens;
using System.Security.Principal;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Generic;
using System.ServiceModel.Channels;
using System.Net;
using System.Globalization;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.ServiceModel.Diagnostics;
using System.Xml;
/*
* This is the base class for all token providers that negotiate an SCT from
* the target service.
*/
abstract class NegotiationTokenProvider : IssuanceTokenProviderBase
where T : IssuanceTokenProviderState
{
IChannelFactory rstChannelFactory;
bool requiresManualReplyAddressing;
BindingContext issuanceBindingContext;
MessageVersion messageVersion;
protected NegotiationTokenProvider()
: base()
{
}
public BindingContext IssuerBindingContext
{
get { return this.issuanceBindingContext; }
set
{
this.CommunicationObject.ThrowIfDisposedOrImmutable();
if (value == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("value");
}
this.issuanceBindingContext = value.Clone();
}
}
public override XmlDictionaryString RequestSecurityTokenAction
{
get
{
return this.StandardsManager.TrustDriver.RequestSecurityTokenAction;
}
}
public override XmlDictionaryString RequestSecurityTokenResponseAction
{
get
{
return this.StandardsManager.TrustDriver.RequestSecurityTokenResponseAction;
}
}
protected override MessageVersion MessageVersion
{
get
{
return this.messageVersion;
}
}
protected override bool RequiresManualReplyAddressing
{
get
{
ThrowIfCreated();
return this.requiresManualReplyAddressing;
}
}
public override void OnClose(TimeSpan timeout)
{
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
if (this.rstChannelFactory != null)
{
this.rstChannelFactory.Close(timeout);
this.rstChannelFactory = null;
}
base.OnClose(timeoutHelper.RemainingTime());
}
public override void OnAbort()
{
if (this.rstChannelFactory != null)
{
this.rstChannelFactory.Abort();
this.rstChannelFactory = null;
}
base.OnAbort();
}
public override void OnOpen(TimeSpan timeout)
{
if (this.IssuerBindingContext == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.IssuerBuildContextNotSet, this.GetType())));
}
TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
this.SetupRstChannelFactory();
this.rstChannelFactory.Open(timeout);
base.OnOpen(timeoutHelper.RemainingTime());
}
protected abstract IChannelFactory GetNegotiationChannelFactory(IChannelFactory transportChannelFactory, ChannelBuilder channelBuilder);
void SetupRstChannelFactory()
{
IChannelFactory innerChannelFactory = null;
ChannelBuilder channelBuilder = new ChannelBuilder(this.IssuerBindingContext.Clone(), true);
// if the underlying transport does not support request/reply, wrap it inside
// a service channel factory.
if (channelBuilder.CanBuildChannelFactory())
{
innerChannelFactory = channelBuilder.BuildChannelFactory();
this.requiresManualReplyAddressing = true;
}
else
{
ClientRuntime clientRuntime = new ClientRuntime("RequestSecurityTokenContract", NamingHelper.DefaultNamespace);
clientRuntime.ValidateMustUnderstand = false;
ServiceChannelFactory serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(channelBuilder, clientRuntime);
serviceChannelFactory.ClientRuntime.UseSynchronizationContext = false;
serviceChannelFactory.ClientRuntime.AddTransactionFlowProperties = false;
ClientOperation rstOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "RequestSecurityToken", this.RequestSecurityTokenAction.Value);
rstOperation.Formatter = MessageOperationFormatter.Instance;
serviceChannelFactory.ClientRuntime.Operations.Add(rstOperation);
if (this.IsMultiLegNegotiation)
{
ClientOperation rstrOperation = new ClientOperation(serviceChannelFactory.ClientRuntime, "RequestSecurityTokenResponse", this.RequestSecurityTokenResponseAction.Value);
rstrOperation.Formatter = MessageOperationFormatter.Instance;
serviceChannelFactory.ClientRuntime.Operations.Add(rstrOperation);
}
// service channel automatically adds reply headers
this.requiresManualReplyAddressing = false;
innerChannelFactory = new SecuritySessionSecurityTokenProvider.RequestChannelFactory(serviceChannelFactory);
}
this.rstChannelFactory = GetNegotiationChannelFactory(innerChannelFactory, channelBuilder);
this.messageVersion = channelBuilder.Binding.MessageVersion;
}
// negotiation message processing overrides
protected override bool WillInitializeChannelFactoriesCompleteSynchronously(EndpointAddress target)
{
return true;
}
protected override void InitializeChannelFactories(EndpointAddress target, TimeSpan timeout)
{
}
protected override IAsyncResult BeginInitializeChannelFactories(EndpointAddress target, TimeSpan timeout, AsyncCallback callback, object state)
{
return new CompletedAsyncResult(callback, state);
}
protected override void EndInitializeChannelFactories(IAsyncResult result)
{
CompletedAsyncResult.End(result);
}
protected override IRequestChannel CreateClientChannel(EndpointAddress target, Uri via)
{
if (via != null)
{
return this.rstChannelFactory.CreateChannel(target, via);
}
else
{
return this.rstChannelFactory.CreateChannel(target);
}
}
}
}
// 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
- CodeLinePragma.cs
- ExportException.cs
- _DisconnectOverlappedAsyncResult.cs
- CodeEntryPointMethod.cs
- SemaphoreSecurity.cs
- SpellerError.cs
- SqlBuilder.cs
- DataGridViewMethods.cs
- NumericUpDownAcceleration.cs
- DockProviderWrapper.cs
- Compensate.cs
- AppDomainFactory.cs
- LocatorGroup.cs
- Run.cs
- HMACSHA1.cs
- FrameDimension.cs
- ToolBar.cs
- XsdDateTime.cs
- TypedDatasetGenerator.cs
- StatusBarItemAutomationPeer.cs
- ScriptHandlerFactory.cs
- SafeLocalMemHandle.cs
- ServiceContractListItemList.cs
- serverconfig.cs
- BaseConfigurationRecord.cs
- WorkItem.cs
- ContentElementAutomationPeer.cs
- Cursors.cs
- DataGridViewLinkCell.cs
- ProfilePropertySettingsCollection.cs
- ReadOnlyDictionary.cs
- CapabilitiesRule.cs
- GrammarBuilderRuleRef.cs
- CrossAppDomainChannel.cs
- MachinePropertyVariants.cs
- TextSchema.cs
- SafeFileMappingHandle.cs
- AlphabeticalEnumConverter.cs
- Panel.cs
- XmlCDATASection.cs
- ConfigurationElementCollection.cs
- TypefaceCollection.cs
- PropertyManager.cs
- ClientTargetSection.cs
- WindowsSlider.cs
- MobileFormsAuthentication.cs
- ZoneLinkButton.cs
- SweepDirectionValidation.cs
- ImportCatalogPart.cs
- PropertyChangingEventArgs.cs
- InternalCache.cs
- PathFigureCollection.cs
- SoapSchemaImporter.cs
- ListViewUpdateEventArgs.cs
- IMembershipProvider.cs
- DataGridViewSelectedRowCollection.cs
- InputLanguageCollection.cs
- KeyEvent.cs
- TextSegment.cs
- PeerCollaborationPermission.cs
- MimeMapping.cs
- Endpoint.cs
- RoleManagerSection.cs
- DbCommandDefinition.cs
- HashStream.cs
- StringComparer.cs
- WebEventTraceProvider.cs
- PasswordTextContainer.cs
- DynamicObject.cs
- ScriptDescriptor.cs
- KeyToListMap.cs
- _BufferOffsetSize.cs
- HyperlinkAutomationPeer.cs
- WebBrowserNavigatedEventHandler.cs
- QuotedPairReader.cs
- XamlWrappingReader.cs
- AssemblyResolver.cs
- StrokeRenderer.cs
- GregorianCalendar.cs
- ModuleElement.cs
- WebHttpBindingElement.cs
- ProvidersHelper.cs
- BinaryObjectReader.cs
- MemberHolder.cs
- DelegateBodyWriter.cs
- XmlTextEncoder.cs
- EntitySqlQueryBuilder.cs
- GeometryConverter.cs
- RefreshEventArgs.cs
- querybuilder.cs
- SqlPersonalizationProvider.cs
- CreatingCookieEventArgs.cs
- EntityDescriptor.cs
- Parser.cs
- CacheSection.cs
- HostedHttpTransportManager.cs
- JavaScriptSerializer.cs
- VectorAnimationUsingKeyFrames.cs
- BuilderInfo.cs
- ThousandthOfEmRealDoubles.cs