简体   繁体   English

C#Windows应用程序中基于许可证的配置

[英]License Based Configuration in C# Windows Application

I am working on a Windows application in C# (.NET 4.0) and need something to implement some basic ACL rules or more specifically, apply certain configurations based on the user type. 我正在使用C#(.NET 4.0)中的Windows应用程序,需要一些东西来实现一些基本的ACL规则,或者更具体地说,根据用户类型应用某些配置。

The application has license keys that we are able to use to determine the user type (ie User, Installer, Engineer) among other pieces of information. 该应用程序具有许可证密钥,我们可以使用它来确定用户类型(即用户,安装程序,工程师)以及其他信息。

Based on the type of user, certain features, menus, buttons, and display data will be different. 根据用户类型,某些功能,菜单,按钮和显示数据将有所不同。 I could just hard code showing and hiding of these elements in the application based on the user type, but we have a permissions matrix that defines the permissions so I would like to create an ACL so we could easily audit the matrix to the application code. 我可以根据用户类型硬编码在应用程序中显示和隐藏这些元素,但是我们有一个权限矩阵来定义权限,因此我想创建一个ACL,以便我们可以轻松地审核应用程序代码的矩阵。

I have looked around but a lot of the ACL and security code in the System.Security namespace seem to be made for Windows and Filesystem ACLs. 我环顾四周,但System.Security命名空间中的很多ACL和安全代码似乎是针对Windows和文件系统ACL进行的。

Can someone recommend any existing classes (preferably free) that implement simple ACL's in C#. 有人可以推荐在C#中实现简单ACL的任何现有类(最好是免费的)。

I just need to be able to do something like this: 我只需要能够做这样的事情:

ACL acl = new ACL();
acl.addRole("User");
acl.addRole("Manufacturer");

acl.addResource("SpecialButton");

acl.deny("SpecialButton");
acl.allow("SpecialButton", "Manufacturer");

// so later in my app I can do

theUserType = "Manufacturer";
// ...
if (acl.isAllowed(theUserType, "SpecialButton")) {
    SpecialButton.Visible = true;
}

I'm not looking to try to stop people from tampering with code at runtime, if they want to go out of their way to do that then they can, but I would like an easy way to create and query the ACL's to determine how the GUI looks and what options are available when the program is loaded based on the key. 我不打算试图阻止人们在运行时篡改代码,如果他们想要尽力而为,那么他们可以,但我想要一种简单的方法来创建和查询ACL以确定如何GUI查看以及基于密钥加载程序时可用的选项。

It's easy enough to create this but if it is already done then that is even better. 创建它很容易,但如果已经完成,那就更好了。

If you are deploying your app to Windows 7 or Windows Server 2003/2008, you might want to consider using the free Authorization Manager functionality that comes with Windows. 如果要将应用程序部署到Windows 7或Windows Server 2003/2008,则可能需要考虑使用Windows附带的免费授权管理器功能。

See here for a full overview from Microsoft. 有关Microsoft的完整概述,请参见此处

Essentially, it allows you to define Roles, the Tasks that each Role can perform, and the Operations permissible in each Task. 从本质上讲,它允许您定义角色,每个角色可以执行的任务以及每个任务中允许的操作。

There is an API which you can use from your C# app to query the Authorization Store, so you can then query what Operations are available to a particular Role. 您可以从C#应用程序中使用API​​来查询授权存储,以便您可以查询特定角色可用的操作。 This will give you back an aggregate list of the Operation numbers assigned to that role. 这将返回分配给该角色的操作编号的汇总列表。 Then you can test for the existence of a particular operation (or if it is missing) and customize your UI accordingly. 然后,您可以测试特定操作的存在(或者如果缺少)并相应地自定义UI。

HTH, Dean. HTH,院长。

There really isn't much to what you are talking about. 你说的话真的不多。

You have Roles and Roles have Attributes. 你有角色和角色有属性。 A single attribute might appear in one or more roles. 单个属性可能出现在一个或多个角色中。 Simple enough. 很简单。

The license key defines the role in use. 许可证密钥定义了正在使用的角色。 From that, load the list of attributes which could be either a stand alone list of characters ("OPENCONTACT", "EDITCONTACT", DELETECONTACT") or name value pairs (100=OPENCONTACT, 101=EDITCONTACT, etc) 从那里,加载属性列表,这些属性可以是独立的字符列表(“OPENCONTACT”,“EDITCONTACT”,DELETECONTACT“)或名称值对(100 = OPENCONTACT,101 = EDITCONTACT等)

Although you can use AzMan for this, it's a bit more than it sounds like you need. 虽然你可以使用AzMan,但它听起来比你需要的多一点。

The Role / Attribute list could be delivered as an encrypted resource that's loaded at runtime... 角色/属性列表可以作为在运行时加载的加密资源提供......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM