首页 > 其他 > 详细

在xaf 14 中实现 Tonyyang原文中的action权限

时间:2014-08-20 15:59:32      阅读:340      评论:0      收藏:0      [点我收藏+]

具体实现过程,主要修改了以下几个地方:

第一:角色和用户类中需要修改成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;
        }

 

在xaf 14 中实现 Tonyyang原文中的action权限,布布扣,bubuko.com

在xaf 14 中实现 Tonyyang原文中的action权限

原文:http://www.cnblogs.com/ddlzq/p/3924565.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!