Skip to content

Commit 96e2331

Browse files
committed
NETC-11
- Fixed redirect-related bug. The endRequest parameter in Response.Redirect(url, endRequest) aborts the executing thread when set to true, preventing cookies from being stored on the client and raising/handling a ThreadAbortException. Set parameter to false and followed with HttpContext.Current.ApplicationInstance.CompleteRequest() to avoid the undesired behavior. - Removed unused GatewayResolver field/property
1 parent c852af3 commit 96e2331

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

DotNetCasClient/CasAuthentication.cs

+46-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Web;
55
using System.Web.Configuration;
66
using System.Web.Security;
7-
using DotNetCasClient.Authentication;
87
using DotNetCasClient.Configuration;
98
using DotNetCasClient.Proxy;
109
using DotNetCasClient.State;
@@ -56,7 +55,6 @@ public sealed class CasAuthentication
5655

5756
// Gateway support
5857
private static bool _gateway;
59-
private static IGatewayResolver _gatewayResolver;
6058
private static string _gatewayStatusCookieName;
6159

6260
// Proxy support
@@ -162,11 +160,11 @@ public static void Initialize()
162160

163161
if (CasClientConfig.ProxyGrantingTicketReceptor)
164162
{
165-
// throw new NotImplementedException("Proxy support is not implemented at this time.");
166163
/*
167164
_proxyGrantingTicketReceptor = CasClientConfig.ProxyGrantingTicketReceptor;
168165
_proxyCallbackUrl = CasClientConfig.ProxyCallbackUrl;
169166
_proxyReceptorUrl = CasClientConfig.ProxyReceptorUrl;
167+
_proxyCallbackHandler = new ProxyCallbackHandler();
170168
*/
171169
}
172170

@@ -254,18 +252,26 @@ public static void Initialize()
254252

255253
public static void RedirectToLoginPage()
256254
{
255+
Initialize();
256+
257257
HttpContext context = HttpContext.Current;
258258
HttpResponse response = context.Response;
259-
260-
response.Redirect(ConstructLoginRedirectUrl(false, Renew), true);
259+
HttpApplication application = context.ApplicationInstance;
260+
261+
response.Redirect(ConstructLoginRedirectUrl(false, Renew), false);
262+
application.CompleteRequest();
261263
}
262264

263265
public static void RedirectToLoginPage(bool forceRenew)
264266
{
267+
Initialize();
268+
265269
HttpContext context = HttpContext.Current;
266270
HttpResponse response = context.Response;
271+
HttpApplication application = context.ApplicationInstance;
267272

268-
response.Redirect(ConstructLoginRedirectUrl(false, forceRenew), true);
273+
response.Redirect(ConstructLoginRedirectUrl(false, forceRenew), false);
274+
application.CompleteRequest();
269275
}
270276

271277
public static void Authenticate(string netId, string password)
@@ -275,8 +281,11 @@ public static void Authenticate(string netId, string password)
275281

276282
public static void GatewayAuthenticate(bool ignoreGatewayStatusCookie)
277283
{
284+
Initialize();
285+
278286
HttpContext context = HttpContext.Current;
279287
HttpResponse response = context.Response;
288+
HttpApplication application = context.ApplicationInstance;
280289

281290
if (!ignoreGatewayStatusCookie)
282291
{
@@ -287,39 +296,55 @@ public static void GatewayAuthenticate(bool ignoreGatewayStatusCookie)
287296
}
288297

289298
SetGatewayStatusCookie(GatewayStatus.Attempting);
290-
response.Redirect(ConstructLoginRedirectUrl(true, false), true);
299+
response.Redirect(ConstructLoginRedirectUrl(true, false), false);
300+
application.CompleteRequest();
291301
}
292302

293303
public static void PerformSingleSignout()
294304
{
305+
Initialize();
306+
295307
HttpContext context = HttpContext.Current;
296308
HttpResponse response = context.Response;
309+
HttpApplication application = context.ApplicationInstance;
297310

298311
ClearAuthCookie();
299-
response.Redirect(ConstructSingleSignOutRedirectUrl(), true);
312+
response.Redirect(ConstructSingleSignOutRedirectUrl(), false);
313+
application.CompleteRequest();
300314
}
301315

