diff --git a/Bootstrap.Admin/App_Start/BAAPIAuthorizaAttribute.cs b/Bootstrap.Admin/App_Start/BAAPIAuthorizaAttribute.cs new file mode 100644 index 00000000..58e4e658 --- /dev/null +++ b/Bootstrap.Admin/App_Start/BAAPIAuthorizaAttribute.cs @@ -0,0 +1,29 @@ +using Longbow.Security.Principal; +using System.Security.Principal; +using System.Web.Http; +using System.Web.Http.Controllers; + + +namespace Bootstrap.Admin +{ + /// + /// + /// + public class BAAPIAuthorizaAttribute : AuthorizeAttribute + { + /// + /// + /// + /// + /// + protected override bool IsAuthorized(HttpActionContext actionContext) + { + IPrincipal principal = actionContext.ControllerContext.RequestContext.Principal; + if (principal.Identity.IsAuthenticated) + { + if (LgbPrincipal.IsAdmin(principal.Identity.Name)) return true; + } + return base.IsAuthorized(actionContext); + } + } +} \ No newline at end of file diff --git a/Bootstrap.Admin/App_Start/WebApiConfig.cs b/Bootstrap.Admin/App_Start/WebApiConfig.cs index eb7b6b37..069ac497 100644 --- a/Bootstrap.Admin/App_Start/WebApiConfig.cs +++ b/Bootstrap.Admin/App_Start/WebApiConfig.cs @@ -7,7 +7,7 @@ namespace Bootstrap.Admin public static void Register(HttpConfiguration config) { // Web API configuration and services - + config.Filters.Add(new BAAPIAuthorizaAttribute()); // Web API routes config.MapHttpAttributeRoutes(); diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 85e7ad8b..58c9a689 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -234,6 +234,7 @@ bldver.cs +