|
|
@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
using Rougamo;
|
|
|
|
|
|
|
|
using Rougamo.Context;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region << 版 本 注 释 >>
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
|
|
|
|
* 版权所有 (c) 2024 WenJY 保留所有权利。
|
|
|
|
|
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
|
|
|
|
|
* 机器名称:T14-GEN3-7895
|
|
|
|
|
|
|
|
* 命名空间:SlnMesnac.WPF.Attribute
|
|
|
|
|
|
|
|
* 唯一标识:34a4538b-bbac-4b48-9e87-1662b859a705
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 创建者:WenJY
|
|
|
|
|
|
|
|
* 电子邮箱:
|
|
|
|
|
|
|
|
* 创建时间:2024-12-30 9:59:19
|
|
|
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
|
|
|
* 描述:
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
*--------------------------------------------------------------------
|
|
|
|
|
|
|
|
* 修改人:
|
|
|
|
|
|
|
|
* 时间:
|
|
|
|
|
|
|
|
* 修改说明:
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
|
|
|
*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
|
|
|
|
|
namespace SlnMesnac.WPF.Attribute
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 权限过滤
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public class RequirePermissionAttribute : MoAttribute
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
private string _permissionName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public RequirePermissionAttribute(string permissionName)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_permissionName = permissionName;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnEntry(MethodContext context)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.WriteLine($"{_permissionName}方法执行前");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool hasPermission = CheckPermission(_permissionName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasPermission)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 如果用户没有权限,抛出异常或采取其他措施
|
|
|
|
|
|
|
|
throw new UnauthorizedAccessException("User does not have the required permission.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base.OnEntry(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private bool CheckPermission(string permissionName)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 这里实现你的权限检查逻辑
|
|
|
|
|
|
|
|
// 例如,从用户的权限集合中检查是否包含所需的权限
|
|
|
|
|
|
|
|
// 这只是一个示例,你可以根据实际需要实现
|
|
|
|
|
|
|
|
return false; // 假设用户总是有权限
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|