CAS-SSO in the .NET Web-Applications
Total Page:16
File Type:pdf, Size:1020Kb
![CAS-SSO in the .NET Web-Applications](http://data.docslib.org/img/8a4e803bc9429b77b5afdbc7256f672f-1.webp)
Administration General Direction Information Technology Direction
CAS .NET
CAS-SSO IN THE .NET WEB-APPLICATIONS
Type of document: working document waiting for validation approved for diffusion
Référence : 019f08e37f72d22fecf8cc668802e368.docx
Objectives of the document :
This document describes the best practices of the single sign-on « CAS » tool integration in a .NET application development for the Council of Europe.
This document is the Council of Europe’s property. It can’t be reproduced or communicated without the author’s agreement.
019f08e37f72d22fecf8cc668802e368.docx [CAS .NET] Dernière modification 15 novembre 2012 à 09:50:00 Auteur
Version : 1.0 Page 1 / 6 CAS .NET CAS-SSO in the .NET web-applications
Sommaire
019f08e37f72d22fecf8cc668802e368.docx [CAS .NET] Last modification 15 novembre 2012 à 09:50:00 Author
Version : 1.0 Page 2 / 6 CAS .NET CAS-SSO in the .NET web-applications
1. INTRODUCTION
1.1 OBJECTIVES
This document describes the best practices of the single sign-on « CAS » tool integration in a .NET application development for the Council of Europe.
2. INTÉGRATION - C# - ASP.NET
2.1 REFERENCE
The CasModule reference must be added to the Web Project. This library is available in the common_dlls directory linked to the solution.
2.2 WEB.CONFIG
Add the following lines in the web.config
And
019f08e37f72d22fecf8cc668802e368.docx [CAS .NET] Last modification 15 novembre 2012 à 09:50:00 Author
Version : 1.0 Page 3 / 6 CAS .NET CAS-SSO in the .NET web-applications
. NB : The key “Folders_Without_CAS_Authentication” est is very important because she makes CAS know the folders that need an authentication (e.g. « webforms/tools » for the Sanity Tests).
2.3 CODE
Code to include in the masterpage
- e.g. in the Page_Load
//username without CAS string user = Page.User.Identity.Name;
//if CAS is activated, username is in HTTTPContext string casAuthent = appSettings.Get("CasAuthActivate"); if (casAuthent != null && casAuthent.ToLower().Equals("true")) { user = System.Web.HttpContext.Current.User.Identity.Name; CheckCASSession(); }
- PreviousCheckTime function
///
- CheckCASSEssion function
///
019f08e37f72d22fecf8cc668802e368.docx [CAS .NET] Last modification 15 novembre 2012 à 09:50:00 Author
Version : 1.0 Page 4 / 6 CAS .NET CAS-SSO in the .NET web-applications
/// (this does delete the cookie if it’s still here by error) /// 2) check the presence of the CAS cookie /// - No => Displays the requested page /// private void CheckCASSession() { NameValueCollection appSettings = ConfigurationManager.AppSettings;
if (Request.HttpMethod == "POST" || appSettings.Get("CASCheckIntervalInMinutes") == "-1") { //we’re in POST mode where the periodical check of CAS is disabled, so we don’t go further //In POST mode we don’t check, in order no to lose some data return; }
int nCASCheckInterval; if (!Int32.TryParse(appSettings.Get("CASCheckIntervalInMinutes"), out nCASCheckInterval)) { nCASCheckInterval = 5; }
if (PreviousCheckTime.AddMinutes(nCASCheckInterval) < DateTime.Now) { //last check is more than 5 minutes old
//update PreviousCheckTime PreviousCheckTime = DateTime.Now;
/// 1) Request on the login page to extend the session /// (this does delete the cookie if it’s still here by error)
string sUrlCAS = appSettings.Get("loginUrl") + "?service=" + this.Request.Url; Response.Redirect(sUrlCAS, false);
/// 2) check the presence of the CAS cookie foreach (string cookieMonster in Request.Cookies) { if (cookieMonster.ToLower().Contains("castgc")) { return; } }
// no cookie --> we redirect to the CAS Login Response.Redirect( sUrlCAS, true );
019f08e37f72d22fecf8cc668802e368.docx [CAS .NET] Last modification 15 novembre 2012 à 09:50:00 Author
Version : 1.0 Page 5 / 6 CAS .NET CAS-SSO in the .NET web-applications
Response.End(); } }
End of the document
019f08e37f72d22fecf8cc668802e368.docx [CAS .NET] Last modification 15 novembre 2012 à 09:50:00 Author
Version : 1.0 Page 6 / 6