1 package Apache2
::AuthzCaps
0.001;
8 use Apache2
::Const qw
/OK DECLINED/;
9 use Apache2
::RequestRec
;
10 use YAML
::Any qw
/LoadFile DumpFile/;
12 use parent qw
/Exporter/;
14 our @EXPORT_OK = qw
/setcap hascaps/;
16 ##################################################
21 my ($user, $cap, $value) = @_;
22 my $config = eval { LoadFile
"$rootdir/$user.yml" } // {};
24 my $caps=$config->{caps
};
26 delete $caps->{$cap} unless $value;
27 $caps->{$cap} = 1 if $value;
28 DumpFile
"$rootdir/$user.yml", $config
32 my ($user, @caps) = @_;
33 my $config = LoadFile
"$rootdir/$user.yml";
34 my $caps = $config->{caps
};
36 return 0 unless $caps->{$_}
44 local $rootdir = $r->dir_config('AuthzCapsRootdir');
47 LOOP
: for my $requirement (map { $_->{requirement
} } @
{$r->requires}) {
48 my ($command, @args) = split ' ', $requirement;
52 return OK
if hascaps
$user, @args
67 Apache2::AuthzCaps - mod_perl2 capability authorization
71 use Apache2::AuthzCaps qw/setcap hascaps/;
72 $Apache2::AuthzCaps::rootdir = "/path/to/user/directory"
73 setcap marius => deleteusers => 1; # Grant marius the deleteusers capability
74 setcap marius => createusers => 0;
75 hascaps marius => qw/deleteusers/; # returns 1, since marius can delete users
76 hascaps marius => qw/deleteusers createusers/; # returns 0, since marius can delete users but cannot create users
80 # Insert authentication here
81 PerlAuthzHandler Apache2::AuthzCaps
82 PerlSetVar AuthzCapsRootdir /path/to/user/directory
83 Require cap staff important
87 # 1) Let important staff members access /protected
88 # 2) Let admins access /protected
89 # 3) Not let anyone else (such as an important non-staff member or an non-important staff member) access /protected
93 Apache2::AuthzCaps is a perl module which provides simple Apache2 capability-based authorization. It contains a PerlAuthzHandler and some utility functions.
95 The user data is stored in YAML files in a user-set directory. Set this directory using:
97 $Apache2::AuthzCaps::rootdir = "/path/to/directory"; # From perl
98 PerlSetVar AuthzCapsRootdir /path/to/directory # From Apache2 config
104 =item B<setcap>(I<$username>, I<$capability>, I<$value>)
106 If I<$value> is true, grants I<$username> the I<$capability> capability. Otherwise denies I<$username> that capability.
108 =item B<hascaps>(I<$username>, I<$cap>, ...)
110 Returns true if and only of I<$username> has ALL of the listed capabilities. Dies if I<$username> does not exist.
114 The PerlAuthzHandler for use in apache2.
120 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
122 =head1 COPYRIGHT AND LICENSE
124 Copyright (C) 2013 by Marius Gavrilescu
126 This library is free software; you can redistribute it and/or modify
127 it under the same terms as Perl itself, either Perl version 5.14.2 or,
128 at your option, any later version of Perl 5 you may have available.
This page took 0.025526 seconds and 4 git commands to generate.