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

第一:角色和用户类中需要修改成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权限的更多相关文章

  1. XAF 框架中,自定义参数动作(Action),输入参数的控件可定义,用于选择组织及项目

    XAF 框架中,如何生成一个自定义参数动作(Action),输入参数的控件可定义? 参考文档:https://documentation.devexpress.com/eXpressAppFramew ...

  2. N个整数(数的大小为0-255)的序列,把它们加密为K个整数(数的大小为0-255).再将K个整数顺序随机打乱,使得可以从这乱序的K个整数中解码出原序列。设计加密解密算法,且要求K<=15*N.

    N个整数(数的大小为0-255)的序列,把它们加密为K个整数(数的大小为0-255).再将K个整数顺序随机打乱,使得可以从这乱序的K个整数中解码出原序列.设计加密解密算法,且要求K<=15*N. ...

  3. devexpress xaf 开发中遇到的问题.

    devexpress xaf 开发中遇到的问题很多久了就忘记了.每天都把开发内容记录下来,方便大家,方便自己

  4. 15、解决14中csv用excel打开乱码的问题 open('zhihu.csv','w',newline='',encoding='utf-8-sig')

    解决14中csv用excel打开乱码的问题 ,其实就是在写csv的时候把 utf-8 改成 utf-8-sig open('zhihu.csv','w',newline='',encoding='ut ...

  5. 在VMware 14中安装Centos7

    在VMware 14中安装Centos7 一.安装前准备 安装VMware14.1 Centos7 64位镜像下载 在VMware中安装Centos7的步骤为: 1.创建虚拟机 创建虚拟机有两种方式: ...

  6. 并发编程学习笔记(4)----jdk5中提供的原子类及Lock使用及原理

    (1)jdk中原子类的使用: jdk5中提供了很多原子类,它会使变量的操作变成原子性的. 原子性:原子性指的是一个操作是不可中断的,即使是在多个线程一起操作的情况下,一个操作一旦开始,就不会被其他线程 ...

  7. Ubuntu 14 中给 APACHE2安装 SSL 模块 Enable SSL site on Ubuntu 14 LTS, Apache 2.4.7:

    Ubuntu 14 中给 APACHE2安装 SSL 模块 Enable SSL site on Ubuntu 14 LTS, Apache 2.4.7: 参考 http://blog.csdn.ne ...

  8. Go 1.14 中 Cleanup 方法简介

    目录 一般的测试 使用 defer 清除依赖 使用 Cleanup 关于t.Parallel 总结 原文:What's New In Go 1.14: Test Cleanup 单元测试通常遵循某些步 ...

  9. Java 14中对switch的增强,终于可以不写break了

    面对这样的if语句,你是不是很难受呢? if (flag == 1) { log.info("didispace.com: 1"); } else if (flag == 2) { ...

随机推荐

  1. 在 Typescript 2.0 中使用 @types 类型定义

    在 Typescript 2.0 中使用 @type 类型定义 基于 Typescript 开发的时候,很麻烦的一个问题就是类型定义.导致在编译的时候,经常会看到一连串的找不到类型的提示.解决的方式经 ...

  2. Java陷阱之assert关键字

    Java陷阱之assert关键字   一.概述   在C和C++语言中都有assert关键,表示断言. 在Java中,同样也有assert关键字,表示断言,用法和含义都差不多.   二.语法   在J ...

  3. 如何将App程序发布到App Store?

    见链接:http://my.oschina.net/u/1245365/blog/201920

  4. webstrom11 和12破解码

    很多人都发现 http://idea.lanyus.com/ 不能激活了 很多帖子说的 http://15.idea.lanyus.com/ 之类都用不了了,最近封的厉害仅作测试. 红色字体的是最近大 ...

  5. android bundle存放数据详解

    转载自:android bundle存放数据详解 正如大家所知道,Activity之间传递数据,是将数据存放在Intent或者Bundle中 例如: 将数据存放倒Intent中传递: 将数据放到Bun ...

  6. 裸奔Spring(1)

    pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...

  7. 如何判断js中的数据类型

    如何判断js中的数据类型:typeof.instanceof. constructor. prototype方法比较 如何判断js中的类型呢,先举几个例子: var a = "iamstri ...

  8. 第六百零六天 how can I 坚持(应该是六百零六天吧)

    找了个考研的借口,也是挺逗的,终于结束了,而且考的很渣. 最近发生了很多事,很快就要离开泛华了,放弃安逸,开始改变吧,其实感觉自己内心挺怂的,很怕改变,哎,这不像是有梦想,能成事的人应该有的. 还是想 ...

  9. 8天掌握EF的Code First开发系列之3 管理数据库创建,填充种子数据以及LINQ操作详解

    本文出自8天掌握EF的Code First开发系列,经过自己的实践整理出来. 本篇目录 管理数据库创建 管理数据库连接 管理数据库初始化 填充种子数据 LINQ to Entities详解 什么是LI ...

  10. PHP+Mysql+jQuery实现文件下载次数统计

    数据表 CREATE TABLE IF NOT EXISTS `downloads` (   `id` int(6) unsigned NOT NULL AUTO_INCREMENT,   `file ...