You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SlnMesnac/SlnMesnac.WPF/Attribute/RequirePermissionAttribute.cs

68 lines
2.0 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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; // 假设用户总是有权限
}
}
}