Filename | /var/www/foswikidev/core/lib/Foswiki/Configure/Auth.pm |
Statements | Executed 11 statements in 440µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 231µs | 297µs | BEGIN@7 | Foswiki::Configure::Auth::
1 | 1 | 1 | 11µs | 31µs | BEGIN@6 | Foswiki::Configure::Auth::
1 | 1 | 1 | 10µs | 10µs | BEGIN@5 | Foswiki::Configure::Auth::
1 | 1 | 1 | 8µs | 20µs | BEGIN@17 | Foswiki::Configure::Auth::
1 | 1 | 1 | 8µs | 12µs | BEGIN@18 | Foswiki::Configure::Auth::
0 | 0 | 0 | 0s | 0s | checkAccess | Foswiki::Configure::Auth::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | package Foswiki::Configure::Auth; | ||||
4 | |||||
5 | 2 | 34µs | 1 | 10µs | # spent 10µs within Foswiki::Configure::Auth::BEGIN@5 which was called:
# once (10µs+0s) by Foswiki::Plugins::ConfigurePlugin::BEGIN@37 at line 5 # spent 10µs making 1 call to Foswiki::Configure::Auth::BEGIN@5 |
6 | 2 | 31µs | 2 | 52µs | # spent 31µs (11+21) within Foswiki::Configure::Auth::BEGIN@6 which was called:
# once (11µs+21µs) by Foswiki::Plugins::ConfigurePlugin::BEGIN@37 at line 6 # spent 31µs making 1 call to Foswiki::Configure::Auth::BEGIN@6
# spent 21µs making 1 call to Error::import |
7 | 2 | 116µs | 2 | 318µs | # spent 297µs (231+66) within Foswiki::Configure::Auth::BEGIN@7 which was called:
# once (231µs+66µs) by Foswiki::Plugins::ConfigurePlugin::BEGIN@37 at line 7 # spent 297µs making 1 call to Foswiki::Configure::Auth::BEGIN@7
# spent 21µs making 1 call to Error::import |
8 | |||||
9 | =begin TML | ||||
10 | |||||
11 | ---+ package Foswiki::Configure::Auth | ||||
12 | |||||
13 | Implements authorization checking for access to configure. | ||||
14 | |||||
15 | =cut | ||||
16 | |||||
17 | 2 | 23µs | 2 | 32µs | # spent 20µs (8+12) within Foswiki::Configure::Auth::BEGIN@17 which was called:
# once (8µs+12µs) by Foswiki::Plugins::ConfigurePlugin::BEGIN@37 at line 17 # spent 20µs making 1 call to Foswiki::Configure::Auth::BEGIN@17
# spent 12µs making 1 call to strict::import |
18 | 2 | 233µs | 2 | 15µs | # spent 12µs (8+4) within Foswiki::Configure::Auth::BEGIN@18 which was called:
# once (8µs+4µs) by Foswiki::Plugins::ConfigurePlugin::BEGIN@37 at line 18 # spent 12µs making 1 call to Foswiki::Configure::Auth::BEGIN@18
# spent 4µs making 1 call to warnings::import |
19 | |||||
20 | =begin TML | ||||
21 | |||||
22 | ---++ StaticMethod checkAccess( $session, $die ) | ||||
23 | |||||
24 | Throws an AccessControlException if access is denied. | ||||
25 | |||||
26 | =cut | ||||
27 | |||||
28 | sub checkAccess { | ||||
29 | my $session = shift; | ||||
30 | my $json = shift; # JSON needs throw JSON errors. | ||||
31 | |||||
32 | return | ||||
33 | if ( defined $Foswiki::cfg{LoginManager} | ||||
34 | && $Foswiki::cfg{LoginManager} eq 'none' ); | ||||
35 | |||||
36 | my $wikiname = Foswiki::Func::getWikiName( $session->{user} ); | ||||
37 | |||||
38 | return | ||||
39 | if ( defined $Foswiki::cfg{AdminUserWikiName} | ||||
40 | && $Foswiki::cfg{AdminUserWikiName} eq $wikiname ); | ||||
41 | |||||
42 | if ( defined $Foswiki::cfg{FeatureAccess}{Configure} | ||||
43 | && length( $Foswiki::cfg{FeatureAccess}{Configure} ) ) | ||||
44 | { | ||||
45 | my $authorized = ''; | ||||
46 | foreach my $authuser ( | ||||
47 | split( /[,\s]/, $Foswiki::cfg{FeatureAccess}{Configure} ) ) | ||||
48 | { | ||||
49 | if ( $wikiname eq $authuser ) { | ||||
50 | $authorized = 1; | ||||
51 | last; | ||||
52 | } | ||||
53 | } | ||||
54 | unless ($authorized) { | ||||
55 | if ($json) { | ||||
56 | throw Foswiki::Contrib::JsonRpcContrib::Error( -32600, | ||||
57 | 'Access to configure denied by {FeatureAccess}{Configure} Setting' | ||||
58 | ); | ||||
59 | } | ||||
60 | else { | ||||
61 | throw Foswiki::AccessControlException( 'VIEW', | ||||
62 | $session->{user}, 'System', 'Configuration', | ||||
63 | 'Denied by {FeatureAccess}{Configure} Setting' ); | ||||
64 | } | ||||
65 | } | ||||
66 | } | ||||
67 | else { | ||||
68 | unless ( Foswiki::Func::isAnAdmin() ) { | ||||
69 | if ($json) { | ||||
70 | throw Foswiki::Contrib::JsonRpcContrib::Error( -32600, | ||||
71 | 'Access to configure denied for non-admin users' ); | ||||
72 | } | ||||
73 | else { | ||||
74 | throw Foswiki::AccessControlException( 'VIEW', | ||||
75 | $session->{user}, 'System', 'Configuration', | ||||
76 | 'Not an admin' ); | ||||
77 | } | ||||
78 | } | ||||
79 | } | ||||
80 | } | ||||
81 | |||||
82 | 1 | 2µs | 1; | ||
83 | __END__ |