增加功能: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.UseStaticFiles();
app.UseAuthentication();
app.UseBootstrapAdminAuthorization(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, DbHelper.RetrieveAppsByUserName);
app.UseBootstrapAdminAuthorization(RoleHelper.RetrieveRolesByUserName, RoleHelper.RetrieveRolesByUrl, AppHelper.RetrieveAppsByUserName);
app.UseCacheManagerCorsHandler();
app.UseSignalR(routes => { routes.MapHub<SignalRHub>("/NotiHub"); });
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));
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.Collections.Generic;
using System.Linq;
@ -40,6 +41,13 @@ namespace Bootstrap.DataAccess
return ret;
}
/// <summary>
/// 根据指定用户名获得授权应用程序集合
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public virtual IEnumerable<string> RetrieveAppsByUserName(string userName) => DbHelper.RetrieveAppsByUserName(userName);
/// <summary>
/// 根据角色ID以及选定的App ID保到角色应用表
/// </summary>

View File

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