Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Selectors / WindowsUserNameSecurityTokenAuthenticator.cs / 1305376 / WindowsUserNameSecurityTokenAuthenticator.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Selectors { using System.Collections.ObjectModel; using System.ComponentModel; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.IdentityModel.Tokens; using System.Runtime.InteropServices; using System.Security; using System.Security.Principal; public class WindowsUserNameSecurityTokenAuthenticator : UserNameSecurityTokenAuthenticator { bool includeWindowsGroups; public WindowsUserNameSecurityTokenAuthenticator() : this(WindowsClaimSet.DefaultIncludeWindowsGroups) { } public WindowsUserNameSecurityTokenAuthenticator(bool includeWindowsGroups) { this.includeWindowsGroups = includeWindowsGroups; } protected override ReadOnlyCollectionValidateUserNamePasswordCore(string userName, string password) { string domain = null; string[] strings = userName.Split('\\'); if (strings.Length != 1) { if (strings.Length != 2 || String.IsNullOrEmpty(strings[0])) { // Only support one slash and domain cannot be empty (consistent with windowslogon). throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.IncorrectUserNameFormat)); } // This is the downlevel case - domain\userName userName = strings[1]; domain = strings[0]; } const uint LOGON32_PROVIDER_DEFAULT = 0; const uint LOGON32_LOGON_NETWORK_CLEARTEXT = 8; SafeCloseHandle tokenHandle = null; try { if (!NativeMethods.LogonUser(userName, domain, password, LOGON32_LOGON_NETWORK_CLEARTEXT, LOGON32_PROVIDER_DEFAULT, out tokenHandle)) { int error = Marshal.GetLastWin32Error(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenValidationException(SR.GetString(SR.FailLogonUser, userName), new Win32Exception(error))); } WindowsIdentity windowsIdentity = new WindowsIdentity(tokenHandle.DangerousGetHandle(), SecurityUtils.AuthTypeBasic); WindowsClaimSet claimSet = new WindowsClaimSet(windowsIdentity, SecurityUtils.AuthTypeBasic, this.includeWindowsGroups, false); return SecurityUtils.CreateAuthorizationPolicies(claimSet, claimSet.ExpirationTime); } finally { if (tokenHandle != null) tokenHandle.Close(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Selectors { using System.Collections.ObjectModel; using System.ComponentModel; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.IdentityModel.Tokens; using System.Runtime.InteropServices; using System.Security; using System.Security.Principal; public class WindowsUserNameSecurityTokenAuthenticator : UserNameSecurityTokenAuthenticator { bool includeWindowsGroups; public WindowsUserNameSecurityTokenAuthenticator() : this(WindowsClaimSet.DefaultIncludeWindowsGroups) { } public WindowsUserNameSecurityTokenAuthenticator(bool includeWindowsGroups) { this.includeWindowsGroups = includeWindowsGroups; } protected override ReadOnlyCollection ValidateUserNamePasswordCore(string userName, string password) { string domain = null; string[] strings = userName.Split('\\'); if (strings.Length != 1) { if (strings.Length != 2 || String.IsNullOrEmpty(strings[0])) { // Only support one slash and domain cannot be empty (consistent with windowslogon). throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.IncorrectUserNameFormat)); } // This is the downlevel case - domain\userName userName = strings[1]; domain = strings[0]; } const uint LOGON32_PROVIDER_DEFAULT = 0; const uint LOGON32_LOGON_NETWORK_CLEARTEXT = 8; SafeCloseHandle tokenHandle = null; try { if (!NativeMethods.LogonUser(userName, domain, password, LOGON32_LOGON_NETWORK_CLEARTEXT, LOGON32_PROVIDER_DEFAULT, out tokenHandle)) { int error = Marshal.GetLastWin32Error(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityTokenValidationException(SR.GetString(SR.FailLogonUser, userName), new Win32Exception(error))); } WindowsIdentity windowsIdentity = new WindowsIdentity(tokenHandle.DangerousGetHandle(), SecurityUtils.AuthTypeBasic); WindowsClaimSet claimSet = new WindowsClaimSet(windowsIdentity, SecurityUtils.AuthTypeBasic, this.includeWindowsGroups, false); return SecurityUtils.CreateAuthorizationPolicies(claimSet, claimSet.ExpirationTime); } finally { if (tokenHandle != null) tokenHandle.Close(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConfigXmlReader.cs
- ExpressionValueEditor.cs
- EncryptedKeyIdentifierClause.cs
- DataSourceView.cs
- Condition.cs
- CommandValueSerializer.cs
- PartialClassGenerationTaskInternal.cs
- EntityDataSourceValidationException.cs
- XamlToRtfWriter.cs
- AsyncDataRequest.cs
- ContextBase.cs
- TransformerInfoCollection.cs
- GenericTypeParameterBuilder.cs
- GetReadStreamResult.cs
- Function.cs
- InvalidComObjectException.cs
- XmlNamespaceDeclarationsAttribute.cs
- XmlCollation.cs
- UIntPtr.cs
- IDispatchConstantAttribute.cs
- IPAddressCollection.cs
- FullTextLine.cs
- ManagedFilter.cs
- ImageInfo.cs
- PersonalizationStateInfo.cs
- SplineKeyFrames.cs
- IResourceProvider.cs
- BackStopAuthenticationModule.cs
- TraceUtils.cs
- CacheDependency.cs
- _ProxyChain.cs
- Oid.cs
- DocumentXPathNavigator.cs
- GridItemPatternIdentifiers.cs
- metadatamappinghashervisitor.hashsourcebuilder.cs
- SmtpReplyReader.cs
- ListItem.cs
- ImageBrush.cs
- StateMachineWorkflowInstance.cs
- DataServiceExpressionVisitor.cs
- DetailsViewUpdateEventArgs.cs
- TreeViewDesigner.cs
- MenuItemStyleCollection.cs
- SqlSelectStatement.cs
- DispatcherSynchronizationContext.cs
- TextWriter.cs
- _HelperAsyncResults.cs
- ConfigurationManagerInternalFactory.cs
- SelectionProviderWrapper.cs
- PrintDialogException.cs
- NavigationWindowAutomationPeer.cs
- PropertyManager.cs
- TemplateColumn.cs
- OdbcConnectionOpen.cs
- Stacktrace.cs
- CoreSwitches.cs
- MarkupWriter.cs
- MarkupExtensionReturnTypeAttribute.cs
- ImplicitInputBrush.cs
- SuspendDesigner.cs
- ColumnMapCopier.cs
- RequestCache.cs
- ActiveXSite.cs
- FixedSOMElement.cs
- ScriptingJsonSerializationSection.cs
- AttachedPropertyDescriptor.cs
- DirectoryInfo.cs
- GetKeyedHashRequest.cs
- StandardTransformFactory.cs
- Automation.cs
- SafeRegistryHandle.cs
- CodeGenerator.cs
- TreeIterator.cs
- WsiProfilesElementCollection.cs
- SqlUtils.cs
- BezierSegment.cs
- MtomMessageEncodingBindingElement.cs
- NavigateEvent.cs
- ParameterInfo.cs
- TextBoxBase.cs
- CustomTypeDescriptor.cs
- TextBoxView.cs
- ToolboxDataAttribute.cs
- XmlSerializerNamespaces.cs
- OrderByQueryOptionExpression.cs
- SafeRightsManagementPubHandle.cs
- ItemChangedEventArgs.cs
- WsatExtendedInformation.cs
- DbInsertCommandTree.cs
- DbProviderManifest.cs
- VBIdentifierNameEditor.cs
- MouseDevice.cs
- TextModifierScope.cs
- TreeNodeBinding.cs
- ToolboxCategory.cs
- DesignTimeHTMLTextWriter.cs
- NumericUpDownAcceleration.cs
- SizeAnimationClockResource.cs
- Content.cs
- ScrollBar.cs