4
4
using System . Web ;
5
5
using System . Web . Configuration ;
6
6
using System . Web . Security ;
7
- using DotNetCasClient . Authentication ;
8
7
using DotNetCasClient . Configuration ;
9
8
using DotNetCasClient . Proxy ;
10
9
using DotNetCasClient . State ;
@@ -56,7 +55,6 @@ public sealed class CasAuthentication
56
55
57
56
// Gateway support
58
57
private static bool _gateway ;
59
- private static IGatewayResolver _gatewayResolver ;
60
58
private static string _gatewayStatusCookieName ;
61
59
62
60
// Proxy support
@@ -162,11 +160,11 @@ public static void Initialize()
162
160
163
161
if ( CasClientConfig . ProxyGrantingTicketReceptor )
164
162
{
165
- // throw new NotImplementedException("Proxy support is not implemented at this time.");
166
163
/*
167
164
_proxyGrantingTicketReceptor = CasClientConfig.ProxyGrantingTicketReceptor;
168
165
_proxyCallbackUrl = CasClientConfig.ProxyCallbackUrl;
169
166
_proxyReceptorUrl = CasClientConfig.ProxyReceptorUrl;
167
+ _proxyCallbackHandler = new ProxyCallbackHandler();
170
168
*/
171
169
}
172
170
@@ -254,18 +252,26 @@ public static void Initialize()
254
252
255
253
public static void RedirectToLoginPage ( )
256
254
{
255
+ Initialize ( ) ;
256
+
257
257
HttpContext context = HttpContext . Current ;
258
258
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 ( ) ;
261
263
}
262
264
263
265
public static void RedirectToLoginPage ( bool forceRenew )
264
266
{
267
+ Initialize ( ) ;
268
+
265
269
HttpContext context = HttpContext . Current ;
266
270
HttpResponse response = context . Response ;
271
+ HttpApplication application = context . ApplicationInstance ;
267
272
268
- response . Redirect ( ConstructLoginRedirectUrl ( false , forceRenew ) , true ) ;
273
+ response . Redirect ( ConstructLoginRedirectUrl ( false , forceRenew ) , false ) ;
274
+ application . CompleteRequest ( ) ;
269
275
}
270
276
271
277
public static void Authenticate ( string netId , string password )
@@ -275,8 +281,11 @@ public static void Authenticate(string netId, string password)
275
281
276
282
public static void GatewayAuthenticate ( bool ignoreGatewayStatusCookie )
277
283
{
284
+ Initialize ( ) ;
285
+
278
286
HttpContext context = HttpContext . Current ;
279
287
HttpResponse response = context . Response ;
288
+ HttpApplication application = context . ApplicationInstance ;
280
289
281
290
if ( ! ignoreGatewayStatusCookie )
282
291
{
@@ -287,39 +296,55 @@ public static void GatewayAuthenticate(bool ignoreGatewayStatusCookie)
287
296
}
288
297
289
298
SetGatewayStatusCookie ( GatewayStatus . Attempting ) ;
290
- response . Redirect ( ConstructLoginRedirectUrl ( true , false ) , true ) ;
299
+ response . Redirect ( ConstructLoginRedirectUrl ( true , false ) , false ) ;
300
+ application . CompleteRequest ( ) ;
291
301
}
292
302
293
303
public static void PerformSingleSignout ( )
294
304
{
305
+ Initialize ( ) ;
306
+
295
307
HttpContext context = HttpContext . Current ;
296
308
HttpResponse response = context . Response ;
309
+ HttpApplication application = context . ApplicationInstance ;
297
310
298
311
ClearAuthCookie ( ) ;
299
- response . Redirect ( ConstructSingleSignOutRedirectUrl ( ) , true ) ;
312
+ response . Redirect ( ConstructSingleSignOutRedirectUrl ( ) , false ) ;
313
+ application . CompleteRequest ( ) ;
300
314
}
301
315
302
316
public static void RedirectToCookiesRequiredPage ( )
303
317
{
318
+ Initialize ( ) ;
319
+
304
320
HttpContext context = HttpContext . Current ;
305
321
HttpResponse response = context . Response ;
322
+ HttpApplication application = context . ApplicationInstance ;
306
323
307
- response . Redirect ( ResolveUrl ( CookiesRequiredUrl ) , true ) ;
324
+ response . Redirect ( ResolveUrl ( CookiesRequiredUrl ) , false ) ;
325
+ application . CompleteRequest ( ) ;
308
326
}
309
327
310
328
public static void RedirectToUnauthorizedPage ( )
311
329
{
330
+ Initialize ( ) ;
331
+
312
332
HttpContext context = HttpContext . Current ;
313
333
HttpResponse response = context . Response ;
334
+ HttpApplication application = context . ApplicationInstance ;
314
335
315
- response . Redirect ( ResolveUrl ( NotAuthorizedUrl ) , true ) ;
336
+ response . Redirect ( ResolveUrl ( NotAuthorizedUrl ) , false ) ;
337
+ application . CompleteRequest ( ) ;
316
338
}
317
339
318
340
internal static void RedirectFromLoginCallback ( )
319
341
{
342
+ Initialize ( ) ;
343
+
320
344
HttpContext context = HttpContext . Current ;
321
345
HttpRequest request = context . Request ;
322
346
HttpResponse response = context . Response ;
347
+ HttpApplication application = context . ApplicationInstance ;
323
348
324
349
if ( GetRequestHasGatewayParameter ( ) )
325
350
{
@@ -328,27 +353,36 @@ internal static void RedirectFromLoginCallback()
328
353
SetGatewayStatusCookie ( GatewayStatus . Success ) ;
329
354
}
330
355
331
- response . Redirect ( RemoveCasArtifactsFromUrl ( request . Url . AbsoluteUri ) , true ) ;
356
+ response . Redirect ( RemoveCasArtifactsFromUrl ( request . Url . AbsoluteUri ) , false ) ;
357
+ application . CompleteRequest ( ) ;
332
358
}
333
359
334
360
internal static void RedirectFromFailedGatewayCallback ( )
335
361
{
362
+ Initialize ( ) ;
363
+
336
364
HttpContext context = HttpContext . Current ;
337
365
HttpRequest request = context . Request ;
338
366
HttpResponse response = context . Response ;
367
+ HttpApplication application = context . ApplicationInstance ;
339
368
340
369
SetGatewayStatusCookie ( GatewayStatus . Failed ) ;
341
- response . Redirect ( RemoveGatewayStatusArtifactFromUrl ( request . Url . AbsoluteUri ) , true ) ;
370
+ response . Redirect ( RemoveGatewayStatusArtifactFromUrl ( request . Url . AbsoluteUri ) , false ) ;
371
+ application . CompleteRequest ( ) ;
342
372
}
343
373
344
374
internal static string RemoveCasArtifactsFromUrl ( string url )
345
375
{
376
+ Initialize ( ) ;
377
+
346
378
string urlSansTicket = RemoveQueryStringVariableFromUrl ( url , TicketValidator . ArtifactParameterName ) ;
347
379
return RemoveQueryStringVariableFromUrl ( urlSansTicket , GatewayParameterName ) ;
348
380
}
349
381
350
382
internal static string RemoveGatewayStatusArtifactFromUrl ( string url )
351
383
{
384
+ Initialize ( ) ;
385
+
352
386
return RemoveQueryStringVariableFromUrl ( url , GatewayParameterName ) ;
353
387
}
354
388
@@ -1236,19 +1270,6 @@ public static bool Gateway
1236
1270
}
1237
1271
}
1238
1272
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
-
1252
1273
/// <summary>
1253
1274
/// The name of the cookie used to store the Gateway status (NotAttempted,
1254
1275
/// Success, Failed). This cookie is used to prevent the client from
0 commit comments