| 1 |
Apache Notes |
| 2 |
============ |
| 3 |
This package allows you to create a complex site authorization system where |
| 4 |
specific actions on resources are given custom rules. It extends |
| 5 |
Apache::AuthCookie to track sessions. It has been tested with Apache 1 and 2, |
| 6 |
and seems to work well. There are sample sites in the samples directory. The |
| 7 |
differences in the two apache environments require slightly different setups, |
| 8 |
so be sure to use the proper sample for your configuration. |
| 9 |
|
| 10 |
Use Apache2::SiteControl for apache 2.x. |
| 11 |
|
| 12 |
Description |
| 13 |
=========== |
| 14 |
|
| 15 |
There are two levels of control in Apache::SiteControl. |
| 16 |
|
| 17 |
The first is managed by Apache::SiteControl, and determines if a valid user |
| 18 |
has logged in. If so, it makes a user object available to the request |
| 19 |
processor. This is done using Apache::SiteControl::UserFactory (a good base |
| 20 |
implementation is already written). The underlying code associates this user |
| 21 |
with a session, and manages the browser interaction. |
| 22 |
|
| 23 |
The second level of control is supplied by an application level |
| 24 |
PermissionManager. The user objects are passed to this object, along |
| 25 |
with the requested action and an opaque resource (of any type). Rules are |
| 26 |
installed in the PM that determine if a specific action is allowed for a given |
| 27 |
user and resource. |
| 28 |
|
| 29 |
if($manager->can($currentUser, "change", $dnsrecord)) { |
| 30 |
... |
| 31 |
} |
| 32 |
|
| 33 |
where the PM applies the various installed rules (user-defined) and returns |
| 34 |
true if the action is allowed, false otherwise. In this example, one of the |
| 35 |
rules might detect that the resource (dnsrecord) is a row from a DNS tracking |
| 36 |
table. It might then check to see if the currentUser is associated with |
| 37 |
DNS management and return true if they are, false otherwise. The top level |
| 38 |
application could then use this in a pretty abstract way. For example, if there |
| 39 |
is a generic section of code that allows users to modify a row from a table, |
| 40 |
the same code could be used: |
| 41 |
|
| 42 |
if($manager->can($currentUser, "change", $thisRecord)) { |
| 43 |
... |
| 44 |
} |
| 45 |
|
| 46 |
The application doesn't have to figure out what thisRecord is...the rules can |
| 47 |
sense them. This allows the top-level application to be written in very |
| 48 |
generic terms, and rules to be written based on the actual logic involved. |
| 49 |
|
| 50 |
A rule might include code like this: |
| 51 |
|
| 52 |
sub grants |
| 53 |
{ |
| 54 |
$this = shift; |
| 55 |
$user = shift; |
| 56 |
$action = shift; |
| 57 |
$resource = shift; |
| 58 |
|
| 59 |
if($action eq "change") { |
| 60 |
if($resource->isa("DNS::Record")) |
| 61 |
{ |
| 62 |
if($resource->getContactEMail() eq $user->getAttribute("email")) |
| 63 |
{ |
| 64 |
return "permission granted by DNSRule"; |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
return 0; |
| 69 |
} |
| 70 |
|
| 71 |
which would detect the proper types that it knows how to handle, and do a check |
| 72 |
that would indicate if permission is to be granted. |
| 73 |
|
| 74 |
Comments on Rules |
| 75 |
|
| 76 |
How would you make a system that allows everything, unless something is |
| 77 |
specifically denied? |
| 78 |
Have a GrantAll rule that always grants permission. |
| 79 |
Add rules that never grant, but deny on specific cases. |
| 80 |
|
| 81 |
How to make a system that denies everything except things that have been |
| 82 |
checked out: |
| 83 |
Write rules that grant on your specific cases. The default is to deny |
| 84 |
permission if no rules have anything else to say about the request. |
| 85 |
|
| 86 |
A rule can take several approaches: |
| 87 |
|
| 88 |
Relative rule: It grants but never denies. Or it denies, but never grants. |
| 89 |
|
| 90 |
Absolute rule: If it grants, then it does not deny. If it does not grant, then |
| 91 |
it denies. |
| 92 |
|
| 93 |
Read the manual pages for more information. |