2003-01-04 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sat, 4 Jan 2003 04:39:32 +0000 (04:39 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sat, 4 Jan 2003 04:39:32 +0000 (04:39 -0000)
* System.Web/HttpApplication.cs: added new state to handle default
authentication.

* System.Web.Configuration/HttpModulesConfigurationHandler.cs: add
a default authentication module at the end of the list.

* System.Web.Configuration/ModuleItem.cs: new constructor.
* System.Web.Security/DefaultAuthenticationModule.cs: implemented. It
just create a default unauthenticated user when no one else provided one.
* System.Web.Security/FormsAuthenticationModule.cs: removed debug output.
* System.Web.UI/Control.cs:
(AddedControl): take the children to the same state of the parent.
(InitRecursive): set the page of the children.
* System.Web.UI/Page.cs: removed one line (it's done a few lines above).
* System.Web.UI/UserControl.cs:
(OnInit): always call InitializeAsUserControl
(InitializeAsUserControl): sets the page for the control.

svn path=/trunk/mcs/; revision=10114

12 files changed:
mcs/class/System.Web/System.Web.Configuration/ChangeLog
mcs/class/System.Web/System.Web.Configuration/HttpModulesConfigurationHandler.cs
mcs/class/System.Web/System.Web.Configuration/ModuleItem.cs
mcs/class/System.Web/System.Web.Security/ChangeLog
mcs/class/System.Web/System.Web.Security/DefaultAuthenticationModule.cs
mcs/class/System.Web/System.Web.Security/FormsAuthenticationModule.cs
mcs/class/System.Web/System.Web.UI/ChangeLog
mcs/class/System.Web/System.Web.UI/Control.cs
mcs/class/System.Web/System.Web.UI/Page.cs
mcs/class/System.Web/System.Web.UI/UserControl.cs
mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/HttpApplication.cs

index 034dc2db32aeca0826c9cbcf87221d63b870aba0..0e59da70f8353f4c6daf18d55fcceed3aa3e5833 100644 (file)
@@ -1,3 +1,10 @@
+2003-01-04  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * HttpModulesConfigurationHandler.cs: add a default authentication
+       module at the end of the list.
+
+       * ModuleItem.cs: new constructor.
+
 2002-12-19  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * AuthConfig.cs: LoginUrl defaults to login.aspx.
index 123c074671da342c3015ba6b13903d4546fb8bd9..44776eb3a44bfdf71a3111feb6986cacfadeab9c 100644 (file)
@@ -73,6 +73,7 @@ namespace System.Web.Configuration
                                HandlersUtil.ThrowException ("Unrecognized element", child);
                        }
 
+                       mapper.Add (new ModuleItem ("DefaultAuthentication", typeof (DefaultAuthenticationModule)));
                        return mapper;
                }
        }
index f1c75b362e794685d5207b540f9b6aa2c41bd21b..3db4bce3edab116780d52fec5aa86cbb8bae0434 100644 (file)
@@ -21,6 +21,14 @@ namespace System.Web.Configuration {
                                throw new HttpException(HttpRuntime.FormatResourceString("type_not_module"));
                }
 
+               public ModuleItem(string name, Type type) {
+                       _typeName = type.ToString ();
+                       _name = name;
+                       _type = type;
+                       if (!typeof(IHttpModule).IsAssignableFrom(_type))
+                               throw new HttpException(HttpRuntime.FormatResourceString("type_not_module"));
+               }
+
                public IHttpModule Create() {
                        return (IHttpModule) HttpRuntime.CreateInternalObject(_type);
                }
index cd695d2e20bf23d38e193513d9d73689c22e279f..68177fddc55089fdb3f45b95c3dff3e46a677ee7 100644 (file)
@@ -1,3 +1,10 @@
+2003-01-04  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * DefaultAuthenticationModule.cs: implemented. It just create a default 
+       unauthenticated user when no one else provided one.
+
+       * FormsAuthenticationModule.cs: removed debug output.
+
 2002-12-20  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * FormsAuthenticationModule.cs: remove debug lines.
index 0603262edbfe1e8652ba122b4a10a6762239c81b..d9b56142143c1679b6f7ef1733f86f907f76bccf 100644 (file)
@@ -8,21 +8,35 @@
 //
 
 using System.Web;
