From 9a7b407ecb5eba48a263ff1afacade83be1076cc Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Thu, 17 Nov 2016 12:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=9C=80=E6=96=B0=E7=9A=84?= =?UTF-8?q?=E7=88=B6=E7=B1=BB=E9=87=8D=E6=9E=84=E8=AE=A4=E8=AF=81=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=EF=BC=8C=E6=9B=B4=E5=8A=A0=E7=AE=80=E6=B4=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../App_Start/BAAuthorizeAttribute.cs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs b/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs index 3c41228c..3c0a47bc 100644 --- a/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs +++ b/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs @@ -1,7 +1,7 @@ using Bootstrap.DataAccess; -using Longbow.Security.Principal; using Longbow.Web.Mvc; using System; +using System.Collections.Generic; using System.Linq; using System.Web.Mvc; @@ -13,26 +13,23 @@ namespace Bootstrap.Admin [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] class BAAuthorizeAttribute : LgbAuthorizeAttribute { - public override void OnAuthorization(AuthorizationContext filterContext) - { - if (filterContext.HttpContext.User.Identity.IsAuthenticated) - { - string username = filterContext.HttpContext.User.Identity.Name; - var roles = RoleHelper.RetrieveRolesByUserName(username).Select(r => r.RoleName); - filterContext.HttpContext.User = new LgbPrincipal(filterContext.HttpContext.User.Identity, roles); - } - base.OnAuthorization(filterContext); - } /// /// /// /// /// - protected override bool AuthenticateRole() + protected override IEnumerable RetrieveRolesByUserName(string userName) { - string url = string.Format("~/{0}/{1}", ControllerName, ActionName); - Roles = string.Join(";", RoleHelper.RetrieveRolesByUrl(url).Select(r => r.RoleName)); - return base.AuthenticateRole(); + return RoleHelper.RetrieveRolesByUserName(userName).Select(r => r.RoleName); + } + /// + /// + /// + /// + /// + protected override IEnumerable RetrieveRolesByUrl(string url) + { + return RoleHelper.RetrieveRolesByUrl(url).Select(r => r.RoleName); } /// /// @@ -45,7 +42,6 @@ namespace Bootstrap.Admin base.HandleUnauthorizedRequest(filterContext); return; } - var view = new ViewResult(); view.ViewName = "UnAuthorized"; filterContext.Result = view;