using C4IT.FASD.Licensing;
using System.Net;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;

namespace F4SDwebService.ActionFilters
{
    public class CheckLicenceFilter : AuthorizationFilterAttribute
    {
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (cF4SDLicense.Instance?.IsValid != true)
                actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.Forbidden, "No valid licence was found.");

            base.OnAuthorization(actionContext);
        }
    }
}