增加webapi安全认证过滤器
This commit is contained in:
parent
9a7b407ecb
commit
1b9d44d68a
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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" />
|
||||
|
|
Loading…
Reference in New Issue