using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Principal;
using System.Diagnostics;
namespace HTB.DevFx.Security
{
///
/// 方法属性权限检测类
///
public class PermissionPrincipal : IPrincipal
{
private IIdentity _identity;
private string[] _roles;
///
/// 构造函数
///
///
public PermissionPrincipal(IIdentity _IID)
{
_identity = _IID;
_roles = new string[1] { "check" };
}
///
/// 检测角色资料
///
///
///
public bool IsInRole(string role)
{
return Check_PopedomTypeAttaible();
}
///
/// 用户标识
///
public IIdentity Identity
{
get
{
return _identity;
}
}
private bool Check_PopedomTypeAttaible()
{
//System.Web.HttpResponse rp = System.Web.HttpContext.Current.Response;
//rp.Write("执行方法名称!");
//rp.Write(System.Reflection.MethodBase.GetCurrentMethod().Name);
//rp.Write("
");
StackTrace stack = new StackTrace();
foreach (StackFrame sframe in stack.GetFrames())
{
//rp.Write(sframe.GetMethod().Name);
//rp.Write("
");
foreach (PermissionAttaible var in sframe.GetMethod().GetCustomAttributes(typeof(PermissionAttaible), true))
{
//rp.Write(var.PType.ToString());
//rp.Write("
");
//rp.Write("无权限!");
//rp.End();
//return false;
PermissionHelper.CheckPermissionVoid(var.PermissionId);
}
//rp.Write("------");
//rp.Write("
");
}
//rp.End();
return true;
}
}
///
/// 权限方法属性
///
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true, Inherited = true)]
public class PermissionAttaible : Attribute
{
///
/// 构造函数
///
///
public PermissionAttaible(int PT)
{
_PType = PT;
}
///
/// 权限类型
///
private int _PType;
///
/// 权限编码
///
public int PermissionId
{
get
{
return _PType;
}
}
}
}