init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
51
KretaWeb/Security/MvcFeatureAuthorizeAttribute.cs
Normal file
51
KretaWeb/Security/MvcFeatureAuthorizeAttribute.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Kreta.Web.Security
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
|
||||
public class MvcFeatureAuthorizeAttribute : AuthorizeAttribute
|
||||
{
|
||||
private readonly string[] featureNames;
|
||||
|
||||
public MvcFeatureAuthorizeAttribute(params string[] features)
|
||||
{
|
||||
featureNames = features;
|
||||
}
|
||||
|
||||
public override void OnAuthorization(AuthorizationContext filterContext)
|
||||
{
|
||||
if (AuthorizeCore(filterContext.HttpContext))
|
||||
{
|
||||
HttpCachePolicyBase cache = filterContext.HttpContext.Response.Cache;
|
||||
cache.SetProxyMaxAge(new TimeSpan(0L));
|
||||
cache.AddValidationCallback(new HttpCacheValidateHandler(CacheValidateHandler), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
HandleUnauthorizedRequest(filterContext);
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool AuthorizeCore(HttpContextBase httpContext)
|
||||
{
|
||||
return AuthorizeHelper.CheckFeatureAccess(featureNames);
|
||||
}
|
||||
|
||||
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
|
||||
{
|
||||
AuthorizeHelper.MvcRequestAuthorizeFail(filterContext);
|
||||
}
|
||||
|
||||
protected override HttpValidationStatus OnCacheAuthorization(HttpContextBase httpContext)
|
||||
{
|
||||
return !AuthorizeCore(httpContext) ? HttpValidationStatus.IgnoreThisRequest : HttpValidationStatus.Valid;
|
||||
}
|
||||
|
||||
private void CacheValidateHandler(HttpContext context, object data, ref HttpValidationStatus validationStatus)
|
||||
{
|
||||
validationStatus = OnCacheAuthorization(new HttpContextWrapper(context));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue