From 1dfdccb8118aeaa3cd844ac8de2a672c93312166 Mon Sep 17 00:00:00 2001 From: mokhan Date: Sat, 21 Feb 2009 21:44:27 +0000 Subject: git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219 --- .../src/app/Marina/Web/AuthenticationHttpModule.cs | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 slips/src/app/Marina/Web/AuthenticationHttpModule.cs (limited to 'slips/src/app/Marina/Web/AuthenticationHttpModule.cs') diff --git a/slips/src/app/Marina/Web/AuthenticationHttpModule.cs b/slips/src/app/Marina/Web/AuthenticationHttpModule.cs new file mode 100644 index 0000000..c90c317 --- /dev/null +++ b/slips/src/app/Marina/Web/AuthenticationHttpModule.cs @@ -0,0 +1,28 @@ +using System.Security.Principal; +using System.Web; +using System.Web.Security; + +namespace Marina.Web { + public class AuthenticationHttpModule : IHttpModule { + public void Init( HttpApplication context ) { + context.AuthenticateRequest += delegate { AuthenticateHttpRequest( ); }; + } + + public void Dispose() {} + + public void AuthenticateHttpRequest() { + HttpCookie cookie = GetCookieFrom( HttpContext.Current ); + if ( null != cookie ) { + BindPrincipalToThreadUsing( FormsAuthentication.Decrypt( cookie.Value ).Name ); + } + } + + private HttpCookie GetCookieFrom( HttpContext context ) { + return context.Request.Cookies[ FormsAuthentication.FormsCookieName ]; + } + + private void BindPrincipalToThreadUsing( string username ) { + HttpContext.Current.User = new GenericPrincipal( new GenericIdentity( username ), new string[] {"Customer"} ); + } + } +} \ No newline at end of file -- cgit v1.2.3