Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https://issues.jasig.org/browse/NETC-55 #8

Open
wants to merge 1 commit into
base: develop
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
10 changes: 5 additions & 5 deletions DotNetCasClient/CasAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ public static void Initialize()
configLogger.Info("requireCasForMissingContentTypes = " + requireCasForMissingContentTypes);

requireCasForContentTypes = CasClientConfig.RequireCasForContentTypes;
configLogger.Info("requireCasForContentTypes = " + requireCasForContentTypes);
configLogger.Info("requireCasForContentTypes = " + string.Join(",", requireCasForContentTypes));

bypassCasForHandlers = CasClientConfig.BypassCasForHandlers;
configLogger.Info("bypassCasForHandlers = " + bypassCasForHandlers);
bypassCasForHandlers = CasClientConfig.BypassCasForHandlers;
configLogger.Info("bypassCasForHandlers = " + string.Join(",", bypassCasForHandlers));

if (String.Compare(ticketValidatorName, CasClientConfiguration.CAS10_TICKET_VALIDATOR_NAME, true) == 0)
{
Expand Down Expand Up @@ -770,8 +770,8 @@ internal static void ProcessTicketValidation()
CasAuthenticationTicket casTicket;
ICasPrincipal principal;

string ticket = request[TicketValidator.ArtifactParameterName];
string ticket = request[TicketValidator.ArtifactParameterName];

try
{
// Attempt to authenticate the ticket and resolve to an ICasPrincipal
Expand Down
73 changes: 38 additions & 35 deletions DotNetCasClient/CasAuthenticationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

using System;
using System;
using System.Web;
using DotNetCasClient.Logging;
using DotNetCasClient.Utils;
Expand All @@ -33,26 +33,26 @@ namespace DotNetCasClient
/// <author>Catherine D. Winfrey</author>
public sealed class CasAuthenticationModule : IHttpModule
{
private static readonly Logger logger = new Logger(Category.HttpModule);
private static readonly Logger logger = new Logger(Category.HttpModule);

/// <summary>
/// Performs initializations / startup functionality when an instance of this HttpModule
/// is being created.
/// </summary>
/// <param name="context">the current HttpApplication</param>
public void Init(HttpApplication context)
{
// Register our event handlers. These are fired on every HttpRequest.
public void Init(HttpApplication context)
{
// Register our event handlers. These are fired on every HttpRequest.
context.BeginRequest += OnBeginRequest;
context.AuthenticateRequest += OnAuthenticateRequest;
context.EndRequest += OnEndRequest;
context.EndRequest += OnEndRequest;
}

/// <summary>
/// Performs cleanup when an instance of this HttpModule is being destroyed.
/// </summary>
public void Dispose()
{
{
}

/// <summary>
Expand All @@ -68,15 +68,21 @@ public void Dispose()
/// </summary>
/// <param name="sender">The HttpApplication that sent the request</param>
/// <param name="e">Not used</param>
private static void OnBeginRequest(object sender, EventArgs e)
{
private static void OnBeginRequest(object sender, EventArgs e)
{
// Validate the ticket coming back from the CAS server
if (!RequestEvaluator.GetRequestIsAppropriateForCasAuthentication())
{
logger.Debug("BeginRequest bypassed for " + HttpContext.Current.Request.RawUrl);
return;
}
CasAuthentication.Initialize();

HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;
HttpRequest request = context.Request;

logger.Debug("Starting BeginRequest for " + request.RawUrl);

logger.Debug("Starting BeginRequest for " + request.RawUrl);

// Cleanup expired ServiceTickets in the ServiceTicketManager
if (CasAuthentication.ServiceTicketManager != null)
{
Expand All @@ -103,8 +109,8 @@ private static void OnBeginRequest(object sender, EventArgs e)
logger.Info("Processing Proxy Callback request");
CasAuthentication.ProcessProxyCallbackRequest();
return;
}

}
logger.Debug("Ending BeginRequest for " + request.RawUrl);
}

Expand All @@ -126,17 +132,16 @@ private static void OnBeginRequest(object sender, EventArgs e)
/// <param name="sender">The HttpApplication that sent the request</param>
/// <param name="e">Not used</param>
private static void OnAuthenticateRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;

// Validate the ticket coming back from the CAS server
{
if (!RequestEvaluator.GetRequestIsAppropriateForCasAuthentication())
{
logger.Debug("AuthenticateRequest bypassed for " + request.RawUrl);
{
logger.Debug("AuthenticateRequest bypassed for " + HttpContext.Current.Request.RawUrl);
return;
}

}

HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;

// Validate the ticket coming back from the CAS server
if (RequestEvaluator.GetRequestHasCasTicket())
{
Expand All @@ -145,7 +150,7 @@ private static void OnAuthenticateRequest(object sender, EventArgs e)
}

logger.Debug("Starting AuthenticateRequest for " + request.RawUrl);
CasAuthentication.ProcessRequestAuthentication();
CasAuthentication.ProcessRequestAuthentication();
logger.Debug("Ending AuthenticateRequest for " + request.RawUrl);
}

Expand Down Expand Up @@ -177,13 +182,17 @@ private static void OnAuthenticateRequest(object sender, EventArgs e)
/// <param name="sender">The HttpApplication that sent the request</param>
/// <param name="e">Not used</param>
private static void OnEndRequest(object sender, EventArgs e)
{
{
if (!RequestEvaluator.GetRequestIsAppropriateForCasAuthentication())
{
logger.Debug("EndRequest bypassed for " + HttpContext.Current.Request.RawUrl);
return;
}

HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;

if (RequestEvaluator.GetRequestIsAppropriateForCasAuthentication())
{
logger.Debug("Starting EndRequest for " + request.RawUrl);
logger.Debug("Starting EndRequest for " + request.RawUrl);

if (RequestEvaluator.GetRequestRequiresGateway())
{
Expand Down Expand Up @@ -219,14 +228,8 @@ private static void OnEndRequest(object sender, EventArgs e)
{
logger.Info(" Redirecting to CAS Login Page");
CasAuthentication.RedirectToLoginPage();
}

}
logger.Debug("Ending EndRequest for " + request.RawUrl);
}
else
{
logger.Debug("No EndRequest processing for " + request.RawUrl);
}
}
}
}
23 changes: 18 additions & 5 deletions DotNetCasClient/Configuration/CasClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,16 @@ public bool RequireCasForMissingContentTypes
/// <summary>
/// Content-types for which CAS authentication will be required
/// </summary>
[ConfigurationProperty(REQUIRE_CAS_FOR_CONTENT_TYPES_PARAMETER_NAME, IsRequired = false, DefaultValue = new[] { "text/plain", "text/html" })]
public string[] RequireCasForContentTypes {
[ConfigurationProperty(REQUIRE_CAS_FOR_CONTENT_TYPES_PARAMETER_NAME, IsRequired = false,DefaultValue = "text/plain,text/html")]
private string _RequireCasForContentTypes
{
get { return this[REQUIRE_CAS_FOR_CONTENT_TYPES_PARAMETER_NAME] as string; }
}

public string[] RequireCasForContentTypes {
get
{
string[] types = ((this[REQUIRE_CAS_FOR_CONTENT_TYPES_PARAMETER_NAME] as string) ?? "text/plain,text/html").Split(',');
string[] types = _RequireCasForContentTypes.Split(',');
for (int i = 0; i < types.Length; i++)
{
string type = types[i];
Expand All @@ -274,12 +279,20 @@ public string[] RequireCasForContentTypes {
/// <summary>
/// Handlers for which CAS authentication will be bypassed.
/// </summary>
[ConfigurationProperty(BYPASS_CAS_FOR_HANDLERS_PARAMETER_NAME, IsRequired = false, DefaultValue = new[] { "trace.axd", "webresource.axd" })]
[ConfigurationProperty(BYPASS_CAS_FOR_HANDLERS_PARAMETER_NAME, IsRequired = false, DefaultValue = "trace.axd,webresource.axd")]
private string _BypassCasForHandlers
{
get { return this[BYPASS_CAS_FOR_HANDLERS_PARAMETER_NAME] as string; }
}

/// <summary>
/// Handlers for which CAS authentication will be bypassed.
/// </summary>
public string[] BypassCasForHandlers
{
get
{
string[] types = ((this[REQUIRE_CAS_FOR_CONTENT_TYPES_PARAMETER_NAME] as string) ?? "trace.axd,webresource.axd").Split(',');
string[] types = _BypassCasForHandlers.Split(',');
for (int i = 0; i < types.Length; i++)
{
string type = types[i];
Expand Down
2 changes: 0 additions & 2 deletions DotNetCasClient/Utils/RequestEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,6 @@ private static bool GetRequestIsCookiesRequiredUrl()
/// <returns>True if the request is appropriate for CAS authentication, otherwise False</returns>
internal static bool GetRequestIsAppropriateForCasAuthentication()
{
CasAuthentication.Initialize();

HttpContext context = HttpContext.Current;
HttpRequest request = context.Request;
HttpResponse response = context.Response;
Expand Down