Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Security / SpnegoTokenAuthenticator.cs / 1 / SpnegoTokenAuthenticator.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.Security { using System; using System.ServiceModel; using System.Collections; using System.Xml; using System.Net; using System.Security.Principal; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.IdentityModel.Tokens; using System.ServiceModel.Security.Tokens; using System.Runtime.Serialization; using System.ServiceModel.Diagnostics; using SafeCloseHandle = System.IdentityModel.SafeCloseHandle; using SafeFreeCredentials = System.IdentityModel.SafeFreeCredentials; sealed class SpnegoTokenAuthenticator : SspiNegotiationTokenAuthenticator { bool extractGroupsForWindowsAccounts; NetworkCredential serverCredential; bool allowUnauthenticatedCallers; SafeFreeCredentials credentialsHandle; public SpnegoTokenAuthenticator() : base() { // empty } // settings public bool ExtractGroupsForWindowsAccounts { get { return this.extractGroupsForWindowsAccounts; } set { this.CommunicationObject.ThrowIfDisposedOrImmutable(); this.extractGroupsForWindowsAccounts = value; } } public NetworkCredential ServerCredential { get { return this.serverCredential; } set { this.CommunicationObject.ThrowIfDisposedOrImmutable(); this.serverCredential = value; } } public bool AllowUnauthenticatedCallers { get { return this.allowUnauthenticatedCallers; } set { this.CommunicationObject.ThrowIfDisposedOrImmutable(); this.allowUnauthenticatedCallers = value; } } // overrides public override XmlDictionaryString NegotiationValueType { get { return XD.TrustApr2004Dictionary.SpnegoValueTypeUri; } } public override void OnOpening() { base.OnOpening(); if (this.credentialsHandle == null) { this.credentialsHandle = SecurityUtils.GetCredentialsHandle("Negotiate", this.serverCredential, true); } } public override void OnClose(TimeSpan timeout) { base.OnClose(timeout); FreeCredentialsHandle(); } public override void OnAbort() { base.OnAbort(); FreeCredentialsHandle(); } void FreeCredentialsHandle() { if (this.credentialsHandle != null) { this.credentialsHandle.Close(); this.credentialsHandle = null; } } protected override SspiNegotiationTokenAuthenticatorState CreateSspiState(byte[] incomingBlob, string incomingValueTypeUri) { ISspiNegotiation windowsNegotiation = new WindowsSspiNegotiation("Negotiate", this.credentialsHandle); return new SspiNegotiationTokenAuthenticatorState(windowsNegotiation); } protected override ReadOnlyCollectionValidateSspiNegotiation(ISspiNegotiation sspiNegotiation) { WindowsSspiNegotiation windowsNegotiation = (WindowsSspiNegotiation)sspiNegotiation; if (windowsNegotiation.IsValidContext == false) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new SecurityNegotiationException(SR.GetString(SR.InvalidSspiNegotiation))); } SecurityTraceRecordHelper.TraceServiceSpnego(windowsNegotiation); if (this.IsClientAnonymous) { return EmptyReadOnlyCollection .Instance; } using (SafeCloseHandle contextToken = windowsNegotiation.GetContextToken()) { WindowsIdentity windowsIdentity = new WindowsIdentity(contextToken.DangerousGetHandle()); SecurityUtils.ValidateAnonymityConstraint(windowsIdentity, this.AllowUnauthenticatedCallers); List policies = new List (1); WindowsClaimSet wic = new WindowsClaimSet(windowsIdentity, this.extractGroupsForWindowsAccounts, false); policies.Add(new System.IdentityModel.Policy.UnconditionalPolicy(wic, TimeoutHelper.Add(DateTime.UtcNow, base.ServiceTokenLifetime))); return policies.AsReadOnly(); } } } } // 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
- SortedList.cs
- EdmFunction.cs
- ProxyManager.cs
- XmlSchemaInferenceException.cs
- EmptyQuery.cs
- StateBag.cs
- SqlBooleanizer.cs
- CompoundFileStorageReference.cs
- MDIWindowDialog.cs
- QilGeneratorEnv.cs
- OuterGlowBitmapEffect.cs
- DataObjectFieldAttribute.cs
- UIPermission.cs
- SafeRightsManagementPubHandle.cs
- SelectorAutomationPeer.cs
- DataGridViewColumnCollectionDialog.cs
- SqlUDTStorage.cs
- XmlDataLoader.cs
- ConfigXmlSignificantWhitespace.cs
- TypeUtils.cs
- ObjectNavigationPropertyMapping.cs
- ResourceExpressionBuilder.cs
- FontWeightConverter.cs
- SettingsSavedEventArgs.cs
- coordinatorscratchpad.cs
- NetTcpBindingCollectionElement.cs
- ListItemParagraph.cs
- control.ime.cs
- RequestDescription.cs
- ActivitySurrogateSelector.cs
- ByteAnimationBase.cs
- GridViewCancelEditEventArgs.cs
- AttributeQuery.cs
- AccessedThroughPropertyAttribute.cs
- Camera.cs
- SafeCryptoHandles.cs
- MatrixValueSerializer.cs
- Trigger.cs
- ThemeDictionaryExtension.cs
- CryptoProvider.cs
- DefaultAssemblyResolver.cs
- RenderData.cs
- TypeContext.cs
- GrammarBuilderPhrase.cs
- PageDeviceFont.cs
- ListComponentEditor.cs
- PeerApplicationLaunchInfo.cs
- CallbackValidator.cs
- WinEventTracker.cs
- DropShadowEffect.cs
- ElementsClipboardData.cs
- VirtualDirectoryMappingCollection.cs
- UntypedNullExpression.cs
- HttpClientCertificate.cs
- WebDescriptionAttribute.cs
- PageThemeCodeDomTreeGenerator.cs
- WorkflowServiceHostFactory.cs
- ChtmlLinkAdapter.cs
- XmlLoader.cs
- RequestCacheManager.cs
- XmlSchemaValidator.cs
- ScriptBehaviorDescriptor.cs
- HostingEnvironmentSection.cs
- CommonXSendMessage.cs
- BamlStream.cs
- CompositeScriptReference.cs
- EventLogRecord.cs
- FragmentQuery.cs
- FamilyTypefaceCollection.cs
- Compiler.cs
- EditorZoneBase.cs
- EntityDataSourceContextCreatingEventArgs.cs
- TraceListeners.cs
- Regex.cs
- ColorMap.cs
- Automation.cs
- URIFormatException.cs
- SecureConversationVersion.cs
- EventMappingSettingsCollection.cs
- XmlKeywords.cs
- _NetworkingPerfCounters.cs
- PenLineCapValidation.cs
- TextRangeAdaptor.cs
- LogicalExpr.cs
- SiteMapNodeItem.cs
- SizeAnimationBase.cs
- ControlBuilderAttribute.cs
- IPAddress.cs
- RegistrySecurity.cs
- JournalEntryListConverter.cs
- HttpCachePolicyElement.cs
- NavigationProperty.cs
- ApplicationSecurityManager.cs
- ZoneLinkButton.cs
- StylusButton.cs
- ServiceNameCollection.cs
- DataColumnCollection.cs
- HwndMouseInputProvider.cs
- XmlBoundElement.cs
- DrawingVisual.cs