SctClaimSerializer.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. namespace System.ServiceModel.Security
  5. {
  6. using System;
  7. using System.ServiceModel;
  8. using System.Security.Cryptography;
  9. using System.Security.Cryptography.X509Certificates;
  10. using System.ServiceModel.Security.Tokens;
  11. using System.IO;
  12. using System.Collections.Generic;
  13. using System.Collections.ObjectModel;
  14. using System.Net.Mail;
  15. using System.Xml;
  16. using System.Runtime.Serialization;
  17. using System.IdentityModel.Claims;
  18. using System.IdentityModel.Policy;
  19. using System.Security.Principal;
  20. static class SctClaimSerializer
  21. {
  22. static void SerializeSid(SecurityIdentifier sid, SctClaimDictionary dictionary, XmlDictionaryWriter writer)
  23. {
  24. byte[] sidBytes = new byte[sid.BinaryLength];
  25. sid.GetBinaryForm(sidBytes, 0);
  26. writer.WriteBase64(sidBytes, 0, sidBytes.Length);
  27. }
  28. static void WriteRightAttribute(Claim claim, SctClaimDictionary dictionary, XmlDictionaryWriter writer)
  29. {
  30. if (Rights.PossessProperty.Equals(claim.Right))
  31. return;
  32. writer.WriteAttributeString(dictionary.Right, dictionary.EmptyString, claim.Right);
  33. }
  34. static string ReadRightAttribute(XmlDictionaryReader reader, SctClaimDictionary dictionary)
  35. {
  36. string right = reader.GetAttribute(dictionary.Right, dictionary.EmptyString);
  37. return String.IsNullOrEmpty(right) ? Rights.PossessProperty : right;
  38. }
  39. static void WriteSidAttribute(SecurityIdentifier sid, SctClaimDictionary dictionary, XmlDictionaryWriter writer)
  40. {
  41. byte[] sidBytes = new byte[sid.BinaryLength];
  42. sid.GetBinaryForm(sidBytes, 0);
  43. writer.WriteAttributeString(dictionary.Sid, dictionary.EmptyString, Convert.ToBase64String(sidBytes));
  44. }
  45. static SecurityIdentifier ReadSidAttribute(XmlDictionaryReader reader, SctClaimDictionary dictionary)
  46. {
  47. byte[] sidBytes = Convert.FromBase64String(reader.GetAttribute(dictionary.Sid, dictionary.EmptyString));
  48. return new SecurityIdentifier(sidBytes, 0);
  49. }
  50. public static void SerializeClaim(Claim claim, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer)
  51. {
  52. // the order in which known claim types are checked is optimized for use patterns
  53. if (claim == null)
  54. {
  55. writer.WriteElementString(dictionary.NullValue, dictionary.EmptyString, string.Empty);
  56. return;
  57. }
  58. else if (ClaimTypes.Sid.Equals(claim.ClaimType))
  59. {
  60. writer.WriteStartElement(dictionary.WindowsSidClaim, dictionary.EmptyString);
  61. WriteRightAttribute(claim, dictionary, writer);
  62. SerializeSid((SecurityIdentifier)claim.Resource, dictionary, writer);
  63. writer.WriteEndElement();
  64. return;
  65. }
  66. else if (ClaimTypes.DenyOnlySid.Equals(claim.ClaimType))
  67. {
  68. writer.WriteStartElement(dictionary.DenyOnlySidClaim, dictionary.EmptyString);
  69. WriteRightAttribute(claim, dictionary, writer);
  70. SerializeSid((SecurityIdentifier)claim.Resource, dictionary, writer);
  71. writer.WriteEndElement();
  72. return;
  73. }
  74. else if (ClaimTypes.X500DistinguishedName.Equals(claim.ClaimType))
  75. {
  76. writer.WriteStartElement(dictionary.X500DistinguishedNameClaim, dictionary.EmptyString);
  77. WriteRightAttribute(claim, dictionary, writer);
  78. byte[] rawData = ((X500DistinguishedName)claim.Resource).RawData;
  79. writer.WriteBase64(rawData, 0, rawData.Length);
  80. writer.WriteEndElement();
  81. return;
  82. }
  83. else if (ClaimTypes.Thumbprint.Equals(claim.ClaimType))
  84. {
  85. writer.WriteStartElement(dictionary.X509ThumbprintClaim, dictionary.EmptyString);
  86. WriteRightAttribute(claim, dictionary, writer);
  87. byte[] thumbprint = (byte[])claim.Resource;
  88. writer.WriteBase64(thumbprint, 0, thumbprint.Length);
  89. writer.WriteEndElement();
  90. return;
  91. }
  92. else if (ClaimTypes.Name.Equals(claim.ClaimType))
  93. {
  94. writer.WriteStartElement(dictionary.NameClaim, dictionary.EmptyString);
  95. WriteRightAttribute(claim, dictionary, writer);
  96. writer.WriteString((string)claim.Resource);
  97. writer.WriteEndElement();
  98. return;
  99. }
  100. else if (ClaimTypes.Dns.Equals(claim.ClaimType))
  101. {
  102. writer.WriteStartElement(dictionary.DnsClaim, dictionary.EmptyString);
  103. WriteRightAttribute(claim, dictionary, writer);
  104. writer.WriteString((string)claim.Resource);
  105. writer.WriteEndElement();
  106. return;
  107. }
  108. else if (ClaimTypes.Rsa.Equals(claim.ClaimType))
  109. {
  110. writer.WriteStartElement(dictionary.RsaClaim, dictionary.EmptyString);
  111. WriteRightAttribute(claim, dictionary, writer);
  112. writer.WriteString(((RSA)claim.Resource).ToXmlString(false));
  113. writer.WriteEndElement();
  114. return;
  115. }
  116. else if (ClaimTypes.Email.Equals(claim.ClaimType))
  117. {
  118. writer.WriteStartElement(dictionary.MailAddressClaim, dictionary.EmptyString);
  119. WriteRightAttribute(claim, dictionary, writer);
  120. writer.WriteString(((MailAddress)claim.Resource).Address);
  121. writer.WriteEndElement();
  122. return;
  123. }
  124. else if (claim == Claim.System)
  125. {
  126. writer.WriteElementString(dictionary.SystemClaim, dictionary.EmptyString, string.Empty);
  127. return;
  128. }
  129. else if (ClaimTypes.Hash.Equals(claim.ClaimType))
  130. {
  131. writer.WriteStartElement(dictionary.HashClaim, dictionary.EmptyString);
  132. WriteRightAttribute(claim, dictionary, writer);
  133. byte[] hash = (byte[])claim.Resource;
  134. writer.WriteBase64(hash, 0, hash.Length);
  135. writer.WriteEndElement();
  136. return;
  137. }
  138. else if (ClaimTypes.Spn.Equals(claim.ClaimType))
  139. {
  140. writer.WriteStartElement(dictionary.SpnClaim, dictionary.EmptyString);
  141. WriteRightAttribute(claim, dictionary, writer);
  142. writer.WriteString((string)claim.Resource);
  143. writer.WriteEndElement();
  144. return;
  145. }
  146. else if (ClaimTypes.Upn.Equals(claim.ClaimType))
  147. {
  148. writer.WriteStartElement(dictionary.UpnClaim, dictionary.EmptyString);
  149. WriteRightAttribute(claim, dictionary, writer);
  150. writer.WriteString((string)claim.Resource);
  151. writer.WriteEndElement();
  152. return;
  153. }
  154. else if (ClaimTypes.Uri.Equals(claim.ClaimType))
  155. {
  156. writer.WriteStartElement(dictionary.UrlClaim, dictionary.EmptyString);
  157. WriteRightAttribute(claim, dictionary, writer);
  158. writer.WriteString(((Uri)claim.Resource).AbsoluteUri);
  159. writer.WriteEndElement();
  160. return;
  161. }
  162. else
  163. {
  164. // this is an extensible claim... need to delegate to xml object serializer
  165. serializer.WriteObject(writer, claim);
  166. }
  167. }
  168. public static void SerializeClaimSet(ClaimSet claimSet, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer, XmlObjectSerializer claimSerializer)
  169. {
  170. if (claimSet is X509CertificateClaimSet)
  171. {
  172. X509CertificateClaimSet x509ClaimSet = (X509CertificateClaimSet)claimSet;
  173. writer.WriteStartElement(dictionary.X509CertificateClaimSet, dictionary.EmptyString);
  174. byte[] rawData = x509ClaimSet.X509Certificate.RawData;
  175. writer.WriteBase64(rawData, 0, rawData.Length);
  176. writer.WriteEndElement();
  177. }
  178. else if (claimSet == ClaimSet.System)
  179. {
  180. writer.WriteElementString(dictionary.SystemClaimSet, dictionary.EmptyString, String.Empty);
  181. }
  182. else if (claimSet == ClaimSet.Windows)
  183. {
  184. writer.WriteElementString(dictionary.WindowsClaimSet, dictionary.EmptyString, String.Empty);
  185. }
  186. else if (claimSet == ClaimSet.Anonymous)
  187. {
  188. writer.WriteElementString(dictionary.AnonymousClaimSet, dictionary.EmptyString, String.Empty);
  189. }
  190. else if (claimSet is WindowsClaimSet || claimSet is DefaultClaimSet)
  191. {
  192. writer.WriteStartElement(dictionary.ClaimSet, dictionary.EmptyString);
  193. writer.WriteStartElement(dictionary.PrimaryIssuer, dictionary.EmptyString);
  194. if (claimSet.Issuer == claimSet)
  195. {
  196. writer.WriteElementString(dictionary.NullValue, dictionary.EmptyString, string.Empty);
  197. }
  198. else
  199. {
  200. SerializeClaimSet(claimSet.Issuer, dictionary, writer, serializer, claimSerializer);
  201. }
  202. writer.WriteEndElement();
  203. foreach (Claim claim in claimSet)
  204. {
  205. writer.WriteStartElement(dictionary.Claim, dictionary.EmptyString);
  206. SerializeClaim(claim, dictionary, writer, claimSerializer);
  207. writer.WriteEndElement();
  208. }
  209. writer.WriteEndElement();
  210. }
  211. else
  212. {
  213. serializer.WriteObject(writer, claimSet);
  214. }
  215. }
  216. public static Claim DeserializeClaim(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer)
  217. {
  218. if (reader.IsStartElement(dictionary.NullValue, dictionary.EmptyString))
  219. {
  220. reader.ReadElementString();
  221. return null;
  222. }
  223. else if (reader.IsStartElement(dictionary.WindowsSidClaim, dictionary.EmptyString))
  224. {
  225. string right = ReadRightAttribute(reader, dictionary);
  226. reader.ReadStartElement();
  227. byte[] sidBytes = reader.ReadContentAsBase64();
  228. reader.ReadEndElement();
  229. return new Claim(ClaimTypes.Sid, new SecurityIdentifier(sidBytes, 0), right);
  230. }
  231. else if (reader.IsStartElement(dictionary.DenyOnlySidClaim, dictionary.EmptyString))
  232. {
  233. string right = ReadRightAttribute(reader, dictionary);
  234. reader.ReadStartElement();
  235. byte[] sidBytes = reader.ReadContentAsBase64();
  236. reader.ReadEndElement();
  237. return new Claim(ClaimTypes.DenyOnlySid, new SecurityIdentifier(sidBytes, 0), right);
  238. }
  239. else if (reader.IsStartElement(dictionary.X500DistinguishedNameClaim, dictionary.EmptyString))
  240. {
  241. string right = ReadRightAttribute(reader, dictionary);
  242. reader.ReadStartElement();
  243. byte[] rawData = reader.ReadContentAsBase64();
  244. reader.ReadEndElement();
  245. return new Claim(ClaimTypes.X500DistinguishedName, new X500DistinguishedName(rawData), right);
  246. }
  247. else if (reader.IsStartElement(dictionary.X509ThumbprintClaim, dictionary.EmptyString))
  248. {
  249. string right = ReadRightAttribute(reader, dictionary);
  250. reader.ReadStartElement();
  251. byte[] thumbprint = reader.ReadContentAsBase64();
  252. reader.ReadEndElement();
  253. return new Claim(ClaimTypes.Thumbprint, thumbprint, right);
  254. }
  255. else if (reader.IsStartElement(dictionary.NameClaim, dictionary.EmptyString))
  256. {
  257. string right = ReadRightAttribute(reader, dictionary);
  258. reader.ReadStartElement();
  259. string name = reader.ReadString();
  260. reader.ReadEndElement();
  261. return new Claim(ClaimTypes.Name, name, right);
  262. }
  263. else if (reader.IsStartElement(dictionary.DnsClaim, dictionary.EmptyString))
  264. {
  265. string right = ReadRightAttribute(reader, dictionary);
  266. reader.ReadStartElement();
  267. string dns = reader.ReadString();
  268. reader.ReadEndElement();
  269. return new Claim(ClaimTypes.Dns, dns, right);
  270. }
  271. else if (reader.IsStartElement(dictionary.RsaClaim, dictionary.EmptyString))
  272. {
  273. string right = ReadRightAttribute(reader, dictionary);
  274. reader.ReadStartElement();
  275. string rsaXml = reader.ReadString();
  276. reader.ReadEndElement();
  277. System.Security.Cryptography.RSACryptoServiceProvider rsa = new System.Security.Cryptography.RSACryptoServiceProvider();
  278. rsa.FromXmlString(rsaXml);
  279. return new Claim(ClaimTypes.Rsa, rsa, right);
  280. }
  281. else if (reader.IsStartElement(dictionary.MailAddressClaim, dictionary.EmptyString))
  282. {
  283. string right = ReadRightAttribute(reader, dictionary);
  284. reader.ReadStartElement();
  285. string address = reader.ReadString();
  286. reader.ReadEndElement();
  287. return new Claim(ClaimTypes.Email, new System.Net.Mail.MailAddress(address), right);
  288. }
  289. else if (reader.IsStartElement(dictionary.SystemClaim, dictionary.EmptyString))
  290. {
  291. reader.ReadElementString();
  292. return Claim.System;
  293. }
  294. else if (reader.IsStartElement(dictionary.HashClaim, dictionary.EmptyString))
  295. {
  296. string right = ReadRightAttribute(reader, dictionary);
  297. reader.ReadStartElement();
  298. byte[] hash = reader.ReadContentAsBase64();
  299. reader.ReadEndElement();
  300. return new Claim(ClaimTypes.Hash, hash, right);
  301. }
  302. else if (reader.IsStartElement(dictionary.SpnClaim, dictionary.EmptyString))
  303. {
  304. string right = ReadRightAttribute(reader, dictionary);
  305. reader.ReadStartElement();
  306. string spn = reader.ReadString();
  307. reader.ReadEndElement();
  308. return new Claim(ClaimTypes.Spn, spn, right);
  309. }
  310. else if (reader.IsStartElement(dictionary.UpnClaim, dictionary.EmptyString))
  311. {
  312. string right = ReadRightAttribute(reader, dictionary);
  313. reader.ReadStartElement();
  314. string upn = reader.ReadString();
  315. reader.ReadEndElement();
  316. return new Claim(ClaimTypes.Upn, upn, right);
  317. }
  318. else if (reader.IsStartElement(dictionary.UrlClaim, dictionary.EmptyString))
  319. {
  320. string right = ReadRightAttribute(reader, dictionary);
  321. reader.ReadStartElement();
  322. string url = reader.ReadString();
  323. reader.ReadEndElement();
  324. return new Claim(ClaimTypes.Uri, new Uri(url), right);
  325. }
  326. else
  327. {
  328. return (Claim)serializer.ReadObject(reader);
  329. }
  330. }
  331. public static ClaimSet DeserializeClaimSet(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer, XmlObjectSerializer claimSerializer)
  332. {
  333. if (reader.IsStartElement(dictionary.NullValue, dictionary.EmptyString))
  334. {
  335. reader.ReadElementString();
  336. return null;
  337. }
  338. else if (reader.IsStartElement(dictionary.X509CertificateClaimSet, dictionary.EmptyString))
  339. {
  340. reader.ReadStartElement();
  341. byte[] rawData = reader.ReadContentAsBase64();
  342. reader.ReadEndElement();
  343. return new X509CertificateClaimSet(new X509Certificate2(rawData), false);
  344. }
  345. else if (reader.IsStartElement(dictionary.SystemClaimSet, dictionary.EmptyString))
  346. {
  347. reader.ReadElementString();
  348. return ClaimSet.System;
  349. }
  350. else if (reader.IsStartElement(dictionary.WindowsClaimSet, dictionary.EmptyString))
  351. {
  352. reader.ReadElementString();
  353. return ClaimSet.Windows;
  354. }
  355. else if (reader.IsStartElement(dictionary.AnonymousClaimSet, dictionary.EmptyString))
  356. {
  357. reader.ReadElementString();
  358. return ClaimSet.Anonymous;
  359. }
  360. else if (reader.IsStartElement(dictionary.ClaimSet, dictionary.EmptyString))
  361. {
  362. ClaimSet issuer = null;
  363. List<Claim> claims = new List<Claim>();
  364. reader.ReadStartElement();
  365. if (reader.IsStartElement(dictionary.PrimaryIssuer, dictionary.EmptyString))
  366. {
  367. reader.ReadStartElement();
  368. issuer = DeserializeClaimSet(reader, dictionary, serializer, claimSerializer);
  369. reader.ReadEndElement();
  370. }
  371. while (reader.IsStartElement())
  372. {
  373. reader.ReadStartElement();
  374. claims.Add(DeserializeClaim(reader, dictionary, claimSerializer));
  375. reader.ReadEndElement();
  376. }
  377. reader.ReadEndElement();
  378. return issuer != null ? new DefaultClaimSet(issuer, claims) : new DefaultClaimSet(claims);
  379. }
  380. else
  381. {
  382. return (ClaimSet)serializer.ReadObject(reader);
  383. }
  384. }
  385. public static void SerializeIdentities(AuthorizationContext authContext, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer)
  386. {
  387. object obj;
  388. IList<IIdentity> identities;
  389. if (authContext.Properties.TryGetValue(SecurityUtils.Identities, out obj))
  390. {
  391. identities = obj as IList<IIdentity>;
  392. if (identities != null && identities.Count > 0)
  393. {
  394. writer.WriteStartElement(dictionary.Identities, dictionary.EmptyString);
  395. for (int i = 0; i < identities.Count; ++i)
  396. {
  397. SerializePrimaryIdentity(identities[i], dictionary, writer, serializer);
  398. }
  399. writer.WriteEndElement();
  400. }
  401. }
  402. }
  403. static void SerializePrimaryIdentity(IIdentity identity, SctClaimDictionary dictionary, XmlDictionaryWriter writer, XmlObjectSerializer serializer)
  404. {
  405. if (identity != null && identity != SecurityUtils.AnonymousIdentity)
  406. {
  407. writer.WriteStartElement(dictionary.PrimaryIdentity, dictionary.EmptyString);
  408. if (identity is WindowsIdentity)
  409. {
  410. WindowsIdentity wid = (WindowsIdentity)identity;
  411. writer.WriteStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString);
  412. WriteSidAttribute(wid.User, dictionary, writer);
  413. // This is to work around WOW64 bug Windows OS 1491447
  414. string authenticationType = null;
  415. using (WindowsIdentity self = WindowsIdentity.GetCurrent())
  416. {
  417. // is owner or admin? AuthenticationType could throw un-authorized exception
  418. if ((self.User == wid.Owner) ||
  419. (wid.Owner != null && self.Groups.Contains(wid.Owner)) ||
  420. (wid.Owner != SecurityUtils.AdministratorsSid && self.Groups.Contains(SecurityUtils.AdministratorsSid)))
  421. {
  422. authenticationType = wid.AuthenticationType;
  423. }
  424. }
  425. if (!String.IsNullOrEmpty(authenticationType))
  426. writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, authenticationType);
  427. writer.WriteString(wid.Name);
  428. writer.WriteEndElement();
  429. }
  430. else if (identity is WindowsSidIdentity)
  431. {
  432. WindowsSidIdentity wsid = (WindowsSidIdentity)identity;
  433. writer.WriteStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString);
  434. WriteSidAttribute(wsid.SecurityIdentifier, dictionary, writer);
  435. if (!String.IsNullOrEmpty(wsid.AuthenticationType))
  436. writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, wsid.AuthenticationType);
  437. writer.WriteString(wsid.Name);
  438. writer.WriteEndElement();
  439. }
  440. else if (identity is GenericIdentity)
  441. {
  442. GenericIdentity genericIdentity = (GenericIdentity)identity;
  443. writer.WriteStartElement(dictionary.GenericIdentity, dictionary.EmptyString);
  444. if (!String.IsNullOrEmpty(genericIdentity.AuthenticationType))
  445. writer.WriteAttributeString(dictionary.AuthenticationType, dictionary.EmptyString, genericIdentity.AuthenticationType);
  446. writer.WriteString(genericIdentity.Name);
  447. writer.WriteEndElement();
  448. }
  449. else
  450. {
  451. serializer.WriteObject(writer, identity);
  452. }
  453. writer.WriteEndElement();
  454. }
  455. }
  456. public static IList<IIdentity> DeserializeIdentities(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer)
  457. {
  458. List<IIdentity> identities = null;
  459. if (reader.IsStartElement(dictionary.Identities, dictionary.EmptyString))
  460. {
  461. identities = new List<IIdentity>();
  462. reader.ReadStartElement();
  463. while (reader.IsStartElement(dictionary.PrimaryIdentity, dictionary.EmptyString))
  464. {
  465. IIdentity identity = DeserializePrimaryIdentity(reader, dictionary, serializer);
  466. if (identity != null && identity != SecurityUtils.AnonymousIdentity)
  467. {
  468. identities.Add(identity);
  469. }
  470. }
  471. reader.ReadEndElement();
  472. }
  473. return identities;
  474. }
  475. static IIdentity DeserializePrimaryIdentity(XmlDictionaryReader reader, SctClaimDictionary dictionary, XmlObjectSerializer serializer)
  476. {
  477. IIdentity identity = null;
  478. if (reader.IsStartElement(dictionary.PrimaryIdentity, dictionary.EmptyString))
  479. {
  480. reader.ReadStartElement();
  481. if (reader.IsStartElement(dictionary.WindowsSidIdentity, dictionary.EmptyString))
  482. {
  483. SecurityIdentifier sid = ReadSidAttribute(reader, dictionary);
  484. string authenticationType = reader.GetAttribute(dictionary.AuthenticationType, dictionary.EmptyString);
  485. reader.ReadStartElement();
  486. string name = reader.ReadContentAsString();
  487. identity = new WindowsSidIdentity(sid, name, authenticationType ?? String.Empty);
  488. reader.ReadEndElement();
  489. }
  490. else if (reader.IsStartElement(dictionary.GenericIdentity, dictionary.EmptyString))
  491. {
  492. string authenticationType = reader.GetAttribute(dictionary.AuthenticationType, dictionary.EmptyString);
  493. reader.ReadStartElement();
  494. string name = reader.ReadContentAsString();
  495. identity = SecurityUtils.CreateIdentity(name, authenticationType ?? String.Empty);
  496. reader.ReadEndElement();
  497. }
  498. else
  499. {
  500. identity = (IIdentity)serializer.ReadObject(reader);
  501. }
  502. reader.ReadEndElement();
  503. }
  504. return identity;
  505. }
  506. }
  507. }