15.01.2013 Views

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Although both follow a similar model, they feel quite different to use. Part of the<br />

reason for this is that they typically put you on a different side of the fence: with<br />

code access security, you’re usually the untrusted party; with identity and role security,<br />

you’re usually the untrusting party. Code access security is most often forced<br />

upon you by the CLR or a hosting environment such as ASP.NET or Internet Explorer,<br />

whereas authorization is usually something you implement to prevent unprivileged<br />

callers from accessing your program.<br />

As an application developer, you’ll need to understand code access security (CAS)<br />

in order to write assemblies that will run in a limited permissions environment. If<br />

you’re writing and selling a component <strong>library</strong>, it’s easy to overlook the possibility<br />

that your customers will call your <strong>library</strong> from a sandboxed environment such as a<br />

SQL Server CLR host.<br />

Another reason to understand CAS is if you want to create your own hosting environment<br />

that sandboxes other assemblies. For example, you might write an application<br />

that allows third parties to write plug-in components. Running those plugins<br />

in an application domain with limited permissions reduces the chance of a plugin<br />

destabilizing your application or compromising its security.<br />

The main scenario for identity and role security is when writing middle tier or web<br />

application servers. You typically decide on a set of roles, and then for each method<br />

that you expose, you demand that callers are members of a particular role.<br />

CodeAccessPermission and PrincipalPermission<br />

There are essentially two kinds of permissions:<br />

CodeAccessPermission<br />

The abstract base class for all code access security (CAS) permissions, such as<br />

FileIOPermission, ReflectionPermission, or PrintingPermission<br />

PrincipalPermission<br />

Describes an identity and/or role (e.g., “Mary” or “Human Resources”)<br />

The term permission is somewhat misleading in the case of CodeAccessPermission,<br />

because it suggests something has been granted. This is not necessarily the case. A<br />

CodeAccessPermission object describes a privileged operation.<br />

For instance, a FileIOPermission object describes the privilege of being able to Read,<br />

Write, or Append to a particular set of files or directories. Such an object can be used<br />

in a variety of ways:<br />

• To verify that you and all your callers have the rights to perform these actions<br />

(Demand)<br />

• To verify that your immediate caller has the rights to perform these actions<br />

(LinkDemand)<br />

• To temporarily escape a sandbox and Assert your assembly-given rights to perform<br />

these actions, regardless of callers’ privileges<br />

752 | Chapter 20: Security

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

Saved successfully!

Ooh no, something went wrong!