Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / ComIntegration / ChannelCredentials.cs / 1 / ChannelCredentials.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel.ComIntegration { using System; using System.ServiceModel.Description; using System.Reflection; using System.Net; using System.Security; using System.Security.AccessControl; using System.Security.Principal; using System.Runtime.InteropServices; using System.Collections.Generic; using System.ServiceModel; using System.ServiceModel.Channels; using System.Security.Cryptography.X509Certificates; using System.ServiceModel.Security; using System.ServiceModel.Security.Tokens; internal class ChannelCredentials:IChannelCredentials, IDisposable { protected IProvideChannelBuilderSettings channelBuilderSettings; internal ChannelCredentials (IProvideChannelBuilderSettings channelBuilderSettings) { this.channelBuilderSettings = channelBuilderSettings; } internal static ComProxy Create (IntPtr outer, IProvideChannelBuilderSettings channelBuilderSettings) { if (channelBuilderSettings == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError (new InvalidOperationException (SR.GetString (SR.CannotCreateChannelOption))); ChannelCredentials ChannelCredentials = null; ComProxy proxy = null; try { ChannelCredentials = new ChannelCredentials (channelBuilderSettings) ; proxy = ComProxy.Create (outer, ChannelCredentials, ChannelCredentials); return proxy; } finally { if (proxy == null) { if (ChannelCredentials != null) ((IDisposable)ChannelCredentials).Dispose (); } } } void IDisposable.Dispose () { } void IChannelCredentials.SetWindowsCredential(string domain, string userName, string password, int impersonationLevel, bool allowNtlm) { lock (channelBuilderSettings) { KeyedByTypeCollectionbehaviors = channelBuilderSettings.Behaviors; NetworkCredential newCredentials = null; if ((!String.IsNullOrEmpty(domain)) || (!String.IsNullOrEmpty(userName)) || (!String.IsNullOrEmpty(password)) ) { if(String.IsNullOrEmpty(userName)) { userName = ""; } System.ServiceModel.Security.SecurityUtils.PrepareNetworkCredential(); newCredentials = new NetworkCredential(userName, password, domain); } ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.Windows.AllowedImpersonationLevel = (TokenImpersonationLevel)impersonationLevel; channelCredentials.Windows.AllowNtlm = allowNtlm; channelCredentials.Windows.ClientCredential = newCredentials; } } void IChannelCredentials.SetUserNameCredential(string userName, string password) { lock (channelBuilderSettings) { KeyedByTypeCollection behaviors = channelBuilderSettings.Behaviors; ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.UserName.UserName = userName; channelCredentials.UserName.Password = password; } } void IChannelCredentials.SetServiceCertificateAuthentication(string storeLocation, string revocationMode, string certificationValidationMode) { lock (channelBuilderSettings) { StoreLocation location = (StoreLocation)Enum.Parse(typeof(StoreLocation), storeLocation); X509RevocationMode mode = (X509RevocationMode)Enum.Parse(typeof(X509RevocationMode), revocationMode); X509CertificateValidationMode validationMode = X509ServiceCertificateAuthentication.DefaultCertificateValidationMode; if (!String.IsNullOrEmpty(certificationValidationMode)) validationMode = (X509CertificateValidationMode)Enum.Parse(typeof(X509CertificateValidationMode), certificationValidationMode); KeyedByTypeCollection behaviors = channelBuilderSettings.Behaviors; ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.ServiceCertificate.Authentication.TrustedStoreLocation = location; channelCredentials.ServiceCertificate.Authentication.RevocationMode = mode; channelCredentials.ServiceCertificate.Authentication.CertificateValidationMode = validationMode; } } void IChannelCredentials.SetClientCertificateFromStore(string storeLocation, string storeName, string findType, object findValue) { lock (channelBuilderSettings) { StoreLocation location = (StoreLocation)Enum.Parse(typeof(StoreLocation), storeLocation); StoreName name = (StoreName)Enum.Parse(typeof(StoreName), storeName); X509FindType type = (X509FindType)Enum.Parse(typeof(X509FindType), findType); KeyedByTypeCollection behaviors = channelBuilderSettings.Behaviors; ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.ClientCertificate.SetCertificate(location, name, type, findValue); } } void IChannelCredentials.SetClientCertificateFromStoreByName(string subjectName, string storeLocation, string storeName) { ((IChannelCredentials)this).SetClientCertificateFromStore(storeLocation, storeName, X509CertificateInitiatorClientCredential.DefaultFindType.ToString("G"), subjectName); } void IChannelCredentials.SetClientCertificateFromFile(string fileName, string password, string keyStorageFlags) { lock (channelBuilderSettings) { KeyedByTypeCollection behaviors = channelBuilderSettings.Behaviors; X509Certificate2 cert; if (!String.IsNullOrEmpty(keyStorageFlags)) { X509KeyStorageFlags flags = (X509KeyStorageFlags)Enum.Parse(typeof(X509KeyStorageFlags), keyStorageFlags); cert = new X509Certificate2(fileName, password, flags); } else { cert = new X509Certificate2(fileName, password); } ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.ClientCertificate.Certificate = cert; } } void IChannelCredentials.SetDefaultServiceCertificateFromStore(string storeLocation, string storeName, string findType, object findValue) { lock (channelBuilderSettings) { StoreLocation location = (StoreLocation)Enum.Parse(typeof(StoreLocation), storeLocation); StoreName name = (StoreName)Enum.Parse(typeof(StoreName), storeName); X509FindType type = (X509FindType)Enum.Parse(typeof(X509FindType), findType); KeyedByTypeCollection behaviors = channelBuilderSettings.Behaviors; ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.ServiceCertificate.SetDefaultCertificate(location, name, type, findValue); } } void IChannelCredentials.SetDefaultServiceCertificateFromStoreByName(string subjectName, string storeLocation, string storeName) { ((IChannelCredentials)this).SetDefaultServiceCertificateFromStore(storeLocation, storeName, X509CertificateInitiatorClientCredential.DefaultFindType.ToString("G"), subjectName); } void IChannelCredentials.SetDefaultServiceCertificateFromFile(string fileName, string password, string keyStorageFlags) { lock (channelBuilderSettings) { KeyedByTypeCollection behaviors = channelBuilderSettings.Behaviors; X509Certificate2 cert; if (!String.IsNullOrEmpty(keyStorageFlags)) { X509KeyStorageFlags flags = (X509KeyStorageFlags)Enum.Parse(typeof(X509KeyStorageFlags), keyStorageFlags); cert = new X509Certificate2(fileName, password, flags); } else { cert = new X509Certificate2(fileName, password); } ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.ServiceCertificate.DefaultCertificate = cert; } } void IChannelCredentials.SetIssuedToken(string localIssuerAddres, string localIssuerBindingType, string localIssuerBinding) { lock (channelBuilderSettings) { Binding binding = null; binding = ConfigLoader.LookupBinding (localIssuerBindingType, localIssuerBinding); KeyedByTypeCollection behaviors = channelBuilderSettings.Behaviors; ClientCredentials channelCredentials = behaviors.Find (); if (channelCredentials == null) { channelCredentials = new ClientCredentials(); behaviors.Add(channelCredentials); } channelCredentials.IssuedToken.LocalIssuerAddress = new EndpointAddress(localIssuerAddres); channelCredentials.IssuedToken.LocalIssuerBinding = binding; } } } } // 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
- SectionVisual.cs
- remotingproxy.cs
- DriveNotFoundException.cs
- lengthconverter.cs
- TypedDatasetGenerator.cs
- ClientRuntimeConfig.cs
- documentation.cs
- XmlDictionary.cs
- SqlDataSourceCache.cs
- PasswordBoxAutomationPeer.cs
- OleStrCAMarshaler.cs
- SortDescriptionCollection.cs
- DataRelation.cs
- SqlDataSourceConfigureSortForm.cs
- DataGridViewRowsAddedEventArgs.cs
- ExpressionBuilderCollection.cs
- RangeValidator.cs
- SqlServices.cs
- DropShadowEffect.cs
- GlyphRunDrawing.cs
- TreeIterator.cs
- sitestring.cs
- ObjRef.cs
- ObjectStateManagerMetadata.cs
- TriggerCollection.cs
- LabelLiteral.cs
- EntityConnectionStringBuilder.cs
- AccessedThroughPropertyAttribute.cs
- PresentationTraceSources.cs
- ActiveXHelper.cs
- LineServicesCallbacks.cs
- Serializer.cs
- PngBitmapDecoder.cs
- TrustManagerPromptUI.cs
- MachineSettingsSection.cs
- ResourceAttributes.cs
- BigInt.cs
- StateManager.cs
- XslAstAnalyzer.cs
- ArgIterator.cs
- DivideByZeroException.cs
- initElementDictionary.cs
- ArrayTypeMismatchException.cs
- XmlRawWriterWrapper.cs
- BuildResult.cs
- KerberosTicketHashIdentifierClause.cs
- WorkflowMessageEventArgs.cs
- ClientRoleProvider.cs
- PictureBox.cs
- UrlMappingsModule.cs
- DocumentNUp.cs
- SingleAnimationUsingKeyFrames.cs
- XmlQueryTypeFactory.cs
- CardSpacePolicyElement.cs
- AmbiguousMatchException.cs
- MasterPage.cs
- FilteredAttributeCollection.cs
- TransactionScope.cs
- TreeNodeStyle.cs
- PtsCache.cs
- ProcessingInstructionAction.cs
- BitmapImage.cs
- MarkedHighlightComponent.cs
- HwndProxyElementProvider.cs
- NamedServiceModelExtensionCollectionElement.cs
- SizeChangedInfo.cs
- AuthorizationRuleCollection.cs
- Policy.cs
- CollectionViewSource.cs
- WebPartExportVerb.cs
- _SSPISessionCache.cs
- DataRowCollection.cs
- QuadraticBezierSegment.cs
- TableLayoutStyleCollection.cs
- OverflowException.cs
- HitTestResult.cs
- CustomAttributeSerializer.cs
- CreateUserWizardStep.cs
- WebPartDisplayModeCollection.cs
- ImportCatalogPart.cs
- SqlCrossApplyToCrossJoin.cs
- ProfileSettingsCollection.cs
- ApplicationContext.cs
- PrePostDescendentsWalker.cs
- PartialCachingAttribute.cs
- OletxTransactionManager.cs
- GenericEnumerator.cs
- ListBase.cs
- CustomCredentialPolicy.cs
- PropertyKey.cs
- SqlConnectionManager.cs
- CacheOutputQuery.cs
- WorkflowCompensationBehavior.cs
- OutputWindow.cs
- ContainerFilterService.cs
- SortedDictionary.cs
- HtmlContainerControl.cs
- DataGridTextBoxColumn.cs
- ipaddressinformationcollection.cs
- QueryParameter.cs