Beispiel #1
0
        private bool tryAccess(IInvocation invocation)
        {
            PermissionPointAttribute attribute = AttributeHelper.GetAttribute <PermissionPointAttribute>(invocation) as PermissionPointAttribute;

            if (attribute == null)
            {
                return(true);
            }
            string strLogHeader = "Access accepted";

            try
            {
                IPermissionPointResolve resolve = IocCoreFactory.Get <IPermissionPointResolve>(attribute.ResolveType);
                PermissionPoint         point   = new DefaultPermissionPoint(attribute,
                                                                             InterceptorHelper.GetInvocationTarget(invocation),
                                                                             InterceptorHelper.GetInvocationMethod(invocation) as MemberInfo,
                                                                             InterceptorHelper.GetInvocationMethodArgs(invocation)) as PermissionPoint;
                PermissionInfo info = resolve.Resolve(point);
                info++;
                if (attribute.IsAcceptLog && LogLevel <= attribute.LogLevel)
                {
                    StringBuilder logstr = new StringBuilder();
                    logstr.AppendFormat("{0} {1} {2} {3}-----Access Log ", strLogHeader, PrincipalTokenHolder.CurrentPrincipal.ToString(), attribute.ToString(), InterceptorHelper.GetMethodInfo(invocation));
                    Log.Log(logstr.ToString(), attribute.LogLevel);
                }
            }
            catch (AccessException ex)
            {
                strLogHeader = "Access Denied";
                if (attribute.IsAcceptLog && LogLevel <= attribute.LogLevel)
                {
                    StringBuilder logstr = new StringBuilder();
                    logstr.AppendFormat("{0} {1} {2} {3}-----Access Log ", strLogHeader, PrincipalTokenHolder.CurrentPrincipal.ToString(), attribute.ToString(), InterceptorHelper.GetMethodInfo(invocation));
                    Log.Log(logstr.ToString(), attribute.LogLevel, ex);
                }
                if (attribute.IsAlert)
                {
                    Console.WriteLine("Access diny alert!");
                }
                if (attribute.IsThrow)
                {
                    throw ex;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #2
0
        public override bool Contains(PermissionInfo permission)
        {
            DefaultPermissionInfo tp = permission as DefaultPermissionInfo;

            if (tp == null)
            {
                return(false);
            }
            if (!CompareName(tp))
            {
                return(false);
            }
            else
            {
                return(CompareAction(tp));
            }
        }
Beispiel #3
0
 public override bool Equals(object other)
 {
     if (other == this)
     {
         return(true);
     }
     if (other is EmptyPermissionInfo)
     {
         return(true);//所有权限都包含空权限!!!!
     }
     if (other is PermissionInfo)
     {
         PermissionInfo p = (PermissionInfo)other;
         return(Name.Equals(p.name) && Action.Equals(p.action));
     }
     else
     {
         return(false);
     }
 }
Beispiel #4
0
 public override bool Contains(PermissionInfo permission)
 {
     return(false);
 }
Beispiel #5
0
 /// <summary>
 /// 判断此权限是否包含指定的权限
 /// </summary>
 /// <returns>如果此权限包含指定权限则返回true</returns>
 public abstract bool Contains(PermissionInfo permission);
Beispiel #6
0
 public override bool Remove(PermissionInfo item)
 {
     return(false);
 }
Beispiel #7
0
 public override void Add(PermissionInfo item)
 {
 }
Beispiel #8
0
 /// <summary>
 /// 判断列表中是否存在(单纯比较内容)
 /// </summary>
 public override bool Exist(PermissionInfo p)
 {
     return(false);
 }