summaryrefslogtreecommitdiff
path: root/slips/src/app/Marina/Web/AuthenticationHttpModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'slips/src/app/Marina/Web/AuthenticationHttpModule.cs')
-rw-r--r--slips/src/app/Marina/Web/AuthenticationHttpModule.cs28
1 files changed, 28 insertions, 0 deletions
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