增加webapi安全认证过滤器

This commit is contained in:
Argo-Lenovo 2016-11-17 13:44:19 +08:00
parent 9a7b407ecb
commit 1b9d44d68a
3 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,29 @@
using Longbow.Security.Principal;
using System.Security.Principal;
using System.Web.Http;
using System.Web.Http.Controllers;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
public class BAAPIAuthorizaAttribute : AuthorizeAttribute
{
/// <summary>
///
/// </summary>
/// <param name="actionContext"></param>
/// <returns></returns>
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);
}
}
}

View File

@ -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();

View File

@ -234,6 +234,7 @@
<Compile Include="..\bldver.cs">
<Link>bldver.cs</Link>
</Compile>
<Compile Include="App_Start\BAAPIAuthorizaAttribute.cs" />
<Compile Include="App_Start\BAAuthorizeAttribute.cs" />
<Compile Include="App_Start\DBPublisher.cs" />
<Compile Include="App_Start\FilterConfig.cs" />