mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 01:41:17 -10:00
* 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
92 lines
2.4 KiB
C#
92 lines
2.4 KiB
C#
//
|
|
// System.Web.Security.FormsAuthenticationModule
|
|
//
|
|
// Authors:
|
|
// Gonzalo Paniagua Javier ([email protected])
|
|
//
|
|
// (C) 2002 Ximian, Inc (http://www.ximian.com)
|
|
//
|
|
|
|
using System;
|
|
using System.Security.Principal;
|
|
using System.Web;
|
|
using System.Web.Configuration;
|
|
|
|
namespace System.Web.Security
|
|
{
|
|
public sealed class FormsAuthenticationModule : IHttpModule
|
|
{
|
|
bool noForms;
|
|
|
|
public void Dispose ()
|
|
{
|
|
}
|
|
|
|
public void Init (HttpApplication app)
|
|
{
|
|
app.AuthenticateRequest += new EventHandler (OnAuthenticateRequest);
|
|
app.EndRequest += new EventHandler (OnEndRequest);
|
|
}
|
|
|
|
void OnAuthenticateRequest (object sender, EventArgs args)
|
|
{
|
|
HttpApplication app = (HttpApplication) sender;
|
|
HttpContext context = app.Context;
|
|
AuthConfig config = (AuthConfig) context.GetConfig ("system.web/authentication");
|
|
if (config.Mode != AuthenticationMode.Forms) {
|
|
noForms = true;
|
|
return;
|
|
}
|
|
|
|
string cookieName = config.CookieName;
|
|
string cookiePath = config.CookiePath;
|
|
string loginPage = config.LoginUrl;
|
|
|
|
FormsAuthenticationEventArgs formArgs = new FormsAuthenticationEventArgs (context);
|
|
if (Authenticate != null)
|
|
Authenticate (this, formArgs);
|
|
|
|
bool contextUserNull = (context.User == null);
|
|
if (formArgs.User != null || !contextUserNull) {
|
|
if (contextUserNull)
|
|
context.User = formArgs.User;
|
|
return;
|
|
}
|
|
|
|
HttpCookie cookie = context.Request.Cookies [cookieName];
|
|
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]);
|
|
|
|
cookie.Value = FormsAuthentication.Encrypt (ticket);
|
|
cookie.Path = cookiePath;
|
|
if (ticket.IsPersistent)
|
|
cookie.Expires = ticket.Expiration;
|
|
|
|
context.Response.Cookies.Add (cookie);
|
|
context.SkipAuthorization = (context.Request.Path == loginPage);
|
|
}
|
|
|
|
void OnEndRequest (object sender, EventArgs args)
|
|
{
|
|
if (noForms)
|
|
return;
|
|
|
|
HttpApplication app = (HttpApplication) sender;
|
|
HttpContext context = app.Context;
|
|
if (context.Response.StatusCode != 401)
|
|
return;
|
|
|
|
AuthConfig config = (AuthConfig) context.GetConfig ("system.web/authentication");
|
|
context.Response.Redirect (config.LoginUrl);
|
|
}
|
|
|
|
public event FormsAuthenticationEventHandler Authenticate;
|
|
}
|
|
}
|
|
|