145 lines
4.5 KiB
C#
145 lines
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using HTB.DevFx.Core;
|
|
using System.Configuration;
|
|
using HTB.DevFx.Utils;
|
|
using HTB.DevFx.OnlineManagement;
|
|
|
|
namespace HTB.DevFx.Security
|
|
{
|
|
/// <summary>
|
|
/// 权限检测类
|
|
/// </summary>
|
|
public class PermissionHelper
|
|
{
|
|
|
|
/// <summary>
|
|
/// 检测权限
|
|
/// </summary>
|
|
private bool CheckPermission()
|
|
{
|
|
//获取当前访问的页面文件目录下的权限配置文件
|
|
Permission Pis = GetModulePermission();
|
|
|
|
//如果未配置权限集合则直接返回true
|
|
if (Pis == null)
|
|
return true;
|
|
|
|
//如果用户已经经过认证
|
|
if (Authenticator.IsAuthenticated)
|
|
{
|
|
int UserID = Authenticator.UserID;
|
|
|
|
//从缓存中检查当前用户是否为超级用户
|
|
//如果是管理员则直接返回true
|
|
OnlineUser<string> _curUserOnlineInfo = OnlineUserHelper.UserOnlineList.GetValue(UserID);
|
|
if (_curUserOnlineInfo.U_Super_Flag)
|
|
return true;
|
|
|
|
//检测页面文件名访问权限
|
|
PermissionItem PsItem = GetPermissionItem(Pis.ItemList);
|
|
if (PsItem == null)
|
|
return false;
|
|
|
|
if (string.IsNullOrEmpty(WebHelper.GetScriptNameQueryString()))
|
|
return UserData.CheckPageCode(UserID, Pis.module_id, Pis.PageCode, PsItem.Item_Value);
|
|
else
|
|
{
|
|
if (!UserData.CheckPageCode(UserID, Pis.module_id, Pis.PageCode, PsItem.Item_Value))
|
|
{
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//检测页面文件url权限
|
|
PsItem = GetUrlPermissionItem(Pis.ItemList);
|
|
if (PsItem == null)
|
|
return true;
|
|
return UserData.CheckPageCode(UserID, Pis.module_id, Pis.PageCode, PsItem.Item_Value);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前目录下权限配置集合
|
|
/// </summary>
|
|
public static Permission GetModulePermission()
|
|
{
|
|
return (Permission)ConfigurationManager.GetSection("Permission");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取当前面页所属的PermissionItem
|
|
/// </summary>
|
|
/// <param name="List">权限列表</param>
|
|
/// <returns></returns>
|
|
public static PermissionItem GetPermissionItem(List<PermissionItem> List)
|
|
{
|
|
PermissionItem PI = null;
|
|
string curUrlFileName =WebHelper.GetScriptNameWithDot();
|
|
foreach (PermissionItem var in List)
|
|
{
|
|
if (var.Item_FileList.IndexOf(WebHelper.GetScriptName().ToLower()) >= 0)
|
|
{
|
|
return var;
|
|
}
|
|
}
|
|
return PI;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取当前面页Url所属的PermissionItem
|
|
/// </summary>
|
|
/// <param name="List">权限</param>
|
|
/// <returns>权限值</returns>
|
|
public static PermissionItem GetUrlPermissionItem(List<PermissionItem> List)
|
|
{
|
|
PermissionItem PI = null;
|
|
foreach (PermissionItem var in List)
|
|
{
|
|
if (var.Item_FileList.IndexOf("," + WebHelper.GetScriptNameUrl().ToLower() + ",") >= 0)
|
|
{
|
|
return var;
|
|
}
|
|
}
|
|
return PI;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测按钮权限
|
|
/// </summary>
|
|
/// <param name="PT"></param>
|
|
/// <returns></returns>
|
|
public static bool CheckButtonPermission(int PermissionId)
|
|
{
|
|
Permission Pis = GetModulePermission();
|
|
if (Pis == null)
|
|
return true;
|
|
return UserData.CheckPageCode(Authenticator.UserID, Pis.ApplicationID, Pis.PageCode, PermissionId);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检测权限,如果无操作权限则直接返回
|
|
/// </summary>
|
|
/// <param name="PT"></param>
|
|
public static void CheckPermissionVoid(int PermissionId)
|
|
{
|
|
if (!CheckButtonPermission(PermissionId))
|
|
{
|
|
//发送无权限操作提示
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|