+using System.Security.Principal;
 
 namespace System.Web.Security
 {
        public sealed class DefaultAuthenticationModule : IHttpModule
        {
+               static GenericIdentity defaultIdentity = new GenericIdentity ("", "");
+
                public event DefaultAuthenticationEventHandler Authenticate;
 
                public void Dispose ()
                {
                }
 
-               [MonoTODO]
                public void Init (HttpApplication app)
                {
-                       throw new NotImplementedException ();
+                       app.DefaultAuthentication += new EventHandler (OnDefaultAuthentication);
+               }
+
+               void OnDefaultAuthentication (object sender, EventArgs args)
+               {
+                       HttpApplication app = (HttpApplication) sender;
+                       HttpContext context = app.Context;
+
+                       if (context.User == null && Authenticate != null)
+                               Authenticate (this, new DefaultAuthenticationEventArgs (context));
+
+                       if (context.User == null)
+                               context.User = new GenericPrincipal (defaultIdentity, new string [0]);
                }
        }
 }
index 2d924ac3060281b580413385712f0a7a16e3a8d6..21fc124de0db59a6e16ad88a3c3ae95bd70f123d 100644 (file)
@@ -54,13 +54,13 @@ namespace System.Web.Security
                        }
                                
                        HttpCookie cookie = context.Request.Cookies [cookieName];
-                       if (cookie == null || (cookie.Expires != DateTime.MinValue && cookie.Expires < DateTime.Now))
+                       if (cookie == null || (cookie.Expires != DateTime.MinValue && cookie.Expires < DateTime.Now)) {
                                return;
+                       }
 
                        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt (cookie.Value);
                        FormsAuthentication.RenewTicketIfOld (ticket);
                        context.User = new GenericPrincipal (new FormsIdentity (ticket), new string [0]);
-                       Console.WriteLine ("name: " + ticket.Name);
 
                        cookie.Value = FormsAuthentication.Encrypt (ticket);
                        cookie.Path = cookiePath;
@@ -82,7 +82,6 @@ namespace System.Web.Security
                                return;
 
                        AuthConfig config = (AuthConfig) context.GetConfig ("system.web/authentication");
-                       Console.WriteLine ("Redirecting to login page: '{0}'", config.LoginUrl);
                        context.Response.Redirect (config.LoginUrl);
                }
 
index 960fd483bf85b2975acea21b0e959f50125a3be6..2e2c8ff588247172c7ca89e4c401fedd3f90c5bb 100644 (file)
@@ -1,3 +1,15 @@
+2003-01-04  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * Control.cs:
+       (AddedControl): take the children to the same state of the parent.
+       (InitRecursive): set the page of the children.
+
+       * Page.cs: removed one line (it's done a few lines above).
+
+       * UserControl.cs:
+       (OnInit): always call InitializeAsUserControl
+       (InitializeAsUserControl): sets the page for the control.
+
 2003-01-03  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * Control.cs: fixed bug #36037.
index 2c9769ab212f1c00e814c96cd32f4dd3605b9e03..e8f6d78e0c91fd2e9301efd3889cb535cb2a962d 100644 (file)
@@ -117,6 +117,10 @@ namespace System.Web.UI
                private bool creatingControls = false;\r
                private bool bindingContainer = true;\r
                private bool autoEventWireup = true;\r
+\r
+               bool inited = false;\r
+               bool loaded = false;\r
+               bool prerendered = false;\r
                \r
                    private DataBindingCollection dataBindings = null;\r
 \r
@@ -355,9 +359,14 @@ namespace System.Web.UI
                        if (control.AutoID == true && control.ID == null)\r
                                control.ID = ID + "_ctrl_" + defaultNumberID++;\r
 \r
-                       control.InitRecursive (_isNamingContainer ? this : NamingContainer);\r
-                       control.LoadRecursive ();\r
-                       control.PreRenderRecursiveInternal ();\r
+                       if (inited)\r
+                               control.InitRecursive (_isNamingContainer ? this : NamingContainer);\r
+\r
+                       if (loaded)\r
+                               control.LoadRecursive ();\r
+\r
+                       if (prerendered)\r
+                               control.PreRenderRecursiveInternal ();\r
                }\r
 \r
                 protected virtual void AddParsedSubObject(object obj) //DIT\r
