2003-01-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Security / DefaultAuthenticationModule.cs
1 //
2 // System.Web.Security.DefaultAuthenticationModule
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2002 Ximian, Inc (http://www.ximian.com)
8 //
9
10 using System.Web;
11 using System.Security.Principal;
12
13 namespace System.Web.Security
14 {
15         public sealed class DefaultAuthenticationModule : IHttpModule
16         {
17                 static GenericIdentity defaultIdentity = new GenericIdentity ("", "");
18
19                 public event DefaultAuthenticationEventHandler Authenticate;
20
21                 public void Dispose ()
22                 {
23                 }
24
25                 public void Init (HttpApplication app)
26                 {
27                         app.DefaultAuthentication += new EventHandler (OnDefaultAuthentication);
28                 }
29
30                 void OnDefaultAuthentication (object sender, EventArgs args)
31                 {
32                         HttpApplication app = (HttpApplication) sender;
33                         HttpContext context = app.Context;
34
35                         if (context.User == null && Authenticate != null)
36                                 Authenticate (this, new DefaultAuthenticationEventArgs (context));
37
38                         if (context.User == null)
39                                 context.User = new GenericPrincipal (defaultIdentity, new string [0]);
40                 }
41         }
42 }
43