Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / EndpointIdentity.cs / 1 / EndpointIdentity.cs
//---------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System; using System.Net; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.DirectoryServices; using System.DirectoryServices.ActiveDirectory; using System.Security.Principal; using System.ServiceModel.Security; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.ServiceModel.Channels; using System.ServiceModel.Diagnostics; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Xml; using System.Xml.Serialization; public abstract class EndpointIdentity { internal const StoreLocation defaultStoreLocation = StoreLocation.LocalMachine; internal const StoreName defaultStoreName = StoreName.My; internal const X509FindType defaultX509FindType = X509FindType.FindBySubjectDistinguishedName; Claim identityClaim; IEqualityComparerclaimComparer; protected EndpointIdentity() { } protected void Initialize(Claim identityClaim) { if (identityClaim == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("identityClaim"); Initialize(identityClaim, null); } protected void Initialize(Claim identityClaim, IEqualityComparer claimComparer) { if (identityClaim == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("identityClaim"); this.identityClaim = identityClaim; this.claimComparer = claimComparer; } public Claim IdentityClaim { get { if (this.identityClaim == null) { EnsureIdentityClaim(); } return this.identityClaim; } } public static EndpointIdentity CreateIdentity(Claim identity) { if (identity == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("identity"); // PreSharp Bug: Parameter 'identity.ClaimType' to this public method must be validated: A null-dereference can occur here. #pragma warning suppress 56506 // Claim.ClaimType will never return null if (identity.ClaimType.Equals(ClaimTypes.Dns)) { return new DnsEndpointIdentity(identity); } else if (identity.ClaimType.Equals(ClaimTypes.Spn)) { return new SpnEndpointIdentity(identity); } else if (identity.ClaimType.Equals(ClaimTypes.Upn)) { return new UpnEndpointIdentity(identity); } else if (identity.ClaimType.Equals(ClaimTypes.Rsa)) { return new RsaEndpointIdentity(identity); } else { return new GeneralEndpointIdentity(identity); } } public static EndpointIdentity CreateDnsIdentity(string dnsName) { return new DnsEndpointIdentity(dnsName); } public static EndpointIdentity CreateSpnIdentity(string spnName) { return new SpnEndpointIdentity(spnName); } public static EndpointIdentity CreateUpnIdentity(string upnName) { return new UpnEndpointIdentity(upnName); } public static EndpointIdentity CreateRsaIdentity(string publicKey) { return new RsaEndpointIdentity(publicKey); } public static EndpointIdentity CreateRsaIdentity(X509Certificate2 certificate) { return new RsaEndpointIdentity(certificate); } public static EndpointIdentity CreateX509CertificateIdentity(X509Certificate2 certificate) { return new X509CertificateEndpointIdentity(certificate); } public static EndpointIdentity CreateX509CertificateIdentity(X509Certificate2 primaryCertificate, X509Certificate2Collection supportingCertificates) { return new X509CertificateEndpointIdentity(primaryCertificate, supportingCertificates); } internal static EndpointIdentity CreateX509CertificateIdentity(X509Chain certificateChain) { if (certificateChain == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("certificateChain"); if (certificateChain.ChainElements.Count == 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.X509ChainIsEmpty)); // The first element in the cert chain is the leaf certificate // we want. X509Certificate2 primaryCertificate = certificateChain.ChainElements[0].Certificate; X509Certificate2Collection certificateCollection = new X509Certificate2Collection(); for (int i = 1; i < certificateChain.ChainElements.Count; ++i) { certificateCollection.Add(certificateChain.ChainElements[i].Certificate); } return new X509CertificateEndpointIdentity(primaryCertificate, certificateCollection); } internal virtual void EnsureIdentityClaim() { } public override bool Equals(object obj) { if (obj == (object) this) return true; // as handles null do we need the double null check? if (obj == null) return false; EndpointIdentity otherIdentity = obj as EndpointIdentity; if (otherIdentity == null) return false; return Matches(otherIdentity.IdentityClaim); } public override int GetHashCode() { return GetClaimComparer().GetHashCode(this.IdentityClaim); } public override string ToString() { return "identity(" + this.IdentityClaim + ")"; } internal bool Matches(Claim claim) { return GetClaimComparer().Equals(this.IdentityClaim, claim); } IEqualityComparer GetClaimComparer() { if (this.claimComparer == null) this.claimComparer = Claim.DefaultComparer; return this.claimComparer; } internal static EndpointIdentity ReadIdentity(XmlDictionaryReader reader) { if (reader == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader"); EndpointIdentity readIdentity = null; reader.MoveToContent(); if (reader.IsEmptyElement) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.UnexpectedEmptyElementExpectingClaim, XD.AddressingDictionary.Identity.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value))); reader.ReadStartElement(XD.AddressingDictionary.Identity, XD.AddressingDictionary.IdentityExtensionNamespace); if (reader.IsStartElement(XD.AddressingDictionary.Spn, XD.AddressingDictionary.IdentityExtensionNamespace)) readIdentity = new SpnEndpointIdentity(reader.ReadElementString()); else if (reader.IsStartElement(XD.AddressingDictionary.Upn, XD.AddressingDictionary.IdentityExtensionNamespace)) readIdentity = new UpnEndpointIdentity(reader.ReadElementString()); else if (reader.IsStartElement(XD.AddressingDictionary.Dns, XD.AddressingDictionary.IdentityExtensionNamespace)) readIdentity = new DnsEndpointIdentity(reader.ReadElementString()); else if (reader.IsStartElement(XD.XmlSignatureDictionary.KeyInfo, XD.XmlSignatureDictionary.Namespace)) { reader.ReadStartElement(); if (reader.IsStartElement(XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace)) { readIdentity = new X509CertificateEndpointIdentity(reader); } else if (reader.IsStartElement(XD.XmlSignatureDictionary.RsaKeyValue, XD.XmlSignatureDictionary.Namespace)) { readIdentity = new RsaEndpointIdentity(reader); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.UnrecognizedIdentityType, reader.Name, reader.NamespaceURI))); } reader.ReadEndElement(); } else if (reader.NodeType == XmlNodeType.Element) { // // Something unknown // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.UnrecognizedIdentityType, reader.Name, reader.NamespaceURI))); } else { // // EndpointIdentity element is empty or some other invalid xml // throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidIdentityElement))); } reader.ReadEndElement(); return readIdentity; } internal void WriteTo(XmlDictionaryWriter writer) { if (writer == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); writer.WriteStartElement(XD.AddressingDictionary.Identity, XD.AddressingDictionary.IdentityExtensionNamespace); WriteContentsTo(writer); writer.WriteEndElement(); } internal virtual void WriteContentsTo(XmlDictionaryWriter writer) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.UnrecognizedIdentityPropertyType, this.IdentityClaim.GetType().ToString()))); } } } // 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
- DataControlImageButton.cs
- odbcmetadatafactory.cs
- SoapDocumentMethodAttribute.cs
- LinearQuaternionKeyFrame.cs
- log.cs
- ContentElement.cs
- SplitContainerDesigner.cs
- VisualCollection.cs
- Canvas.cs
- ParameterCollectionEditorForm.cs
- ProviderConnectionPoint.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- UpdatableGenericsFeature.cs
- AnimationException.cs
- SafeFileMappingHandle.cs
- PreProcessInputEventArgs.cs
- AnonymousIdentificationModule.cs
- HeaderUtility.cs
- EncodingFallbackAwareXmlTextWriter.cs
- PersonalizationStateInfo.cs
- Int32Storage.cs
- AccessText.cs
- WebBrowserContainer.cs
- HttpWriter.cs
- InternalRelationshipCollection.cs
- TopClause.cs
- StyleSheetDesigner.cs
- Path.cs
- TransferRequestHandler.cs
- CommandManager.cs
- HandlerFactoryWrapper.cs
- MissingManifestResourceException.cs
- URLAttribute.cs
- ActivationServices.cs
- PreloadHost.cs
- COM2PropertyPageUITypeConverter.cs
- ExecutionEngineException.cs
- IndentedWriter.cs
- PixelFormat.cs
- CompiledXpathExpr.cs
- Adorner.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- EdgeModeValidation.cs
- BamlCollectionHolder.cs
- Size.cs
- QueuePathEditor.cs
- Page.cs
- SchemaEntity.cs
- sqlser.cs
- ZipIOExtraField.cs
- FixUpCollection.cs
- WizardStepBase.cs
- InputQueueChannel.cs
- InternalMappingException.cs
- CloudCollection.cs
- MemberRelationshipService.cs
- InputReferenceExpression.cs
- MarkupExtensionParser.cs
- BufferedConnection.cs
- SelectionListDesigner.cs
- ComEventsHelper.cs
- EntityDescriptor.cs
- Funcletizer.cs
- TextDecoration.cs
- MainMenu.cs
- SecurityTokenRequirement.cs
- DataTableCollection.cs
- XhtmlTextWriter.cs
- SrgsText.cs
- XNodeSchemaApplier.cs
- EmissiveMaterial.cs
- SrgsElement.cs
- ProfileSection.cs
- Base64Encoder.cs
- loginstatus.cs
- DispatcherProcessingDisabled.cs
- PictureBoxDesigner.cs
- AvtEvent.cs
- FunctionUpdateCommand.cs
- SqlNotificationRequest.cs
- Visual.cs
- BadImageFormatException.cs
- TrackBarRenderer.cs
- ImmutableObjectAttribute.cs
- DataRowView.cs
- WindowsSolidBrush.cs
- TextTreeTextNode.cs
- CompilerParameters.cs
- recordstate.cs
- TextDecorationUnitValidation.cs
- NumberFormatInfo.cs
- ToolStripPanelRow.cs
- RadioButtonBaseAdapter.cs
- PageSettings.cs
- ConfigurationSectionGroupCollection.cs
- CannotUnloadAppDomainException.cs
- FontNamesConverter.cs
- LinkConverter.cs
- FileReservationCollection.cs
- DeflateStream.cs