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
- StyleXamlTreeBuilder.cs
- EnumValidator.cs
- ObjectDataSource.cs
- OleDbRowUpdatingEvent.cs
- RijndaelManaged.cs
- IconHelper.cs
- handlecollector.cs
- SafeCryptContextHandle.cs
- CacheMemory.cs
- _ListenerAsyncResult.cs
- ExecutionEngineException.cs
- HtmlAnchor.cs
- RemotingHelper.cs
- ManagementOptions.cs
- recordstatefactory.cs
- FileDialog_Vista_Interop.cs
- documentsequencetextview.cs
- XmlSchemaAttribute.cs
- HyperLinkField.cs
- HideDisabledControlAdapter.cs
- AnimationClock.cs
- ContainsRowNumberChecker.cs
- MailAddressCollection.cs
- DataChangedEventManager.cs
- PermissionSetTriple.cs
- FontStyle.cs
- BitmapFrameDecode.cs
- VarRefManager.cs
- AxisAngleRotation3D.cs
- SingleKeyFrameCollection.cs
- ContainerUtilities.cs
- WindowsRichEditRange.cs
- ChtmlTextWriter.cs
- GroupLabel.cs
- ClassHandlersStore.cs
- Transform.cs
- OptionalColumn.cs
- autovalidator.cs
- TypedElement.cs
- Sql8ConformanceChecker.cs
- BrushValueSerializer.cs
- StorageEntitySetMapping.cs
- RuntimeConfig.cs
- WebPermission.cs
- ActivityExecutorSurrogate.cs
- ScalarConstant.cs
- DataGridPageChangedEventArgs.cs
- Form.cs
- XhtmlBasicTextViewAdapter.cs
- Parser.cs
- MergePropertyDescriptor.cs
- UICuesEvent.cs
- AddInToken.cs
- Psha1DerivedKeyGenerator.cs
- Comparer.cs
- XmlSchemaObjectTable.cs
- BackgroundWorker.cs
- ConnectionConsumerAttribute.cs
- IResourceProvider.cs
- SettingsBase.cs
- GroupBoxAutomationPeer.cs
- ValueQuery.cs
- AspNetPartialTrustHelpers.cs
- HealthMonitoringSection.cs
- InfiniteTimeSpanConverter.cs
- ByteStack.cs
- DbConnectionHelper.cs
- TdsValueSetter.cs
- HierarchicalDataSourceIDConverter.cs
- ObfuscateAssemblyAttribute.cs
- EncryptedKey.cs
- BitmapData.cs
- TextEditorCopyPaste.cs
- Profiler.cs
- NumericPagerField.cs
- RSAProtectedConfigurationProvider.cs
- RepeatButtonAutomationPeer.cs
- TextViewBase.cs
- ExternalFile.cs
- IntPtr.cs
- ComPlusSynchronizationContext.cs
- userdatakeys.cs
- CheckBoxFlatAdapter.cs
- KeyedPriorityQueue.cs
- FileRegion.cs
- ListViewGroupConverter.cs
- _Events.cs
- Exceptions.cs
- CmsInterop.cs
- XmlDataProvider.cs
- handlecollector.cs
- ColorAnimationBase.cs
- DocumentationServerProtocol.cs
- CharacterBufferReference.cs
- QueryableDataSourceEditData.cs
- SiteMapHierarchicalDataSourceView.cs
- DataControlField.cs
- SystemTcpStatistics.cs
- BaseHashHelper.cs
- path.cs