| 1 | package Catalyst::Plugin::Authorization::ACL; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | $Catalyst::Plugin::Authorization::ACL::AUTHORITY = 'cpan:RKITOVER'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | $Catalyst::Plugin::Authorization::ACL::VERSION = '0.16'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use mro 'c3'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | with 'Catalyst::ClassData'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Catalyst::Plugin::Authorization::ACL::Engine qw/$DENIED $ALLOWED/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # TODO | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # refactor forcibly_allow_access so that the guts are cleaner | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | __PACKAGE__->mk_classdata("_acl_engine"); | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my $FORCE_ALLOW = bless {}, __PACKAGE__ . "::Exception"; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 397 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 397 | my ( $c, $class, $action ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 397 | ▶ | if ( Scalar::Util::blessed($action) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
builtin::blessed($action) and $action->name ne "access_denied" and $action->name ne "ACL error rethrower"
builtin::blessed($action) and $action->name ne "access_denied"
MC/DC33%1/3
builtin::blessed($action) and $action->name ne "access_denied" and $action->name ne "ACL error rethrower"
builtin::blessed($action)
$action->name ne "access_denied"
$action->name ne "ACL error rethrower"
Truth table50%2/4
A and B and C
A= builtin::blessed($action)B= $action->name ne "access_denied"C= $action->name ne "ACL error rethrower"
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | and $action->name ne "access_denied" | ||||||||||||||||||||||||||||||||||||||||||
| 25 | and $action->name ne "ACL error rethrower" ) | ||||||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 364 | eval { $c->_acl_engine->check_action_rules( $c, $action ) }; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 364 | ▶ | if ( my $err = $@ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 33 | my $force_allow = $c->acl_access_denied( $class, $action, $err ); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | return unless $force_allow; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 331 | $c->acl_access_allowed( $class, $action ); | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 366 | $c->maybe::next::method( $class, $action ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub acl_allow_root_internals { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
acl_allow_root_internals: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my ( $app, $cmp ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | foreach my $action ( qw/begin auto end/ ) { | |||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | $app->allow_access("/$action") if $app->get_action($action, "/"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | ▶ | sub setup_actions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_actions: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | my $app = shift; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | my $ret = $app->maybe::next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | $app->_acl_engine( | |||||||||||||||||||||||||||||||||||||||||
| 55 | Catalyst::Plugin::Authorization::ACL::Engine->new($app) ); | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | ▶ | if ( my $config = $app->config->{acl} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | foreach my $action ( qw/allow deny/ ) { | |||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | my $method = "${action}_access"; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | if ( my $paths = $config->{$action} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | $app->$method( $_ ) for @$paths; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | ▶ | my $cond = ( $action eq "allow" ? "if" : "unless" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | $method .= "_$cond"; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | if ( my $args = $config->{"${action}_$cond"} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my ( $cond, @paths ) = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $app->$method( $cond, $_ ) for @paths; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | $ret; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | ▶ | sub deny_access_unless { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deny_access_unless: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | $c->_acl_engine->add_deny(@_); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub deny_access_unless_any { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deny_access_unless_any: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | my ($c, $path, $roles) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 5 | ▶ | $c->deny_access_unless($path, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 5 | my ($c, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 5 | return $c->check_any_user_role(@$roles); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | sub deny_access { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deny_access: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | $c->deny_access_unless( @_, undef ); | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | sub allow_access_if { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_access_if: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | $c->_acl_engine->add_allow(@_); | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub allow_access_if_any { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_access_if_any: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my ($c, $path, $roles) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $c->allow_access_if($path, sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my ($c, $action) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return $c->check_any_user_role(@$roles); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | sub allow_access { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow_access: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | $c->allow_access_if( @_, 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | sub acl_add_rule { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
acl_add_rule: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 1 | $c->_acl_engine->add_rule(@_); | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 33 | ▶ | sub acl_access_denied { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
acl_access_denied: called CC=4 SCAR=15.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 33 | my ( $c, $class, $action, $err ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 33 | my $namespace = $action->namespace; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 33 | ▶ | if ( my $handler = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | ( $c->get_actions( "access_denied", $namespace ) )[-1] ) | ||||||||||||||||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 33 | local $c->{_acl_forcibly_allowed} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 33 | (my $path = $handler->reverse) =~ s!^/?!/!; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 33 | eval { $c->detach( $path, [$action, $err] ) }; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 33 | ▶ | return 1 if $c->{_acl_forcibly_allowed}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 31 | ▶ | die $@ || $Catalyst::DETACH; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$@ || $Catalyst::DETACH
MC/DC0%0/2
$@ || $Catalyst::DETACH
$@
$Catalyst::DETACH
Truth table33%1/3
A || B
A= $@B= $Catalyst::DETACH
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | $c->execute( | ||||||||||||||||||||||||||||||||||||||||||
| 142 | $class, | ||||||||||||||||||||||||||||||||||||||||||
| 143 | bless( | ||||||||||||||||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | code => sub { die $err }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | name => "ACL error rethrower", | |||||||||||||||||||||||||||||||||||||||||
| 147 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | "Catalyst::Action" | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | ▶ | sub forcibly_allow_access { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
forcibly_allow_access: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | $c->{_acl_forcibly_allowed} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | die $Catalyst::DETACH; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 331 | ▶ | sub acl_access_allowed { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
acl_access_allowed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | __END__ | ||||||||||||||||||||||||||||||||||||||||||