.NET CAS Client


Note

This software has been lightly tested against the CAS infrastructure at Virginia Tech. Pending further testing, it should be considered alpha software. The CTU group at Tech supports its use in the Virginia Tech environment, and we encourage its use there. Groups outside the University are encouraged to use it with the understanding that we cannot support it outside Virginia Tech. Feedback, bug reports, and feature requests are welcome: myvt@vt.edu.

Download

CasClient.dll - Version 0.1a compiled against .NET Framework 1.1. This version has passed testing in the following environments:

  • VB.NET (Framework version 1.1)
  • C# (Framework version 2.0)

Although it has not been tested in C++.NET or with .NET Framework versions prior to 1.1, we have no reason to suspect it would not work fine in those environments as well.

Features

  • Supports CAS Protocols 1 (plain text response) and 2 (XML response)
  • Optional use of session to prevent CAS round-trips on each validation call
  • Can be used in any .NET Web project (VB.NET, C#, C++.NET)

Limitations

  • Does not support CAS proxies. (We hope to add this support in the future.)
  • Can only be used in the .NET (Microsoft CLR) environment
  • Requires editing code for each page that requires authentication. (This is not so much of a limitation as something we thought we should mention. Other CAS clients (e.g. phpCAS) have the same requirement.)

Usage Examples

Add the CasClient.dll assembly to the References section of your project(s) before using the CasClient class in your code as in the examples below.

VB.NET
'// CAS protocol 2.0 authentication example (preferred)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   Dim message As String
   Dim client As Ctu.Cas.Client.CasClient
   Dim useSession As Boolean

   '// Uncomment the line below if you do not wish to use Session to store
   '// the results of authentication.  The consequence of not using Session storage
   '// is an additional round trip with the CAS server on every page
   '//client = New Ctu.Cas.Client.CasClient(False)
   client = New Ctu.Cas.Client.CasClient()

   client.CasServerName = "auth.vt.edu"
   If client.ServiceValidate(Me) Then
      message = "Service validation succeeded for user " + client.GetNetId
   Else
      message = "Service validation failed."
   End If
   System.Diagnostics.Debug.WriteLine(message)
   Label1.Text = message
End Sub

'// CAS protocol 1.0 authentication example
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   Dim message As String
   Dim client As Ctu.Cas.Client.CasClient
   Dim useSession As Boolean

   '// Uncomment the line below if you do not wish to use Session to store
   '// the results of authentication.  The consequence of not using Session storage
   '// is an additional round trip with the CAS server on every page
   '//client = New Ctu.Cas.Client.CasClient(False)
   client.CasServerName = "auth.vt.edu"
   If client.Validate(Me) Then
   	message = "Validation succeeded for user " + client.GetNetId
   Else
   	message = "Validation failed."
   End If
   System.Diagnostics.Debug.WriteLine(message)
   Label1.Text = message
End Sub

C#
// CAS protocol 2.0 authentication example (preferred)
private void Page_Load(object sender, System.EventArgs e)
{
   string message;
   Ctu.Cas.Client.CasClient client;

   // Uncomment the line below if you do not wish to use Session to store
   // the results of authentication.  The consequence of not using Session storage
   // is an additional round trip with the CAS server on every page
   //client = new Ctu.Cas.Client.CasClient(False)
   client = new Ctu.Cas.Client.CasClient();
   client.CasServerName = "auth.vt.edu";
   if (client.ServiceValidate(this))
   	 message = "Service validation succeeded for user " + client.GetNetId();
   else
   	 message = "Service validation failed.";

   System.Diagnostics.Debug.WriteLine(message);
   Label1.Text = message;
}

// CAS protocol 1.0 authentication example
private void Page_Load(object sender, System.EventArgs e)
{
   string message;
   Ctu.Cas.Client.CasClient client;

   // Uncomment the line below if you do not wish to use Session to store
   // the results of authentication.  The consequence of not using Session storage
   // is an additional round trip with the CAS server on every page
   //client = new Ctu.Cas.Client.CasClient(False)
   client.CasServerName = "auth.vt.edu";
   if (client.Validate(this))
   	 message = "Validation succeeded for user " + client.GetNetId();
   else
   	 message = "Validation failed.";

   System.Diagnostics.Debug.WriteLine(message);
   Label1.Text = message;
}

Debugging

The .NET CAS client has logging features provided by the .NET Tracing capability; the log messages are invaluable for identifying and resolving bugs. Tracing is enabled by modifying the Web.config file of the CAS-enabled ASP.NET Web application. Add the code below to the Web.config file immediately following the <system.web> node:

<system.diagnostics>
   <trace autoflush="true" indentsize="2">
   	<listeners>
   		<remove name="Default"/>
                <!-- 
                     Customize log file location as necessary.
                     Log file must be writable by ASPNET account! 
                -->
   		<add name="TraceLog"
   		type="System.Diagnostics.TextWriterTraceListener"
   		initializeData="C:\Temp\CasClientTest.log"/>
   	</listeners>
   </trace>
</system.diagnostics>

  • No labels