Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

24 lines
803 B
C#

// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Net;
using System.Net.Http;
using System.Security.Principal;
using System.Threading;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
namespace System.Web.Http
{
public class RequireAdminAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(HttpActionContext context)
{
// do authorization based on the principle.
IPrincipal principal = Thread.CurrentPrincipal;
if (principal == null || !principal.IsInRole("Administrators"))
{
context.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
}
}
}
}