15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Code access security ❘ 563<br />

➤ FileDialogPermission controls the ability to access files that have been selected by the user in the<br />

Open dialog box. This permission is commonly used when FileIOPermission is not granted to<br />

allow limited access to files.<br />

➤ FileIOPermission controls the ability to work with files (reading, writing, <strong>and</strong> appending to files, as<br />

well as creating, altering, <strong>and</strong> accessing folders).<br />

➤ IsolatedStorageFilePermission controls the ability to access private virtual file systems.<br />

➤ IsolatedStoragePermission controls the ability to access isolated storage; storage that is associated<br />

with an individual user <strong>and</strong> with some aspect of the code’s identity. Isolated storage is discussed<br />

in Chapter 29, “Manipulating Files <strong>and</strong> the Registry.”<br />

➤ MessageQueuePermission controls the ability to use message queues through the Microsoft<br />

Message Queue.<br />

➤ PerformanceCounterPermission controls the ability to make use of performance counters.<br />

➤ PrintingPermission controls the ability to print.<br />

➤ ReflectionPermission controls the ability to discover information about a type at runtime by using<br />

System.Reflection.<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

RegistryPermission controls the ability to read, write, create, or delete registry keys <strong>and</strong> values.<br />

SecurityPermission controls the ability to execute, assert permissions, call into unmanaged code,<br />

skip verification, <strong>and</strong> other rights.<br />

ServiceControllerPermission controls the ability to control Windows services.<br />

SocketPermission controls the ability to make or accept TCP/IP connections on a network transport<br />

address.<br />

SQLClientPermission controls the ability to access SQL Server databases with the .<strong>NET</strong> data provider<br />

for SQL Server.<br />

➤ UIPermission controls the ability to access the user interface.<br />

➤ WebPermission controls the ability to make or accept connections to or from the Web.<br />

With each of these permission classes, it is often possible to specify an even deeper level of granularity; for<br />

example, the DirectoryServicesPermission allows you to differentiate between read <strong>and</strong> write access,<br />

<strong>and</strong> it also allows you to define which entries in the directory services are allowed or denied access.<br />

Permission sets<br />

Permission sets are collections of permissions. With permission sets, it is not necessary to apply every<br />

single permission to code; permissions are grouped into permission sets. For example, an assembly that has<br />

FullTrust permissions has full access to all resources. With intranet permissions, the assembly is restricted;<br />

that is, it is not allowed to write to the file system other than using the isolated storage. You can create a<br />

custom permission set that includes required permissions.<br />

By assigning the permission to code groups, there is no need to deal with every single permission. Instead,<br />

the permissions are applied in blocks, which is why .<strong>NET</strong> has the concept of permission sets. These are<br />

lists of code access permissions grouped into a named set. The following list explains the seven named<br />

permission sets you get out of the box:<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

FullTrust means no permission restrictions.<br />

SkipVerification means that verification is not done.<br />

Execution grants the ability to run, but not to access, any protected resources.<br />

Nothing grants no permissions <strong>and</strong> prevents the code from executing.<br />

LocalIntranet specifies a subset of the full set of permissions. For example, file IO is restricted to read<br />

access on the share where the assembly originates. With .<strong>NET</strong> 3.5 <strong>and</strong> earlier editions (before .<strong>NET</strong><br />

3.5 SP1) this permission set was used when an application was running from a network share.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!