diff --git a/Bootstrap.Admin/Startup.cs b/Bootstrap.Admin/Startup.cs index 18957079..77a18409 100644 --- a/Bootstrap.Admin/Startup.cs +++ b/Bootstrap.Admin/Startup.cs @@ -62,7 +62,7 @@ namespace Bootstrap.Admin services.AddResponseCompression(); services.AddBootstrapAdminAuthentication(); services.AddSwagger(); - services.AddButtonAuthorization(MenuHelper.AuthorizateButtons); + services.AddButtonAuthorization(); services.AddMvc(options => { options.Filters.Add(); diff --git a/Bootstrap.DataAccess/Helper/MenuHelper.cs b/Bootstrap.DataAccess/Helper/MenuHelper.cs index 0bcd0ce1..833224ff 100644 --- a/Bootstrap.DataAccess/Helper/MenuHelper.cs +++ b/Bootstrap.DataAccess/Helper/MenuHelper.cs @@ -112,26 +112,6 @@ namespace Bootstrap.DataAccess return DbHelper.CascadeMenus(menus, activeUrl); } - /// - /// 通过当前用户名与指定菜单路径获取此菜单下所有授权按钮集合 - /// - /// 请求上下文 - /// 资源按钮所属菜单 - /// 资源授权码 - /// - public static bool AuthorizateButtons(HttpContext context, string url, string key) - { - if (context.User.IsInRole("Administrators")) return true; - - var menus = RetrieveAllMenus(context.User.Identity.Name); - var activeMenu = menus.FirstOrDefault(m => m.Url.Equals(url, StringComparison.OrdinalIgnoreCase)); - if (activeMenu == null) return false; - - var authorKeys = menus.Where(m => m.ParentId == activeMenu.Id && m.IsResource == 2).Select(m => m.Url); - var keys = key.SpanSplitAny(",. ;", StringSplitOptions.RemoveEmptyEntries); - return keys.Any(m => authorKeys.Any(k => k == m)); - } - /// /// 通过当前用户名获得所有菜单,层次化后集合 /// diff --git a/UnitTest/Bootstrap.DataAccess/AuthButtonTest.cs b/UnitTest/Bootstrap.DataAccess/AuthButtonTest.cs deleted file mode 100644 index 3a78ef00..00000000 --- a/UnitTest/Bootstrap.DataAccess/AuthButtonTest.cs +++ /dev/null @@ -1,49 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Http.Authentication; -using Microsoft.AspNetCore.Http.Features; -using System; -using System.Collections.Generic; -using System.Security.Claims; -using System.Threading; -using Xunit; - -namespace Bootstrap.DataAccess -{ - - [Collection("SQLServerContext")] - public class AuthButtonTest - { - [Fact] - public void User_Ok() - { - Assert.False(MenuHelper.AuthorizateButtons(new FooHttpContext(), "~/Admin/Profiles1", "saveDisplayName")); - Assert.False(MenuHelper.AuthorizateButtons(new FooHttpContext(), "~/Admin/Index", "saveDisplayName")); - } - - private class FooHttpContext : HttpContext - { - public override IFeatureCollection Features => throw new NotImplementedException(); - - public override HttpRequest Request => throw new NotImplementedException(); - - public override HttpResponse Response => throw new NotImplementedException(); - - public override ConnectionInfo Connection => throw new NotImplementedException(); - - public override WebSocketManager WebSockets => throw new NotImplementedException(); - - [Obsolete] - public override AuthenticationManager Authentication => throw new NotImplementedException(); - - public override ClaimsPrincipal User { get; set; } = new ClaimsPrincipal(new System.Security.Principal.GenericIdentity("User")); - - public override IDictionary Items { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public override IServiceProvider RequestServices { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public override CancellationToken RequestAborted { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public override string TraceIdentifier { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public override ISession Session { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - - public override void Abort() => throw new NotImplementedException(); - } - } -}