302316
public static void RedirectToCookiesRequiredPage()
303317
{
318+
Initialize();
319+
304320
HttpContext context = HttpContext.Current;
305321
HttpResponse response = context.Response;
322+
HttpApplication application = context.ApplicationInstance;
306323

307-
response.Redirect(ResolveUrl(CookiesRequiredUrl), true);
324+
response.Redirect(ResolveUrl(CookiesRequiredUrl), false);
325+
application.CompleteRequest();
308326
}
309327

310328
public static void RedirectToUnauthorizedPage()
311329
{
330+
Initialize();
331+
312332
HttpContext context = HttpContext.Current;
313333
HttpResponse response = context.Response;
334+
HttpApplication application = context.ApplicationInstance;
314335

315-
response.Redirect(ResolveUrl(NotAuthorizedUrl), true);
336+
response.Redirect(ResolveUrl(NotAuthorizedUrl), false);
337+
application.CompleteRequest();
316338
}
317339

318340
internal static void RedirectFromLoginCallback()
319341
{
342+
Initialize();
343+
320344
HttpContext context = HttpContext.Current;
321345
HttpRequest request = context.Request;
322346
HttpResponse response = context.Response;
347+
HttpApplication application = context.ApplicationInstance;
323348

324349
if (GetRequestHasGatewayParameter())
325350
{
@@ -328,27 +353,36 @@ internal static void RedirectFromLoginCallback()
328353
SetGatewayStatusCookie(GatewayStatus.Success);
329354
}
330355

331-
response.Redirect(RemoveCasArtifactsFromUrl(request.Url.AbsoluteUri), true);
356+
response.Redirect(RemoveCasArtifactsFromUrl(request.Url.AbsoluteUri), false);
357+
application.CompleteRequest();
332358
}
333359

334360
internal static void RedirectFromFailedGatewayCallback()
335361
{
362+
Initialize();
363+
336364
HttpContext context = HttpContext.Current;
337365
HttpRequest request = context.Request;
338366
HttpResponse response = context.Response;
367+
HttpApplication application = context.ApplicationInstance;
339368

340369
SetGatewayStatusCookie(GatewayStatus.Failed);
341-
response.Redirect(RemoveGatewayStatusArtifactFromUrl(request.Url.AbsoluteUri), true);
370+
response.Redirect(RemoveGatewayStatusArtifactFromUrl(request.Url.AbsoluteUri), false);
371+
application.CompleteRequest();
342372
}
343373

344374
internal static string RemoveCasArtifactsFromUrl(string url)
345375
{
376+
Initialize();
377+
346378
string urlSansTicket = RemoveQueryStringVariableFromUrl(url, TicketValidator.ArtifactParameterName);
347379
return RemoveQueryStringVariableFromUrl(urlSansTicket, GatewayParameterName);
348380
}
349381

350382
internal static string RemoveGatewayStatusArtifactFromUrl(string url)
351383
{
384+
Initialize();
385+
352386
return RemoveQueryStringVariableFromUrl(url, GatewayParameterName);
353387
}
354388

@@ -1236,19 +1270,6 @@ public static bool Gateway
12361270
}
12371271
}
12381272

1239-
/// <summary>
1240-
/// Gateway resolver handles CAS gateway requests & responses.
1241-
/// http://www.ja-sig.org/wiki/display/CAS/gateway
1242-
/// </summary>
1243-
internal static IGatewayResolver GatewayResolver
1244-
{
1245-
get
1246-
{
1247-
Initialize();
1248-
return _gatewayResolver;
1249-
}
1250-
}
1251-
12521273
/// <summary>
12531274
/// The name of the cookie used to store the Gateway status (NotAttempted,
12541275
/// Success, Failed). This cookie is used to prevent the client from

0 commit comments

Comments
 (0)