|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
Features .NET Feature — Writing Client Components in .NET
Universal solutions PART 2
Jun. 26, 2007 03:15 AM
Determining the Set of Permissions and Creating the Permission Set
We'll get our permissions once the assembly is loaded, but to exercise them, we need to explicitly assert the permissions we need when we need them. And guess what: asserting permissions requires... permission to assert! I guess this is the reason why books about .NET Security are so thick. Fortunately, it's simpler to code than to explain. The following snippet creates a permission set called "My Permission Set" and adds the three security permissions we've talked about:
NamedPermissionSet permSet = new NamedPermissionSet(PermissionSetName, PermissionState.None); permSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution | SecurityPermissionFlag.UnmanagedCode | SecurityPermissionFlag.Assertion)); Finally, the permission set should be added to the Machine policy level which we got previously: machinePolicyLevel.AddNamedPermissionSet(permSet);
Creating the Code Group
private static readonly byte[] PublicKey ={ ... }; The PublicKey byte array is the public key we got earlier, of course. Just like permission sets, the code group is added to the Machine policy level: machinePolicyLevel.RootCodeGroup.AddChild(group); Finally, we need to commit our changes to the security manager: SecurityManager.SavePolicy();
Installing the Permissions The best solution is to write an install program (an .MSI or Microsoft Installer) file in which the "install" and "uninstall" custom actions add (resp. remove) your permissions. The accompanying code has two projects for this purpose:
1. A project called PermissionInstaller, which contains the necessary code to install and uninstall the permissions. The assembly implements a type PermissionInstaller derived from System.Configuration.Install.Installer, and with the explanation above you should have no trouble finding out what's going on. The type implements the Install and Uninstall methods. Reader Feedback: Page 1 of 1
Your Feedback
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
||||||||||||||||||||||||||||||||||||||||||||||||||||