首页 > 代码库 > 在xaf 14 中实现 Tonyyang原文中的action权限
在xaf 14 中实现 Tonyyang原文中的action权限
具体实现过程,主要修改了以下几个地方:
第一:角色和用户类中需要修改成SecurityStrategy的方式:
具体代码
MySecurityRole:
using System;using System.Collections.Generic;using System.Linq;using System.Security;using System.Text;using DevExpress.ExpressApp.Security.Strategy;using DevExpress.Xpo;using DevExpress.Persistent.Base;using DevExpress.Persistent.Validation;using System.Collections.ObjectModel;using DevExpress.Persistent.Base.Security;namespace SecurityDemoTest.Module.BusinessObjects{ [DefaultClassOptions] public class MySecurityRole : SecuritySystemRole { public const string DefaultAdministratorsGroupName = "Administrators"; //private List<IPermission> _Permissions = new List<IPermission>(); public MySecurityRole(Session session) : base(session) { } [Association("ActionDatas-MySecurityRoles")] public XPCollection<ActionData> ActionPermissions { get { return GetCollection<ActionData>("ActionPermissions"); } } }}
MySecurityUser:
using System;using System.Collections.Generic;using System.Linq;//using DevExpress.ExpressApp.Security;using System.Drawing;using System.Security;using DevExpress.ExpressApp.Security.Strategy;using DevExpress.Persistent.Validation;using DevExpress.Xpo;using DevExpress.Persistent.Base;using DevExpress.Persistent.Base.General;using DevExpress.Persistent.Base.Security;using DevExpress.ExpressApp.DC;using System.ComponentModel;//using WinWebSolution.Module;namespace SecurityDemoTest.Module.BusinessObjects{ [XafDisplayName("User"), Persistent, ImageName("BO_User")] public class MySecurityUser : SecuritySystemUser // SecurityUserWithRolesBase { public MySecurityUser(DevExpress.Xpo.Session session) : base(session) { //_Permissions = new List<IPermission>(); } [Persistent("Color")] private int _Color; [NonPersistent] public Color Color { get { return Color.FromArgb(_Color); } set { SetPropertyValue("Color", ref _Color, value.ToArgb()); } } public override void AfterConstruction() { base.AfterConstruction(); _Color = Color.White.ToArgb(); } private string _Description; public string Description { get { return _Description; } set { SetPropertyValue("Description", ref _Description, value); } } }}
第二:需要在ViewController中添加如下代码:
private static bool IsAllowAccessAction(string actionId) { MySecurityUser currentUser = SecuritySystem.CurrentUser as MySecurityUser; Guard.ArgumentNotNull(currentUser, "CurrentUser"); Guard.ArgumentNotNullOrEmpty(actionId, "ActionId"); foreach (MySecurityRole role in currentUser.Roles) { foreach (ActionData ap in role.ActionPermissions) { if (ap.ActionId == actionId && ap.Kind == "Custom") return true; } } return false; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。