| 1 | package Apache::SiteControl::PermissionManager; | ||
| 2 | |||
| 3 | use 5.008; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Carp; | ||
| 7 | |||
| 8 | our $VERSION = "1.0"; | ||
| 9 | |||
| 10 | sub new { | ||
| 11 | my $proto = shift; | ||
| 12 | my $class = ref($proto) || $proto; | ||
| 13 | my $this = { rules => [] }; | ||
| 14 | bless ($this, $class); | ||
| 15 | return $this; | ||
| 16 | } | ||
| 17 | |||
| 18 | sub addRule($$) | ||
| 19 | { | ||
| 20 | my $this = shift; | ||
| 21 | my $rule = shift; | ||
| 22 | |||
| 23 | push @{$this->{rules}}, $rule; | ||
| 24 | |||
| 25 | return 1; | ||
| 26 | } | ||
| 27 | |||
| 28 | sub can($$$$) | ||
| 29 | { | ||
| 30 | my $this = shift; | ||
| 31 | my $user = shift; | ||
| 32 | my $action = shift; | ||
| 33 | my $resource = shift; | ||
| 34 | my $rule; | ||
| 35 | my ($granted, $denied) = (0,0); | ||
| 36 | |||
| 37 | for $rule (@{$this->{rules}}) | ||
| 38 | { | ||
| 39 | $granted = 1 if($rule->grants($user, $action, $resource)); | ||
| 40 | $denied = 1 if($rule->denies($user, $action, $resource)); | ||
| 41 | } | ||
| 42 | |||
| 43 | return ($granted && !$denied); | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; | ||
| 47 | |||
| 48 | __END__ |