全面修正分级授权,去掉Anonymous,采用Authenticate进行授权

This commit is contained in:
yubaolee
2016-05-26 20:10:22 +08:00
parent b3c6df2931
commit 855f97df7d
24 changed files with 227 additions and 244 deletions

View File

@@ -46,10 +46,10 @@ namespace OpenAuth.Mvc.Controllers
if (function == null)
throw new Exception("未能找到Action");
var anonymous = function.GetCustomAttribute(typeof(AnonymousAttribute));
var authorize = function.GetCustomAttribute(typeof(AuthenticateAttribute));
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
//当前登录用户没有Action记录&&Action没有anonymous标识
if (module == null && anonymous == null)
if (authorize != null && module == null)
{
filterContext.Result = new RedirectResult("/Login/Index");
return;

View File

@@ -4,6 +4,7 @@ using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
using OpenAuth.Domain;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -18,6 +19,7 @@ namespace OpenAuth.Mvc.Controllers
//
// GET: /UserManager/
[Authenticate]
public ActionResult Index()
{
return View();
@@ -33,16 +35,7 @@ namespace OpenAuth.Mvc.Controllers
public string LoadForTree()
{
var models = _app.LoadAll();
//添加根节点
models.Add(new Category
{
Id = 0,
ParentId = -1,
Name = "根结点",
CascadeId = "0"
});
return JsonHelper.Instance.Serialize(models);
return JsonHelper.Instance.Serialize(_app.LoadAll());
}
//添加或修改Category

View File

@@ -16,26 +16,22 @@ namespace OpenAuth.Mvc.Controllers
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
}
[Anonymous]
public string GetModules(int parentId = 0)
{
return JsonHelper.Instance.Serialize(_app.LoadByParent(parentId));
}
[Anonymous]
public ActionResult Index()
{
var user = AutofacExt.GetFromFac<LoginApp>().GetLoginUser();
return View(user.Modules);
}
[Anonymous]
public ActionResult Main()
{
return View();
}
[Anonymous]
public ActionResult Git()
{
return View();
@@ -46,7 +42,6 @@ namespace OpenAuth.Mvc.Controllers
/// </summary>
/// <returns>ActionResult.</returns>
[ChildActionOnly]
[Anonymous]
public ActionResult MenuHeader()
{
return View();

View File

@@ -31,18 +31,15 @@ namespace OpenAuth.Mvc.Controllers
{
_app = AutofacExt.GetFromFac<ModuleElementManagerApp>();
}
[Anonymous]
public ActionResult Index(int id)
{
ViewBag.ModuleId = id;
return View();
}
[Anonymous]
public ActionResult Get(int moduleId = 0)
{
return Json(_app.LoadByModuleId(moduleId));
}
[Anonymous]
[HttpPost]
public string AddOrEditButton(ModuleElement button)
{
@@ -57,7 +54,6 @@ namespace OpenAuth.Mvc.Controllers
}
return JsonHelper.Instance.Serialize(_bjuiResponse);
}
[Anonymous]
public string Del(string moduleElements)
{
try
@@ -80,14 +76,12 @@ namespace OpenAuth.Mvc.Controllers
/// <param name="firstId">The first identifier.</param>
/// <param name="key">The key.</param>
/// <returns>ActionResult.</returns>
[Anonymous]
public ActionResult AssignModuleElement(int firstId, string key)
{
ViewBag.FirstId = firstId;
ViewBag.ModuleType = key;
return View();
}
[Anonymous]
public string LoadWithAccess(int tId, int firstId, string key)
{
return JsonHelper.Instance.Serialize(_app.LoadWithAccess(key, firstId, tId));

View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Web.Mvc;
using Infrastructure.Helper;
using OpenAuth.App.ViewModel;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -18,8 +19,8 @@ namespace OpenAuth.Mvc.Controllers
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
}
//
// GET: /ModuleManager/
[Authenticate]
public ActionResult Index()
{
return View();
@@ -52,14 +53,6 @@ namespace OpenAuth.Mvc.Controllers
public string LoadModuleWithRoot()
{
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().Modules.MapToList<ModuleView>();
//添加根节点
orgs.Add(new Module
{
Id = 0,
ParentId = -1,
Name = "根节点",
CascadeId = "0"
});
return JsonHelper.Instance.Serialize(orgs);
}

View File

@@ -22,11 +22,11 @@ namespace OpenAuth.Mvc.Controllers
//
// GET: /OrgManager/
[Authenticate]
public ActionResult Index()
{
return View();
}
public ActionResult Assign(int firstId, string key)
{
ViewBag.FirstId = firstId;
@@ -34,40 +34,14 @@ namespace OpenAuth.Mvc.Controllers
return View();
}
/// <summary>
/// 返回当前登录用户可访问到的部门
/// </summary>
/// <returns>System.String.</returns>
public string LoadForTree()
{
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().AccessedOrgs;
return JsonHelper.Instance.Serialize(orgs);
}
/// <summary>
/// 返回带有根节点的全部部门,不受用户权限影响
/// <para>可以匿名访问</para>
/// </summary>
/// <returns>System.String.</returns>
[Anonymous]
public string LoadOrg()
{
var orgs = AutofacExt.GetFromFac<LoginApp>().GetLoginUser().AccessedOrgs.MapToList<Org>();
//添加根节点
orgs.Add(new Org
{
Id = 0,
ParentId = -1,
Name = "根结点",
CascadeId = "0"
});
return JsonHelper.Instance.Serialize(orgs);
return JsonHelper.Instance.Serialize(AutofacExt.GetFromFac<LoginApp>().GetLoginUser().AccessedOrgs);
}
public string LoadForUser(int firstId)
{
var orgs = _orgApp.LoadForUser(firstId);
//添加根节点
return JsonHelper.Instance.Serialize(orgs);
}

View File

@@ -20,7 +20,6 @@ namespace OpenAuth.Mvc.Controllers
}
[HttpPost]
[Anonymous]
public string Assign(string type, int firstId, string secIds)
{
try
@@ -36,7 +35,6 @@ namespace OpenAuth.Mvc.Controllers
return JsonHelper.Instance.Serialize(BjuiResponse);
}
[HttpPost]
[Anonymous]
public string UnAssign(string type, int firstId, string secIds)
{
try

View File

@@ -4,6 +4,7 @@ using OpenAuth.Domain;
using System;
using System.Linq;
using System.Web.Mvc;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -18,6 +19,7 @@ namespace OpenAuth.Mvc.Controllers
//
// GET: /UserManager/
[Authenticate]
public ActionResult Index()
{
return View();
@@ -50,14 +52,6 @@ namespace OpenAuth.Mvc.Controllers
public string LoadForTree()
{
var models = _app.LoadAll();
//添加根节点
models.Add(new Resource
{
Id = 0,
ParentId = -1,
Name = "根结点",
CascadeId = "0"
});
return JsonHelper.Instance.Serialize(models);
}

View File

@@ -4,6 +4,7 @@ using OpenAuth.Domain;
using System;
using System.Linq;
using System.Web.Mvc;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -18,6 +19,7 @@ namespace OpenAuth.Mvc.Controllers
//
// GET: /RoleManager/
[Authenticate]
public ActionResult Index()
{
return View();
@@ -66,7 +68,6 @@ namespace OpenAuth.Mvc.Controllers
}
#region
public ActionResult LookupMulti(int userId)
{
ViewBag.UserId = userId;

View File

@@ -3,6 +3,7 @@ using OpenAuth.App;
using OpenAuth.Domain;
using System;
using System.Web.Mvc;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -21,6 +22,7 @@ namespace OpenAuth.Mvc.Controllers
//
// GET: /UserManager/
[Authenticate]
public ActionResult Index()
{
return View();

View File

@@ -4,6 +4,7 @@ using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
using OpenAuth.App.ViewModel;
using OpenAuth.Mvc.Models;
namespace OpenAuth.Mvc.Controllers
{
@@ -18,6 +19,7 @@ namespace OpenAuth.Mvc.Controllers
//
// GET: /UserManager/
[Authenticate]
public ActionResult Index()
{
return View();