Files
Disco/Disco.Services/Authorization/DiscoAuthorizeBaseAttribute.cs
T
Gary Sharp 9784c5d282 Plugin Base WebViewPage #22 & Authorization #24
Plugins have a base WebViewPage to inherit, this offers integration with
various Disco services. Plugins can also add Authorization attributes to
their Web Handlers and Controller Methods.
2013-10-14 20:13:00 +11:00

40 lines
1.1 KiB
C#

using Disco.Services.Users;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace Disco.Services.Authorization
{
public abstract class DiscoAuthorizeBaseAttribute : AuthorizeAttribute
{
protected AuthorizationToken Token
{
get
{
return UserService.CurrentAuthorization;
}
}
public abstract bool IsAuthorized(System.Web.HttpContextBase httpContext);
public abstract string HandleUnauthorizedMessage();
protected sealed override bool AuthorizeCore(System.Web.HttpContextBase httpContext)
{
if (httpContext == null)
throw new ArgumentNullException("httpContext");
return IsAuthorized(httpContext);
}
protected sealed override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
string resultMessage = HandleUnauthorizedMessage();
filterContext.Result = new HttpUnauthorizedResult(resultMessage);
}
}
}