diff --git a/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs b/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs index 5af1f82d..3c41228c 100644 --- a/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs +++ b/Bootstrap.Admin/App_Start/BAAuthorizeAttribute.cs @@ -1,54 +1,54 @@ -using Bootstrap.DataAccess; -using Longbow.Security.Principal; -using Longbow.Web.Mvc; -using System; -using System.Linq; -using System.Web.Mvc; - -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() - { - string url = string.Format("~/{0}/{1}", ControllerName, ActionName); - Roles = string.Join(";", RoleHelper.RetrieveRolesByURL(url).Select(r => r.RoleName)); - return base.AuthenticateRole(); - } - /// - /// - /// - /// - protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext) - { - if (!filterContext.HttpContext.User.Identity.IsAuthenticated) - { - base.HandleUnauthorizedRequest(filterContext); - return; - } - - var view = new ViewResult(); - view.ViewName = "UnAuthorized"; - filterContext.Result = view; - } - } +using Bootstrap.DataAccess; +using Longbow.Security.Principal; +using Longbow.Web.Mvc; +using System; +using System.Linq; +using System.Web.Mvc; + +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() + { + string url = string.Format("~/{0}/{1}", ControllerName, ActionName); + Roles = string.Join(";", RoleHelper.RetrieveRolesByUrl(url).Select(r => r.RoleName)); + return base.AuthenticateRole(); + } + /// + /// + /// + /// + protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext) + { + if (!filterContext.HttpContext.User.Identity.IsAuthenticated) + { + base.HandleUnauthorizedRequest(filterContext); + return; + } + + var view = new ViewResult(); + view.ViewName = "UnAuthorized"; + filterContext.Result = view; + } + } } \ No newline at end of file diff --git a/Bootstrap.DataAccess/RoleHelper.cs b/Bootstrap.DataAccess/RoleHelper.cs index d4c3d0e6..3165d428 100644 --- a/Bootstrap.DataAccess/RoleHelper.cs +++ b/Bootstrap.DataAccess/RoleHelper.cs @@ -396,7 +396,7 @@ namespace Bootstrap.DataAccess /// 从Navigators-〉GroupNavigatorRole-〉Role查查询某个用户所拥有的角色 /// /// - public static IEnumerable RetrieveRolesByURL(string url) + public static IEnumerable RetrieveRolesByUrl(string url) { string key = string.Format("{0}{1}", RoleDataKey, url); return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RoleDataKey), k =>