a575963da9
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
24 lines
803 B
C#
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);
|
|
}
|
|
}
|
|
}
|
|
} |