public object Invoke(IMethodInvocation invocation) { object res; DateTime start; try { if (log.IsDebugEnabled) { log.Debug(string.Format("Client call: {0}.{1}", invocation.Target, invocation.Method.Name)); } if (invocation.Method.MethodHandle != _LoginMethod && invocation.Method.MethodHandle != _LoginVersionCheckMethod && invocation.Method.MethodHandle != _IsUserHasPasswordMethod) { IService svc = invocation.Target as IService; if (svc == null) { object[] attrs = invocation.Method.ReflectedType.GetCustomAttributes(_ServiceIdType, false); if (attrs == null || attrs.Length == 0) { throw new AccessDeniedException(); } Guid id = new Guid(((ServiceIDAttribute)attrs[0]).ID); if (!_AuthSvc.CanExecute(invocation.Method.MethodHandle, id)) { throw new AccessDeniedException(); } } else { if (!_AuthSvc.CanExecute(invocation.Method.MethodHandle, svc.ServiceId)) { throw new AccessDeniedException(); } } } start = DateTime.Now; res = invocation.Proceed(); if (log.IsDebugEnabled) { log.Debug(string.Format("Execution time: {0}", DateTime.Now - start)); } } catch (Exception ex) { if (log.IsWarnEnabled) { log.Warn(string.Format("Exception thrown from {0}.{1}\n Exception Message = {2}:{3}", invocation.Target, invocation.Method.Name, ex.GetType(), ex.Message)); } throw; } return(res); }
/// <summary> /// 检查当前用户是否有权限执行插件元素所对应的功能 /// </summary> /// <param name="caller">调用者</param> /// <param name="context">执行上下文</param> /// <returns>如果通过权限管理系统检查用户可以执行此插件元素对应的功能返回true,否则为false</returns> public bool IsValid(object caller, WorkItem context) { IAuthorizationService authorizationService = context.Services.Get <IAuthorizationService>(); if (authorizationService != null) { string actionKey = SecurityUtility.HashObject(addInPath + command); bool flag = authorizationService.CanExecute(actionKey); ILog logger = context.Services.Get <ILog>(); logger.Debug("AddIn Path: " + addInPath + ", Command : " + command + " CanExecute: " + flag); return(flag); } else { return(true); } }