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); }
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)); } }
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); } }
public override bool Contains(PermissionInfo permission) { return(false); }
/// <summary> /// 判断此权限是否包含指定的权限 /// </summary> /// <returns>如果此权限包含指定权限则返回true</returns> public abstract bool Contains(PermissionInfo permission);
public override bool Remove(PermissionInfo item) { return(false); }
public override void Add(PermissionInfo item) { }
/// <summary> /// 判断列表中是否存在(单纯比较内容) /// </summary> public override bool Exist(PermissionInfo p) { return(false); }