@@ -398,15 +407,17 @@ namespace System.Web.UI
                 protected virtual Control FindControl(string id, int pathOffset)\r
                 {\r
                         //TODO: I think there is Naming Container stuff here. Redo.\r
-                        int i;\r
-                       Control ctrl;\r
-                        for (i = pathOffset; i < _controls.Count; i++){\r
-                               ctrl = _controls [i];\r
+                       EnsureChildControls ();\r
+                       if (_controls == null)\r
+                               return null;\r
+\r
+                        for (int i = pathOffset; i < _controls.Count; i++){\r
+                               Control ctrl = _controls [i];\r
                                \r
                                 if (ctrl.ID == id)\r
                                        return ctrl;\r
 \r
-                               if (ctrl.Controls.Count > 0){\r
+                               if (ctrl._controls != null && ctrl._controls.Count > 0){\r
                                        Control other = ctrl.FindControl (id);\r
                                        if (other != null)\r
                                                return other;\r
@@ -638,6 +649,7 @@ namespace System.Web.UI
                 {\r
                         OnLoad(EventArgs.Empty);\r
                         if (_controls != null) foreach (Control c in _controls) c.LoadRecursive();\r
+                       loaded = true;\r
                 }\r
 \r
                 protected void UnloadRecursive(Boolean dispose)\r
@@ -658,13 +670,21 @@ namespace System.Web.UI
                                foreach (Control c in _controls)\r
                                        c.PreRenderRecursiveInternal ();\r
                        }\r
+                       prerendered = true;\r
                 }\r
 \r
                 protected void InitRecursive(Control namingContainer)\r
                 {\r
-                        if (_controls != null) foreach (Control c in _controls) c.InitRecursive(namingContainer);\r
-                        OnInit(EventArgs.Empty);\r
+                        if (_controls != null) {\r
+                               foreach (Control c in _controls) {\r
+                                       c._page = Page;\r
+                                       c.InitRecursive (namingContainer);\r
+                               }\r
+                       }\r
+\r
+                        OnInit (EventArgs.Empty);\r
                        TrackViewState ();\r
+                       inited = true;\r
                 }\r
                 \r
                 internal object SaveViewStateRecursive()\r
index 74a7bffcf80842d452964da324e698c990824c06..a5e2b409dcfd3aa31ed588aad5fc7187ddf65204 100755 (executable)
@@ -451,7 +451,6 @@ public class Page : TemplateControl, IHttpHandler
                WebTrace.WriteLine ("InitRecursive");
                InitRecursive (null);
                renderingForm = false;  
-               _context = context;
                if (IsPostBack) {
                        LoadPageViewState ();
                        ProcessPostData (DeterminePostBackMode (), false);
index d223b0893e3a4cdd179ad86473657d204fb274d9..50ef9362fab7b987e1860b82c74a4abe55d34860 100644 (file)
@@ -131,6 +131,7 @@ namespace System.Web.UI
                        if (initialized)
                                return;
                        initialized = true;
+                       this.Page = page;
                        WireupAutomaticEvents ();
                        FrameworkInitialize ();
                }
@@ -155,8 +156,7 @@ namespace System.Web.UI
 
                protected override void OnInit (EventArgs e)
                {
-                       if (Page != null)
-                               InitializeAsUserControl (Page);
+                       InitializeAsUserControl (Page);
 
                        base.OnInit(e);
                }
index e10b2b886c52df95104e1bb77fa47bd9557fb327..665677c1445e5cc219330b7612155c8766ae7e9a 100644 (file)
@@ -1,3 +1,7 @@
+2003-01-04  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * HttpApplication.cs: added new state to handle default authentication.
+
 2003-01-03  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * HttpContext.cs: removed hack to get the User.
index 57cd3b7da49ffdc2744a04152e756e447598d105..3e0178f3e451e92d78566b2441d953a5d49e7892 100644 (file)
@@ -40,6 +40,7 @@ namespace System.Web
                // ID objects used to indentify the event
                static object AcquireRequestStateId = new Object ();
                static object AuthenticateRequestId = new Object ();
+               static object DefaultAuthenticationId = new Object ();
                static object EndRequestId = new Object ();
                static object DisposedId = new Object ();
                static object BeginRequestId = new Object ();
@@ -127,6 +128,11 @@ namespace System.Web
                        remove { Events.RemoveHandler (PreSendRequestHeadersId, value); }
                }
 
+               internal event EventHandler DefaultAuthentication {
+                       add { Events.AddHandler (DefaultAuthenticationId, value); }
+                       remove { Events.RemoveHandler (DefaultAuthenticationId, value); }
+               }
+
                public void AddOnAcquireRequestStateAsync (BeginEventHandler beg, EndEventHandler end)
                {
                        if (null == _acquireRequestStateAsync)
@@ -506,6 +512,10 @@ namespace System.Web
                                        _app._authenticateRequestAsync.GetAsStates (_app, states);
                                GetAsStates (HttpApplication.AuthenticateRequestId, states);
 
+                               // DefaultAuthentication
+                               EventHandler defaultAuthHandler = (EventHandler) _app.Events [HttpApplication.DefaultAuthenticationId];
+                               states.Add (new EventState (_app, defaultAuthHandler));
+
                                // AuthorizeRequest
                                if (null != _app._authorizeRequestAsync)
                                        _app._authorizeRequestAsync.GetAsStates (_app, states);