<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ryan's Tech Blog &#187; CAS</title>
	<atom:link href="http://ryepup.unwashedmeme.com/blog/category/cas/feed/" rel="self" type="application/rss+xml" />
	<link>http://ryepup.unwashedmeme.com/blog</link>
	<description>mostly tech, mostly rants</description>
	<lastBuildDate>Wed, 04 Jan 2012 03:42:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CAS Authentication in C#</title>
		<link>http://ryepup.unwashedmeme.com/blog/2007/06/19/cas-authentication-in-c/</link>
		<comments>http://ryepup.unwashedmeme.com/blog/2007/06/19/cas-authentication-in-c/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 19:22:42 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CAS]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://ryepup.unwashedmeme.com/blog/2007/06/19/cas-authentication-in-c/</guid>
		<description><![CDATA[For a recent project I wanted to authenticate using Central Authentication Service (CAS), a single-sign on server deployed world-wide. My project is in ASP.NET, so I hunted down CASP, a C# class produced by John Tantalo at Case Western Reserve University. Coincidentally, John was also responsible for Planarity, a flash game which has only stolen [...]]]></description>
			<content:encoded><![CDATA[<p>
For a recent project I wanted to authenticate using <a href="http://www.ja-sig.org/products/cas/index.html">Central Authentication Service</a> (CAS), a single-sign on server deployed <a href="http://www.frappr.com/jasigcasdeployers">world-wide</a>.  My project is in ASP.NET, so I hunted down <a href="http://opensource.case.edu/trac_projects/CAS/wiki/CASP">CASP</a>, a C# class produced by <a href="http://wiki.case.edu/User:John.Tantalo">John Tantalo</a> at <a href="http://www.case.edu">Case Western Reserve University</a>.  Coincidentally, John was also responsible for <a href="http://www.planarity.net/">Planarity</a>, a flash game which has only stolen mere days of my life.
</p>
<p>I had a few nits to pick with it, so at the risk of calling his baby ugly:</p>
<ol>
<li>Doesn't handle the latest CAS protocol, <a href="http://www.ja-sig.org/products/cas/overview/cas2_architecture/index.html">CAS2</a></li>
<li>Dumps the authenticated username into Session, which isn't what I wanted</li>
<li>Doesn't use "using" statements when dealing with <a href="http://msdn2.microsoft.com/en-us/library/system.idisposable.aspx">IDisposable</a> objects</li>
<li>Doesn't use XML comments, which .NET tools prefer</li>
<li>Some minor duplication in specifying the login URL and the validation URL.</li>
</ol>
<p>
So, all in all nothing really big.  I ended up going a little nuts with it resolving all my complaints.  It can now speak CAS1 or CAS2, and has a bunch of options that I added in to solve my specific needs.  It seems a little overcomplicated now, but I always get that feeling when I'm thinking in C#.
</p>
<h2>Installation</h2>
<p>Pretty simple:</p>
<ol>
<li>Download the source: <a href="/files/CASP.cs">CASP.cs</a> (BSD license)</li>
<li>Add it to your project</li>
</ol>
<h2>Example usage</h2>
<p>Like Tantalo's CASP, mine is designed to be used from a System.Web.UI.Page, and will redirect the browser about as needed.<br/></p>
<p>Simplest example, uses CAS2 by default</p>
<div class="igBar"><span id="lcsharp-4"><a href="#" onclick="javascript:showPlainTxt('csharp-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-4">
<div class="csharp" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #FF0000;">string</span> username = CASP.<span style="color: #0000FF;">Authenticate</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;https://login.case.edu/cas/&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Page</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #008080; font-style: italic;">//do whatever with username</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Slightly more complex, using CAS1 and always renewing the authentication ticket</p>
<div class="igBar"><span id="lcsharp-5"><a href="#" onclick="javascript:showPlainTxt('csharp-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-5">
<div class="csharp" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #FF0000;">string</span> username = CASP.<span style="color: #0000FF;">Authenticate</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;https://login.case.edu/cas/&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Page</span>, <span style="color: #0600FF;">true</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #008080; font-style: italic;">//do whatever with username</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Most complex example, giving you flexibility to decide what to do about errors, etc</p>
<div class="igBar"><span id="lcsharp-6"><a href="#" onclick="javascript:showPlainTxt('csharp-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-6">
<div class="csharp" style="font-family: monospace;">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; CASP casp = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CASP<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;https://login.case.edu/cas/&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Page</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">//re-login every time</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>casp.<span style="color: #0000FF;">Login</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">try</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">string</span> username = casp.<span style="color: #0000FF;">ServerValidate</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #008080; font-style: italic;">//or casp.Validate() for CAS1</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//do whatever with username</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>CASP.<span style="color: #0000FF;">ValidateException</span> ex<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//try again, something was messed up</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; casp.<span style="color: #0000FF;">Login</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000000;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>This code is <a href="http://jcooney.net/archive/2007/02/01/42999.aspx">certified</a>:<br />
<img src='http://ryepup.unwashedmeme.com/blog/wp-content/uploads/2007/06/worksonmymachine_logo_small.png' alt='works on my machine' /></p>
]]></content:encoded>
			<wfw:commentRss>http://ryepup.unwashedmeme.com/blog/2007/06/19/cas-authentication-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.518 seconds -->

