diff --git a/AppHarbor.Web.Security/AppHarbor.Web.Security.csproj b/AppHarbor.Web.Security/AppHarbor.Web.Security.csproj index 840b218..06f208e 100644 --- a/AppHarbor.Web.Security/AppHarbor.Web.Security.csproj +++ b/AppHarbor.Web.Security/AppHarbor.Web.Security.csproj @@ -1,63 +1,64 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {BA59E36D-677F-4F70-94DF-C75C8860F67B} - Library - Properties - AppHarbor.Web.Security - AppHarbor.Web.Security - v4.0 - 512 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {BA59E36D-677F-4F70-94DF-C75C8860F67B} + Library + Properties + AppHarbor.Web.Security + AppHarbor.Web.Security + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + --> \ No newline at end of file diff --git a/AppHarbor.Web.Security/CookieAuthenticationModule.cs b/AppHarbor.Web.Security/CookieAuthenticationModule.cs index 30a0062..2f51dd2 100644 --- a/AppHarbor.Web.Security/CookieAuthenticationModule.cs +++ b/AppHarbor.Web.Security/CookieAuthenticationModule.cs @@ -6,7 +6,8 @@ namespace AppHarbor.Web.Security { public sealed class CookieAuthenticationModule : IHttpModule { - private readonly ICookieAuthenticationConfiguration _configuration; + private readonly ICookieAuthenticationConfiguration _configuration; + private readonly ICookieValidator _validator; public CookieAuthenticationModule() : this(new ConfigFileAuthenticationConfiguration()) @@ -16,8 +17,15 @@ public CookieAuthenticationModule() public CookieAuthenticationModule(ICookieAuthenticationConfiguration configuration) { _configuration = configuration; - } - + } + + public CookieAuthenticationModule(ICookieAuthenticationConfiguration configuration, + ICookieValidator validator) + { + _configuration = configuration; + _validator = validator; + + } private void OnAuthenticateRequest(object sender, EventArgs e) { var context = ((HttpApplication)sender).Context; @@ -29,8 +37,14 @@ private void OnAuthenticateRequest(object sender, EventArgs e) { byte[] data; var cookieData = protector.Validate(cookie.Value, out data); - var authenticationCookie = AuthenticationCookie.Deserialize(data); - if (!authenticationCookie.IsExpired(_configuration.Timeout)) + var authenticationCookie = AuthenticationCookie.Deserialize(data); + + bool isCookieValid = true; + if (_validator != null) + isCookieValid = _validator.IsCookieValid(authenticationCookie); + + if (isCookieValid && !authenticationCookie.IsExpired(_configuration.Timeout)) + { context.User = authenticationCookie.GetPrincipal(); RenewCookieIfExpiring(context, protector, authenticationCookie); diff --git a/AppHarbor.Web.Security/ICookieValidator.cs b/AppHarbor.Web.Security/ICookieValidator.cs new file mode 100644 index 0000000..f57bf4d --- /dev/null +++ b/AppHarbor.Web.Security/ICookieValidator.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace AppHarbor.Web.Security +{ + public interface ICookieValidator + { + bool IsCookieValid(AuthenticationCookie cookie); + } +}