增加功能:MongoDB增加应用程序对登录用户进行权限判断逻辑

This commit is contained in:
Argo-Surface 2019-02-25 14:41:04 +08:00
parent 9e138e81d1
commit b6224cd8c5
4 changed files with 39 additions and 3 deletions

View File

@ -125,7 +125,7 @@ namespace Bootstrap.Admin
app.UseResponseCompression(); app.UseResponseCompression();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseAuthentication(); app.UseAuthentication();
app.UseBootstrapAdminAuthorization(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, DbHelper.RetrieveAppsByUserName); app.UseBootstrapAdminAuthorization(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, AppHelper.RetrieveAppsByUserName);
app.UseCacheManagerCorsHandler(); app.UseCacheManagerCorsHandler();
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); }); app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
app.UseMvc(routes => app.UseMvc(routes =>

View File

@ -35,5 +35,25 @@ namespace Bootstrap.DataAccess.MongoDB
var ret = DbManager.Roles.UpdateOne(md => md.Id == roleId, Builders<Role>.Update.Set(md => md.Apps, appIds)); var ret = DbManager.Roles.UpdateOne(md => md.Id == roleId, Builders<Role>.Update.Set(md => md.Apps, appIds));
return true; return true;
} }
/// <summary>
/// 根据指定用户名获得授权应用程序集合
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveAppsByUserName(string userName)
{
var ret = new List<string>();
var roles = RoleHelper.RetrieveRolesByUserName(userName);
if (roles.Contains("Administrators", StringComparer.OrdinalIgnoreCase))
{
ret.AddRange(DictHelper.RetrieveApps().Select(kv => kv.Key));
}
else
{
RoleHelper.Retrieves().Cast<Role>().Where(r => roles.Any(rn => rn == r.RoleName)).ToList().ForEach(r => ret.AddRange(r.Apps));
}
return ret;
}
} }
} }

View File

@ -1,4 +1,5 @@
using Longbow.Data; using Bootstrap.Security.DataAccess;
using Longbow.Data;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -40,6 +41,13 @@ namespace Bootstrap.DataAccess
return ret; return ret;
} }
/// <summary>
/// 根据指定用户名获得授权应用程序集合
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public virtual IEnumerable<string> RetrieveAppsByUserName(string userName) => DbHelper.RetrieveAppsByUserName(userName);
/// <summary> /// <summary>
/// 根据角色ID以及选定的App ID保到角色应用表 /// 根据角色ID以及选定的App ID保到角色应用表
/// </summary> /// </summary>

View File

@ -1,4 +1,5 @@
using Longbow.Cache; using Bootstrap.Security.DataAccess;
using Longbow.Cache;
using Longbow.Data; using Longbow.Data;
using System.Collections.Generic; using System.Collections.Generic;
@ -27,5 +28,12 @@ namespace Bootstrap.DataAccess
if (ret) CacheCleanUtility.ClearCache(appIds: appIds, roleIds: new List<string>() { roleId }); if (ret) CacheCleanUtility.ClearCache(appIds: appIds, roleIds: new List<string>() { roleId });
return ret; return ret;
} }
/// <summary>
/// 根据指定用户名获得授权应用程序集合
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<string> RetrieveAppsByUserName(string userName) => DbContextManager.Create<App>().RetrieveAppsByUserName(userName);
} }
} }