object ReadHeaderObject (Type type, XmlObjectSerializer serializer, XmlDictionaryReader reader) { // FIXME: it's a nasty workaround just to avoid UniqueId output as a string. // Seealso MessageHeader.DefaultMessageHeader.OnWriteHeaderContents(). // Note that msg.Headers.GetHeader<UniqueId> () simply fails (on .NET too) and it is useless. The API is lame by design. if (type == typeof (UniqueId)) return new UniqueId (reader.ReadElementContentAsString ()); else return serializer.ReadObject (reader); }
static IIdentity DeserializePrimaryIdentity(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer) { IIdentity identity = null; if (reader.IsStartElement(dictionary.PrimaryIdentity, dictionary.EmptyString)) { reader.ReadStartElement(); if (reader.IsStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString)) { SecurityIdentifier sid = ReadSidAttribute(reader, dictionary); string authenticationType = reader.GetAttribute(dictionary.AuthenticationType, dictionary.EmptyString); reader.ReadStartElement(); string name = reader.ReadContentAsString(); identity = new WindowsSidIdentity(sid, name, authenticationType ?? String.Empty); reader.ReadEndElement(); } else if (reader.IsStartElement(dictionary.GenericIdentity, dictionary.EmptyString)) { string authenticationType = reader.GetAttribute(dictionary.AuthenticationType, dictionary.EmptyString); reader.ReadStartElement(); string name = reader.ReadContentAsString(); identity = SecurityUtils.CreateIdentity(name, authenticationType ?? String.Empty); reader.ReadEndElement(); } else { identity = (IIdentity)serializer.ReadObject(reader); } reader.ReadEndElement(); } return identity; }
public static ClaimSet DeserializeClaimSet(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer, XmlObjectSerializer claimSerializer) { if (reader.IsStartElement(dictionary.NullValue, dictionary.EmptyString)) { reader.ReadElementString(); return null; } else if (reader.IsStartElement(dictionary.X509CertificateClaimSet, dictionary.EmptyString)) { reader.ReadStartElement(); byte[] rawData = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new X509CertificateClaimSet(new X509Certificate2(rawData), false); } else if (reader.IsStartElement(dictionary.SystemClaimSet, dictionary.EmptyString)) { reader.ReadElementString(); return ClaimSet.System; } else if (reader.IsStartElement(dictionary.WindowsClaimSet, dictionary.EmptyString)) { reader.ReadElementString(); return ClaimSet.Windows; } else if (reader.IsStartElement(dictionary.AnonymousClaimSet, dictionary.EmptyString)) { reader.ReadElementString(); return ClaimSet.Anonymous; } else if (reader.IsStartElement(dictionary.ClaimSet, dictionary.EmptyString)) { ClaimSet issuer = null; List<Claim> claims = new List<Claim>(); reader.ReadStartElement(); if (reader.IsStartElement(dictionary.PrimaryIssuer, dictionary.EmptyString)) { reader.ReadStartElement(); issuer = DeserializeClaimSet(reader, dictionary, serializer, claimSerializer); reader.ReadEndElement(); } while (reader.IsStartElement()) { reader.ReadStartElement(); claims.Add(DeserializeClaim(reader, dictionary, claimSerializer)); reader.ReadEndElement(); } reader.ReadEndElement(); return issuer != null ? new DefaultClaimSet(issuer, claims) : new DefaultClaimSet(claims); } else { return (ClaimSet)serializer.ReadObject(reader); } }
public static Claim DeserializeClaim(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer) { if (reader.IsStartElement(dictionary.NullValue, dictionary.EmptyString)) { reader.ReadElementString(); return null; } else if (reader.IsStartElement(dictionary.WindowsSidClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] sidBytes = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.Sid, new SecurityIdentifier(sidBytes, 0), right); } else if (reader.IsStartElement(dictionary.DenyOnlySidClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] sidBytes = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.DenyOnlySid, new SecurityIdentifier(sidBytes, 0), right); } else if (reader.IsStartElement(dictionary.X500DistinguishedNameClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] rawData = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.X500DistinguishedName, new X500DistinguishedName(rawData), right); } else if (reader.IsStartElement(dictionary.X509ThumbprintClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] thumbprint = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.Thumbprint, thumbprint, right); } else if (reader.IsStartElement(dictionary.NameClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string name = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Name, name, right); } else if (reader.IsStartElement(dictionary.DnsClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string dns = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Dns, dns, right); } else if (reader.IsStartElement(dictionary.RsaClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string rsaXml = reader.ReadString(); reader.ReadEndElement(); System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider(); rsa.FromXmlString(rsaXml); return new Claim(ClaimTypes.Rsa, rsa, right); } else if (reader.IsStartElement(dictionary.MailAddressClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string address = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Email, new System.Net.Mail.MailAddress(address), right); } else if (reader.IsStartElement(dictionary.SystemClaim, dictionary.EmptyString)) { reader.ReadElementString(); return Claim.System; } else if (reader.IsStartElement(dictionary.HashClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] hash = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.Hash, hash, right); } else if (reader.IsStartElement(dictionary.SpnClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string spn = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Spn, spn, right); } else if (reader.IsStartElement(dictionary.UpnClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string upn = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Upn, upn, right); } else if (reader.IsStartElement(dictionary.UrlClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string url = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Uri, new Uri(url), right); } else { return (Claim)serializer.ReadObject(reader); } }
public static Claim DeserializeClaim(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer) { if (reader.IsStartElement(dictionary.NullValue, dictionary.EmptyString)) { reader.ReadElementString(); return null; } if (reader.IsStartElement(dictionary.WindowsSidClaim, dictionary.EmptyString)) { string right = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] binaryForm = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.Sid, new SecurityIdentifier(binaryForm, 0), right); } if (reader.IsStartElement(dictionary.DenyOnlySidClaim, dictionary.EmptyString)) { string str2 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] buffer2 = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.DenyOnlySid, new SecurityIdentifier(buffer2, 0), str2); } if (reader.IsStartElement(dictionary.X500DistinguishedNameClaim, dictionary.EmptyString)) { string str3 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] encodedDistinguishedName = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.X500DistinguishedName, new X500DistinguishedName(encodedDistinguishedName), str3); } if (reader.IsStartElement(dictionary.X509ThumbprintClaim, dictionary.EmptyString)) { string str4 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] resource = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.Thumbprint, resource, str4); } if (reader.IsStartElement(dictionary.NameClaim, dictionary.EmptyString)) { string str5 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string str6 = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Name, str6, str5); } if (reader.IsStartElement(dictionary.DnsClaim, dictionary.EmptyString)) { string str7 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string str8 = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Dns, str8, str7); } if (reader.IsStartElement(dictionary.RsaClaim, dictionary.EmptyString)) { string str9 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string xmlString = reader.ReadString(); reader.ReadEndElement(); RSACryptoServiceProvider provider = new RSACryptoServiceProvider(); provider.FromXmlString(xmlString); return new Claim(ClaimTypes.Rsa, provider, str9); } if (reader.IsStartElement(dictionary.MailAddressClaim, dictionary.EmptyString)) { string str11 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string address = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Email, new MailAddress(address), str11); } if (reader.IsStartElement(dictionary.SystemClaim, dictionary.EmptyString)) { reader.ReadElementString(); return Claim.System; } if (reader.IsStartElement(dictionary.HashClaim, dictionary.EmptyString)) { string str13 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); byte[] buffer5 = reader.ReadContentAsBase64(); reader.ReadEndElement(); return new Claim(ClaimTypes.Hash, buffer5, str13); } if (reader.IsStartElement(dictionary.SpnClaim, dictionary.EmptyString)) { string str14 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string str15 = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Spn, str15, str14); } if (reader.IsStartElement(dictionary.UpnClaim, dictionary.EmptyString)) { string str16 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string str17 = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Upn, str17, str16); } if (reader.IsStartElement(dictionary.UrlClaim, dictionary.EmptyString)) { string str18 = ReadRightAttribute(reader, dictionary); reader.ReadStartElement(); string uriString = reader.ReadString(); reader.ReadEndElement(); return new Claim(ClaimTypes.Uri, new Uri(uriString), str18); } return (Claim) serializer.ReadObject(reader); }
/// <summary> /// </summary> /// <param name="inputStream"> /// The input stream. /// </param> /// <param name="serializer"> /// The serializer. /// </param> /// <returns> /// The load from stream. /// </returns> protected virtual object LoadFromStream(Stream inputStream, XmlObjectSerializer serializer) { return serializer.ReadObject(inputStream); }