更改RoleHelper.RetrieveRolesByUrl方法名

This commit is contained in:
Argo-Lenovo 2016-11-03 18:49:19 +08:00
parent a69d75e731
commit 849b5dae7a
2 changed files with 54 additions and 54 deletions

View File

@ -1,54 +1,54 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Longbow.Security.Principal; using Longbow.Security.Principal;
using Longbow.Web.Mvc; using Longbow.Web.Mvc;
using System; using System;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
namespace Bootstrap.Admin namespace Bootstrap.Admin
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
class BAAuthorizeAttribute : LgbAuthorizeAttribute class BAAuthorizeAttribute : LgbAuthorizeAttribute
{ {
public override void OnAuthorization(AuthorizationContext filterContext) public override void OnAuthorization(AuthorizationContext filterContext)
{ {
if (filterContext.HttpContext.User.Identity.IsAuthenticated) if (filterContext.HttpContext.User.Identity.IsAuthenticated)
{ {
string username = filterContext.HttpContext.User.Identity.Name; string username = filterContext.HttpContext.User.Identity.Name;
var roles = RoleHelper.RetrieveRolesByUserName(username).Select(r => r.RoleName); var roles = RoleHelper.RetrieveRolesByUserName(username).Select(r => r.RoleName);
filterContext.HttpContext.User = new LgbPrincipal(filterContext.HttpContext.User.Identity, roles); filterContext.HttpContext.User = new LgbPrincipal(filterContext.HttpContext.User.Identity, roles);
} }
base.OnAuthorization(filterContext); base.OnAuthorization(filterContext);
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="userName"></param> /// <param name="userName"></param>
/// <returns></returns> /// <returns></returns>
protected override bool AuthenticateRole() protected override bool AuthenticateRole()
{ {
string url = string.Format("~/{0}/{1}", ControllerName, ActionName); string url = string.Format("~/{0}/{1}", ControllerName, ActionName);
Roles = string.Join(";", RoleHelper.RetrieveRolesByURL(url).Select(r => r.RoleName)); Roles = string.Join(";", RoleHelper.RetrieveRolesByUrl(url).Select(r => r.RoleName));
return base.AuthenticateRole(); return base.AuthenticateRole();
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="filterContext"></param> /// <param name="filterContext"></param>
protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext) protected override void HandleUnauthorizedRequest(System.Web.Mvc.AuthorizationContext filterContext)
{ {
if (!filterContext.HttpContext.User.Identity.IsAuthenticated) if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{ {
base.HandleUnauthorizedRequest(filterContext); base.HandleUnauthorizedRequest(filterContext);
return; return;
} }
var view = new ViewResult(); var view = new ViewResult();
view.ViewName = "UnAuthorized"; view.ViewName = "UnAuthorized";
filterContext.Result = view; filterContext.Result = view;
} }
} }
} }

View File

@ -396,7 +396,7 @@ namespace Bootstrap.DataAccess
/// 从Navigators-〉GroupNavigatorRole-〉Role查查询某个用户所拥有的角色 /// 从Navigators-〉GroupNavigatorRole-〉Role查查询某个用户所拥有的角色
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<Role> RetrieveRolesByURL(string url) public static IEnumerable<Role> RetrieveRolesByUrl(string url)
{ {
string key = string.Format("{0}{1}", RoleDataKey, url); string key = string.Format("{0}{1}", RoleDataKey, url);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RoleDataKey), k => return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RoleDataKey), k =>