using System; using System.Xml; namespace Kreta.EESZTInterface.STS { public class SamlAssertion { public const string LocalName = "Assertion"; public string Id { get; } public string Issuer { get; } public string UserId { get; } public string UserName { get; } public DateTime NotBefore { get; } public DateTime NotOnOrAfter { get; } public XmlElement SamlAssertionElement { get; } public string Original { get; } public SamlAssertion(string content) { Original = content; var xDoc = new XmlDocument(); xDoc.LoadXml(content); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable); nsmgr.AddNamespace("saml", Namespaces.samlNs); SamlAssertionElement = xDoc.DocumentElement; Id = SamlAssertionElement.Attributes["ID"].Value; Issuer = SamlAssertionElement.SelectSingleNode("descendant::saml:Issuer", nsmgr).InnerText; UserId = SamlAssertionElement.SelectSingleNode("descendant::saml:NameID", nsmgr).InnerText; UserName = SamlAssertionElement.SelectSingleNode("descendant::saml:Attribute[@Name=\"displayName\"]", nsmgr).InnerText; var authStatementNode = SamlAssertionElement.SelectSingleNode("descendant::saml:Conditions", nsmgr); NotBefore = DateTime.Parse(authStatementNode.Attributes["NotBefore"].Value).ToUniversalTime(); NotOnOrAfter = DateTime.Parse(authStatementNode.Attributes["NotOnOrAfter"].Value).ToUniversalTime(); } } }