Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Security / RoleManagerModule.cs / 1305376 / RoleManagerModule.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * RoleManagerModule class * * Copyright (c) 1999 Microsoft Corporation */ namespace System.Web.Security { using System.Collections; using System.Security.Principal; using System.Security.Permissions; using System.Text; using System.Threading; using System.Web; using System.Web.Configuration; using System.Web.Caching; using System.Web.Util; ////// public sealed class RoleManagerModule : IHttpModule { private const int MAX_COOKIE_LENGTH = 4096; private RoleManagerEventHandler _eventHandler; ///[To be supplied.] ////// [SecurityPermission(SecurityAction.Demand, Unrestricted=true)] public RoleManagerModule() { } public event RoleManagerEventHandler GetRoles { add { HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level); _eventHandler += value; } remove { _eventHandler -= value; } } ////// Initializes a new instance of the ////// class. /// /// public void Dispose() { } ///[To be supplied.] ////// public void Init(HttpApplication app) { // for IIS 7, skip wireup of these delegates altogether unless the // feature is enabled for this application // this avoids the initial OnEnter transition unless it's needed if (Roles.Enabled) { app.PostAuthenticateRequest += new EventHandler(this.OnEnter); app.EndRequest += new EventHandler(this.OnLeave); } } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// ///[To be supplied.] ////// private void OnEnter(Object source, EventArgs eventArgs) { if (!Roles.Enabled) { if (HttpRuntime.UseIntegratedPipeline) { ((HttpApplication)source).Context.DisableNotifications(RequestNotification.EndRequest, 0); } return; } HttpApplication app = (HttpApplication)source; HttpContext context = app.Context; if (_eventHandler != null) { RoleManagerEventArgs e = new RoleManagerEventArgs(context); _eventHandler(this, e); if (e.RolesPopulated) return; } Debug.Assert(null != context.User, "null != context.User"); if (Roles.CacheRolesInCookie) { if (context.User.Identity.IsAuthenticated && (!Roles.CookieRequireSSL || context.Request.IsSecureConnection)) { // Try to create from cookie try { HttpCookie cookie = context.Request.Cookies[Roles.CookieName]; if (cookie != null) { string cookieValue = cookie.Value; // Ignore cookies that are too long if (cookieValue != null && cookieValue.Length > MAX_COOKIE_LENGTH) { Roles.DeleteCookie(); } else { if (!String.IsNullOrEmpty(Roles.CookiePath) && Roles.CookiePath != "/") { cookie.Path = Roles.CookiePath; } cookie.Domain = Roles.Domain; context.SetPrincipalNoDemand(CreateRolePrincipalWithAssert(context.User.Identity, cookieValue)); } } } catch { } // ---- exceptions } else { if (context.Request.Cookies[Roles.CookieName] != null) Roles.DeleteCookie(); // if we're not using cookie caching, we don't need the EndRequest // event and can suppress it if (HttpRuntime.UseIntegratedPipeline) { context.DisableNotifications(RequestNotification.EndRequest, 0); } } } if (!(context.User is RolePrincipal)) context.SetPrincipalNoDemand(CreateRolePrincipalWithAssert(context.User.Identity)); HttpApplication.SetCurrentPrincipalWithAssert(context.User); } [SecurityPermission(SecurityAction.Assert, ControlPrincipal = true)] private RolePrincipal CreateRolePrincipalWithAssert(IIdentity identity, string encryptedTicket = null) { if (encryptedTicket == null) { return new RolePrincipal(identity); } else { return new RolePrincipal(identity, encryptedTicket); } } private void OnLeave(Object source, EventArgs eventArgs) { HttpApplication app; HttpContext context; app = (HttpApplication)source; context = app.Context; if (!Roles.Enabled || !Roles.CacheRolesInCookie || context.Response.HeadersWritten) return; if (context.User == null || !(context.User is RolePrincipal) || !context.User.Identity.IsAuthenticated) return; if (Roles.CookieRequireSSL && !context.Request.IsSecureConnection) { // if cookie is sent, then clear it if (context.Request.Cookies[Roles.CookieName] != null) Roles.DeleteCookie(); return; } RolePrincipal rp = (RolePrincipal) context.User; if (rp.CachedListChanged && context.Request.Browser.Cookies) { string s = rp.ToEncryptedTicket(); if (string.IsNullOrEmpty(s) || s.Length > MAX_COOKIE_LENGTH) { Roles.DeleteCookie(); } else { HttpCookie cookie = new HttpCookie(Roles.CookieName, s); cookie.HttpOnly = true; cookie.Path = Roles.CookiePath; cookie.Domain = Roles.Domain; if (Roles.CreatePersistentCookie) cookie.Expires = rp.ExpireDate; cookie.Secure = Roles.CookieRequireSSL; context.Response.Cookies.Add(cookie); } } } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //[To be supplied.] ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * RoleManagerModule class * * Copyright (c) 1999 Microsoft Corporation */ namespace System.Web.Security { using System.Collections; using System.Security.Principal; using System.Security.Permissions; using System.Text; using System.Threading; using System.Web; using System.Web.Configuration; using System.Web.Caching; using System.Web.Util; ////// public sealed class RoleManagerModule : IHttpModule { private const int MAX_COOKIE_LENGTH = 4096; private RoleManagerEventHandler _eventHandler; ///[To be supplied.] ////// [SecurityPermission(SecurityAction.Demand, Unrestricted=true)] public RoleManagerModule() { } public event RoleManagerEventHandler GetRoles { add { HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level); _eventHandler += value; } remove { _eventHandler -= value; } } ////// Initializes a new instance of the ////// class. /// /// public void Dispose() { } ///[To be supplied.] ////// public void Init(HttpApplication app) { // for IIS 7, skip wireup of these delegates altogether unless the // feature is enabled for this application // this avoids the initial OnEnter transition unless it's needed if (Roles.Enabled) { app.PostAuthenticateRequest += new EventHandler(this.OnEnter); app.EndRequest += new EventHandler(this.OnLeave); } } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// ///[To be supplied.] ////// private void OnEnter(Object source, EventArgs eventArgs) { if (!Roles.Enabled) { if (HttpRuntime.UseIntegratedPipeline) { ((HttpApplication)source).Context.DisableNotifications(RequestNotification.EndRequest, 0); } return; } HttpApplication app = (HttpApplication)source; HttpContext context = app.Context; if (_eventHandler != null) { RoleManagerEventArgs e = new RoleManagerEventArgs(context); _eventHandler(this, e); if (e.RolesPopulated) return; } Debug.Assert(null != context.User, "null != context.User"); if (Roles.CacheRolesInCookie) { if (context.User.Identity.IsAuthenticated && (!Roles.CookieRequireSSL || context.Request.IsSecureConnection)) { // Try to create from cookie try { HttpCookie cookie = context.Request.Cookies[Roles.CookieName]; if (cookie != null) { string cookieValue = cookie.Value; // Ignore cookies that are too long if (cookieValue != null && cookieValue.Length > MAX_COOKIE_LENGTH) { Roles.DeleteCookie(); } else { if (!String.IsNullOrEmpty(Roles.CookiePath) && Roles.CookiePath != "/") { cookie.Path = Roles.CookiePath; } cookie.Domain = Roles.Domain; context.SetPrincipalNoDemand(CreateRolePrincipalWithAssert(context.User.Identity, cookieValue)); } } } catch { } // ---- exceptions } else { if (context.Request.Cookies[Roles.CookieName] != null) Roles.DeleteCookie(); // if we're not using cookie caching, we don't need the EndRequest // event and can suppress it if (HttpRuntime.UseIntegratedPipeline) { context.DisableNotifications(RequestNotification.EndRequest, 0); } } } if (!(context.User is RolePrincipal)) context.SetPrincipalNoDemand(CreateRolePrincipalWithAssert(context.User.Identity)); HttpApplication.SetCurrentPrincipalWithAssert(context.User); } [SecurityPermission(SecurityAction.Assert, ControlPrincipal = true)] private RolePrincipal CreateRolePrincipalWithAssert(IIdentity identity, string encryptedTicket = null) { if (encryptedTicket == null) { return new RolePrincipal(identity); } else { return new RolePrincipal(identity, encryptedTicket); } } private void OnLeave(Object source, EventArgs eventArgs) { HttpApplication app; HttpContext context; app = (HttpApplication)source; context = app.Context; if (!Roles.Enabled || !Roles.CacheRolesInCookie || context.Response.HeadersWritten) return; if (context.User == null || !(context.User is RolePrincipal) || !context.User.Identity.IsAuthenticated) return; if (Roles.CookieRequireSSL && !context.Request.IsSecureConnection) { // if cookie is sent, then clear it if (context.Request.Cookies[Roles.CookieName] != null) Roles.DeleteCookie(); return; } RolePrincipal rp = (RolePrincipal) context.User; if (rp.CachedListChanged && context.Request.Browser.Cookies) { string s = rp.ToEncryptedTicket(); if (string.IsNullOrEmpty(s) || s.Length > MAX_COOKIE_LENGTH) { Roles.DeleteCookie(); } else { HttpCookie cookie = new HttpCookie(Roles.CookieName, s); cookie.HttpOnly = true; cookie.Path = Roles.CookiePath; cookie.Domain = Roles.Domain; if (Roles.CreatePersistentCookie) cookie.Expires = rp.ExpireDate; cookie.Secure = Roles.CookieRequireSSL; context.Response.Cookies.Add(cookie); } } } //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- UpdateExpressionVisitor.cs
- PointAnimationClockResource.cs
- PauseStoryboard.cs
- ContentIterators.cs
- WhitespaceSignificantCollectionAttribute.cs
- TypeUtil.cs
- PreservationFileReader.cs
- HtmlInputRadioButton.cs
- newinstructionaction.cs
- HtmlUtf8RawTextWriter.cs
- SecurityPermission.cs
- DrawingGroup.cs
- NCryptSafeHandles.cs
- SemaphoreFullException.cs
- SqlDataSourceEnumerator.cs
- IChannel.cs
- PriorityItem.cs
- ThreadStartException.cs
- RemotingServices.cs
- VersionedStreamOwner.cs
- XamlHostingConfiguration.cs
- ExceptionTrace.cs
- XmlSchemaType.cs
- ParserExtension.cs
- WinFormsSecurity.cs
- TaskResultSetter.cs
- MultiSelectRootGridEntry.cs
- DataServicePagingProviderWrapper.cs
- DesignUtil.cs
- FixedSOMPage.cs
- LayoutSettings.cs
- WindowInteropHelper.cs
- TraceListeners.cs
- ProjectedWrapper.cs
- WindowsIdentity.cs
- CachingHintValidation.cs
- ConfigurationPropertyAttribute.cs
- ComplexPropertyEntry.cs
- GridView.cs
- CryptoConfig.cs
- ChangeConflicts.cs
- RepeatButton.cs
- StandardOleMarshalObject.cs
- TraceSection.cs
- SR.cs
- SessionPageStateSection.cs
- TransformConverter.cs
- PathGeometry.cs
- DbConnectionHelper.cs
- IPipelineRuntime.cs
- SynchronousReceiveBehavior.cs
- MessageBox.cs
- ArithmeticException.cs
- BamlLocalizationDictionary.cs
- TextElementEnumerator.cs
- IProducerConsumerCollection.cs
- RNGCryptoServiceProvider.cs
- DesignerOptionService.cs
- AttributeEmitter.cs
- ToolboxItemLoader.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- SqlBuilder.cs
- HyperLinkField.cs
- CultureTableRecord.cs
- TreeViewEvent.cs
- TextServicesContext.cs
- UInt16Storage.cs
- TransformerConfigurationWizardBase.cs
- TextTreeFixupNode.cs
- OraclePermission.cs
- PassportPrincipal.cs
- FlagsAttribute.cs
- TextProviderWrapper.cs
- EntityProviderServices.cs
- SplitterDesigner.cs
- FormatException.cs
- SqlBinder.cs
- StrokeCollection2.cs
- ParserExtension.cs
- BlockCollection.cs
- ConsumerConnectionPointCollection.cs
- IPGlobalProperties.cs
- ArrayWithOffset.cs
- ListViewHitTestInfo.cs
- KeyBinding.cs
- AppDomainProtocolHandler.cs
- MethodCallTranslator.cs
- RelationshipEndCollection.cs
- BmpBitmapEncoder.cs
- Funcletizer.cs
- _HTTPDateParse.cs
- MultiSelector.cs
- AdPostCacheSubstitution.cs
- StylusPointPropertyInfo.cs
- FrameSecurityDescriptor.cs
- RijndaelCryptoServiceProvider.cs
- PopupRootAutomationPeer.cs
- TypeLibraryHelper.cs
- XmlTextReader.cs
- DataSourceProvider.cs