first commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using Landmark.OLA.Models.OnlineBanking;
|
||||
using System.Xml;
|
||||
|
||||
namespace OnlineBankingAuth.Parsers
|
||||
{
|
||||
public class SAMLParser : ISAMLParser<DISAMLAssertion>
|
||||
{
|
||||
public string SAML_NAMESPACE = "saml:";
|
||||
|
||||
public DISAMLAssertion ParseAssertion(XmlElement xmlElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var assertion = new DISAMLAssertion
|
||||
{
|
||||
NameID = xmlElement.GetElementsByTagName(SAML_NAMESPACE + "NameID")[0].InnerText,
|
||||
Recipient = xmlElement.GetElementsByTagName(SAML_NAMESPACE + "SubjectConfirmationData")[0].Attributes[1].InnerText,
|
||||
MemberID = xmlElement.GetElementsByTagName(SAML_NAMESPACE + "AttributeValue")[0].InnerText,
|
||||
FI_ID = xmlElement.GetElementsByTagName(SAML_NAMESPACE + "AttributeValue")[1].InnerText,
|
||||
AuthnStatement = ParseAuthnStatement(xmlElement),
|
||||
Conditions = ParseConditions(xmlElement),
|
||||
|
||||
};
|
||||
|
||||
return assertion;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new FormatException("SAML Response is in an unexpected layout.");
|
||||
}
|
||||
}
|
||||
|
||||
public AuthenticationStatement ParseAuthnStatement(XmlElement xmlElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
var authnStatement = new AuthenticationStatement
|
||||
{
|
||||
SessionIndex = xmlElement.GetElementsByTagName(SAML_NAMESPACE + "AuthnStatement")[0].Attributes[1].InnerText,
|
||||
AuthContextClassRef = xmlElement.GetElementsByTagName(SAML_NAMESPACE + "AuthnContextClassRef")[0].InnerText
|
||||
};
|
||||
return authnStatement;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new FormatException("AuthnStatement is in an unexpected layout.");
|
||||
}
|
||||
}
|
||||
|
||||
public SAMLConditions ParseConditions(XmlElement xmlElement)
|
||||
{
|
||||
try
|
||||
{
|
||||
var conditions = new SAMLConditions
|
||||
{
|
||||
Audience = xmlElement.GetElementsByTagName(SAML_NAMESPACE + "Audience")[0].InnerText,
|
||||
NotBefore = DateTime.Parse(xmlElement.GetElementsByTagName(SAML_NAMESPACE + "Conditions")[0].Attributes[0].InnerText),
|
||||
NotAfter = DateTime.Parse(xmlElement.GetElementsByTagName(SAML_NAMESPACE + "Conditions")[0].Attributes[1].InnerText),
|
||||
};
|
||||
return conditions;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new FormatException("SAML Conditions is in an unexpected layout");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user