Skip to content
This repository has been archived by the owner on Dec 25, 2022. It is now read-only.

Implement IDisposable for .Net 4.6 #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions App_Code/Saml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OneLogin
{
namespace Saml
{
public class Certificate
public class Certificate : IDisposable
{
public X509Certificate2 cert;

Expand All @@ -46,9 +46,32 @@ private byte[] StringToByteArray(string st)
}
return bytes;
}
#region Dispose added for .Net 4.6
bool disposed = false;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (disposed)
return;

if (disposing)
{
cert.Dispose();
}

disposed = true;
}
#endregion

}

public class Response
public class Response: IDisposable
{
private XmlDocument xmlDoc;
private AccountSettings accountSettings;
Expand Down Expand Up @@ -135,6 +158,10 @@ public string GetNameID()
XmlNode node = xmlDoc.SelectSingleNode("/samlp:Response/saml:Assertion/saml:Subject/saml:NameID",manager);
return node.InnerText;
}
public void Dispose()
{
certificate.Dispose();
}
}

public class AuthRequest
Expand Down
22 changes: 12 additions & 10 deletions Consume.aspx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ protected void Page_Load(object sender, EventArgs e)
// replace with an instance of the users account.
AccountSettings accountSettings = new AccountSettings();

OneLogin.Saml.Response samlResponse = new Response(accountSettings);
samlResponse.LoadXmlFromBase64(Request.Form["SAMLResponse"]);

if (samlResponse.IsValid())
{
Response.Write("OK!");
Response.Write(samlResponse.GetNameID());
}
else
using (OneLogin.Saml.Response samlResponse = new Response(accountSettings))
{
Response.Write("Failed");
samlResponse.LoadXmlFromBase64(Request.Form["SAMLResponse"]);

if (samlResponse.IsValid())
{
Response.Write("OK!");
Response.Write(samlResponse.GetNameID());
}
else
{
Response.Write("Failed");
}
}
}
}