/// <summary> /// Gets the identity. /// </summary> /// <param name="element">The element.</param> /// <returns>EndpointIdentity.</returns> /// <exception cref="System.InvalidOperationException">UnableToLoadCertificateIdentity</exception> private static EndpointIdentity GetIdentity(IdentityElement element) { var properties = element.ElementInformation.Properties; var userPrincipalName = properties["userPrincipalName"]; if (userPrincipalName != null && userPrincipalName.ValueOrigin != PropertyValueOrigin.Default) { return EndpointIdentity.CreateUpnIdentity(element.UserPrincipalName.Value); } var servicePrincipalName = properties["servicePrincipalName"]; if (servicePrincipalName != null && servicePrincipalName.ValueOrigin != PropertyValueOrigin.Default) { return EndpointIdentity.CreateSpnIdentity(element.ServicePrincipalName.Value); } var dns = properties["dns"]; if (dns != null && dns.ValueOrigin != PropertyValueOrigin.Default) { return EndpointIdentity.CreateDnsIdentity(element.Dns.Value); } var rsa = properties["rsa"]; if (rsa != null && rsa.ValueOrigin != PropertyValueOrigin.Default) { return EndpointIdentity.CreateRsaIdentity(element.Rsa.Value); } var certificate = properties["certificate"]; if (certificate != null && certificate.ValueOrigin != PropertyValueOrigin.Default) { var supportingCertificates = new X509Certificate2Collection(); supportingCertificates.Import(Convert.FromBase64String(element.Certificate.EncodedValue)); if (supportingCertificates.Count == 0) { throw new InvalidOperationException("UnableToLoadCertificateIdentity"); } var primaryCertificate = supportingCertificates[0]; supportingCertificates.RemoveAt(0); return EndpointIdentity.CreateX509CertificateIdentity(primaryCertificate, supportingCertificates); } return null; }