Apache-SiteControl

 view release on metacpan or  search on metacpan

lib/Apache/SiteControl/GrantAllRule.pm  view on Meta::CPAN

our $VERSION = "1.0";

sub new {
   my $proto = shift;
   my $class = ref($proto) || $proto;
   my $this  = { };
   bless ($this, $class);
   return $this;
}

sub grants($$$$)
{
   my $this = shift;
   my $user = shift;
   my $action = shift;
   my $resource = shift;

   return "Default is to allow";
}

sub denies($$$$)
{
   my $this = shift;
   my $user = shift;
   my $action = shift;
   my $resource = shift;

   return 0;
}

1;

lib/Apache/SiteControl/PermissionManager.pm  view on Meta::CPAN

our $VERSION = "1.0";

sub new {
   my $proto = shift;
   my $class = ref($proto) || $proto;
   my $this  = { rules => [] };
   bless ($this, $class);
   return $this;
}

sub addRule($$)
{
   my $this = shift;
   my $rule = shift;

   push @{$this->{rules}}, $rule;

   return 1;
}

sub can($$$$)
{
   my $this = shift;
   my $user = shift;
   my $action = shift;
   my $resource = shift;
   my $rule;
   my ($granted, $denied) = (0,0);

   for $rule (@{$this->{rules}})
   {

lib/Apache/SiteControl/Rule.pm  view on Meta::CPAN

our $VERSION = "1.0";

sub new {
   my $proto = shift;
   my $class = ref($proto) || $proto;
   my $this  = { };
   bless ($this, $class);
   return $this;
}

sub grants($$$$)
{
   my $this = shift;
   my $user = shift;
   my $action = shift;
   my $resource = shift;

   return 0;
}

sub denies($$$$)
{
   my $this = shift;
   my $user = shift;
   my $action = shift;
   my $resource = shift;

   return "Abstract rule denies everything. Do not use.";
}

1;

lib/Apache/SiteControl/User.pm  view on Meta::CPAN


use 5.008;
use strict;
use warnings;
use Carp;

our $VERSION = "1.0";

# This object represents a transient view of a persistent user. The UserManager
# is responsible for loading/saving these things.
sub new($$$$) {
   my $proto = shift;
   my $username = shift;
   my $sessionid = shift;
   my $usermanager = shift;
   my $class = ref($proto) || $proto;
   my $this  = { username => $username,
                 sessionid => $sessionid,
                 manager => $usermanager, 
                 attributes => {} };
   bless ($this, $class);

sample/EditControlRule.pm  view on Meta::CPAN

@ISA = qw(Apache::SiteControl::Rule);

# This rule is going to be used in a system that automatically grants
# permission for everything (via the GrantAllRule). So this rule will
# only worry about what to deny, and the grants method can return whatever.
# Note that writing a deny-based system is inherently more dangerous and 
# buggy because of the lack of type-safety. Typos in the HTML components can
# cause a rule to fail to deny an invalid request, which is typically less
# desirable than failing to grant a request. The former is a security hole that
# might get missed; the latter is a bug that gets quickly reported.
sub grants($$$$)
{
   return 0;
}

sub denies($$$$)
{
   my ($this, $user, $action, $resource) = @_;

   return 1 if($action eq "edit" && $user->getUsername ne "admin");

   return 0;
}

1;

sample/site/index.html  view on Meta::CPAN

<%init>
my $currentUser = Apache::SiteControl->getCurrentUser($r);
my $manager = Apache::SiteControl->getPermissionManager($r);

# This would be where you would access your back-end data store to get
# data...we will simulate this will literals:
my $preferences = { favoriteColor => 'Red', age => 20 };
</%init>

<%once>
sub colorList($)
{
   my $prefs = shift;
   my $result = "";

   for my $color ("Red", "Green", "Blue", "Purple", "Pink")
   {
      if($color eq $prefs->{"favoriteColor"}) {
         $result .= "<OPTION SELECTED>$color\n";
      } else {
         $result .= "<OPTION>$color\n";



( run in 0.420 second using v1.01-cache-2.11-cpan-65fba6d93b7 )