/// <summary> /// 获取权限列表 /// </summary> /// <returns></returns> public List <Permission> GetAllPermission() { var list = new List <Permission>(); var actions = _mvcHelper.GetAllAction(); foreach (var action in actions) { //排除匿名接口和通用接口 if (action.MethodInfo.CustomAttributes.Any(m => m.AttributeType == typeof(AllowAnonymousAttribute) || m.AttributeType == typeof(CommonAttribute))) { continue; } var p = new Permission { ModuleCode = action.Controller.Area, Controller = action.Controller.Name, Action = action.Name, Name = action.Controller.Description ?? action.Controller.Name }; p.Name += "_" + (action.Description ?? action.Name); list.Add(p); } return(list); }
private AuditInfoEntity CreateAuditInfo(ActionExecutingContext context) { try { var routeValues = context.ActionDescriptor.RouteValues; var auditInfo = new AuditInfoEntity { AccountId = _loginInfo.AccountId, AccountName = _loginInfo.AccountName, Area = routeValues["area"] ?? "", Controller = routeValues["controller"], Action = routeValues["action"], Parameters = JsonSerializer.Serialize(context.ActionArguments), Platform = _loginInfo.Platform, IP = _loginInfo.IP, ExecutionTime = DateTime.Now }; //获取模块的名称 if (auditInfo.Area.NotNull()) { auditInfo.Module = _moduleCollection.FirstOrDefault(m => m.Code.EqualsIgnoreCase(auditInfo.Area))?.Name; } var controllerDescriptor = _mvcHelper.GetAllController().FirstOrDefault(m => m.Area.NotNull() && m.Area.EqualsIgnoreCase(auditInfo.Area) && m.Name.EqualsIgnoreCase(auditInfo.Controller)); if (controllerDescriptor != null) { auditInfo.ControllerDesc = controllerDescriptor.Description; var actionDescription = _mvcHelper.GetAllAction().FirstOrDefault(m => m.Controller == controllerDescriptor && m.Name.EqualsIgnoreCase(auditInfo.Action)); if (actionDescription != null) { auditInfo.ActionDesc = actionDescription.Description; } } //记录浏览器UA if (_loginInfo.Platform == Platform.Web) { auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"]; } return(auditInfo); } catch (Exception ex) { _logger.LogError("审计日志创建异常:{@ex}", ex); } return(null); }
public IResultModel AllAction([BindRequired] string module, [BindRequired] string controller) { var list = _mvcHelper.GetAllAction().Where(m => m.Controller.Area.EqualsIgnoreCase(module) && m.Controller.Name.EqualsIgnoreCase(controller) && !m.MethodInfo.CustomAttributes.Any(n => n.AttributeType == typeof(AllowAnonymousAttribute) || n.AttributeType == typeof(CommonAttribute))) .Select(m => new OptionResultModel { Label = m.Description, Value = m.Name }).ToList(); return(ResultModel.Success(list)); }
/// <summary> /// 获取权限列表 /// </summary> /// <returns></returns> public List <PermissionEntity> GetAllPermission() { var list = new List <PermissionEntity>(); var actions = _mvcHelper.GetAllAction(); foreach (var action in actions) { //如果控制器未继承ControllerAbstract抽象类,则表示不需要权限验证 if (!typeof(ControllerAbstract).IsAssignableFrom(action.Controller.TypeInfo)) { continue; } //排除匿名接口和通用接口 if (action.MethodInfo.CustomAttributes.Any(m => m.AttributeType == typeof(AllowAnonymousAttribute) || m.AttributeType == typeof(CommonAttribute))) { continue; } var p = new PermissionEntity { ModuleCode = action.Controller.Area, Controller = action.Controller.Name, Action = action.Name, Name = action.Controller.Description ?? action.Controller.Name }; var httpMethodAttr = action.MethodInfo.CustomAttributes.FirstOrDefault(m => m.AttributeType.Name.StartsWith("Http")); if (httpMethodAttr != null) { var httpMethodName = httpMethodAttr.AttributeType.Name.Replace("Http", "").Replace("Attribute", "").ToUpper(); p.HttpMethod = (HttpMethod)Enum.Parse(typeof(HttpMethod), httpMethodName); p.Name += "_" + (action.Description ?? action.Name); p.Code = $"{p.ModuleCode}_{p.Controller}_{p.Action}_{httpMethodName}".ToLower(); list.Add(p); } } return(list); }
/// <summary> /// 加载权限 /// </summary> private void LoadPermissions() { var actions = _mvcHelper.GetAllAction(); foreach (var action in actions) { //如果控制器未继承ZtController类,则表示不需要权限验证 if (!typeof(ZtController).IsAssignableFrom(action.Controller.TypeInfo)) { continue; } //排除匿名接口和通用接口 if (action.MethodInfo.CustomAttributes.Any(m => m.AttributeType == typeof(AllowAnonymousAttribute) || m.AttributeType == typeof(CommonAttribute))) { continue; } var p = new PermissionDescriptor { IsPage = action.MethodInfo.CustomAttributes.Any(m => m.AttributeType == typeof(PageAttribute)), Name = action.Description ?? action.Name, ModuleCode = action.Controller.Area, Controller = action.Controller.Name, Action = action.Name }; var httpMethodAttr = action.MethodInfo.CustomAttributes.FirstOrDefault(m => m.AttributeType.Name.StartsWith("Http")); if (httpMethodAttr != null) { var httpMethodName = httpMethodAttr.AttributeType.Name.Replace("Http", "").Replace("Attribute", "").ToUpper(); p.HttpMethod = (HttpMethod)Enum.Parse(typeof(HttpMethod), httpMethodName); } else { p.HttpMethod = HttpMethod.GET; } Add(p); } }
private AuditInfoEntity CreateAuditInfo(ActionExecutingContext context) { var routeValues = context.ActionDescriptor.RouteValues; var auditInfo = new AuditInfoEntity { AccountId = _loginInfo.AccountId, Area = routeValues["area"] ?? "", Controller = routeValues["controller"], Action = routeValues["action"], Parameters = JsonConvert.SerializeObject(context.ActionArguments), Platform = _loginInfo.Platform, IP = _loginInfo.IP, ExecutionTime = DateTime.Now }; var controllerDescriptor = _mvcHelper.GetAllController().FirstOrDefault(m => m.Area.EqualsIgnoreCase(auditInfo.Area) && m.Name.EqualsIgnoreCase(auditInfo.Controller)); if (controllerDescriptor != null) { auditInfo.ControllerDesc = controllerDescriptor.Description; var actionDescription = _mvcHelper.GetAllAction().FirstOrDefault(m => m.Controller == controllerDescriptor && m.Name.EqualsIgnoreCase(auditInfo.Action)); if (actionDescription != null) { auditInfo.ActionDesc = actionDescription.Description; } } //记录浏览器UA if (_loginInfo.Platform == Platform.Web) { auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"]; } return(auditInfo); }
private AuditInfoAddModel CreateAuditInfo(ActionExecutingContext context) { try { var routeValues = context.ActionDescriptor.RouteValues; var auditInfo = new AuditInfoAddModel { Area = routeValues["area"] ?? "", Controller = routeValues["controller"], Action = routeValues["action"], Parameters = context.ActionArguments.ToJson(), IP = _loginInfo.IP }; var controllerDescriptor = _mvcHelper.GetAllController().FirstOrDefault(m => m.Area.NotNull() && m.Area.EqualsIgnoreCase(auditInfo.Area) && m.Name.EqualsIgnoreCase(auditInfo.Controller)); if (controllerDescriptor != null) { auditInfo.ControllerDesc = controllerDescriptor.Description; var actionDescription = _mvcHelper.GetAllAction().FirstOrDefault(m => m.Controller == controllerDescriptor && m.Name.EqualsIgnoreCase(auditInfo.Action)); if (actionDescription != null) { auditInfo.ActionDesc = actionDescription.Description; } } auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"]; return(auditInfo); } catch (Exception ex) { _logger.LogError("审计日志创建异常:{@ex}", ex); } return(null); }
private List <PermissionEntity> GetActions() { var list = new List <PermissionEntity>(); var actions = _mvcHelper.GetAllAction(); foreach (var action in actions) { //排除匿名接口和通用接口 if (action.MethodInfo.CustomAttributes.Any(m => m.AttributeType == typeof(AllowAnonymousAttribute) || m.AttributeType == typeof(CommonAttribute))) { continue; } var p = new PermissionEntity { Area = action.Controller.Area, Controller = action.Controller.Name, Action = action.Name, PermissionName = $"{action.Controller.Description ?? action.Controller.Name}_{action.Description ?? action.Name}", Source = PermissionSource.Auto }; var httpMethodAttr = action.MethodInfo.CustomAttributes.FirstOrDefault(m => m.AttributeType.Name.StartsWith("Http")); if (httpMethodAttr != null) { var httpMethodName = httpMethodAttr.AttributeType.Name.Replace("Http", "").Replace("Attribute", "").ToUpper(); p.HttpMethod = httpMethodName; p.PermissionCode = $"{p.Area}_{p.Controller}_{p.Action}_{httpMethodName}".ToLower(); list.Add(p); } } return(list); }