line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Apache2::AuthAny::AuthUtil; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1522
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
22871
|
use URI::Escape; |
|
1
|
|
|
|
|
1562
|
|
|
1
|
|
|
|
|
87
|
|
5
|
1
|
|
|
1
|
|
9
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
6
|
1
|
|
|
1
|
|
411
|
use Apache2::Const -compile => qw(OK DECLINED HTTP_UNAUTHORIZED REDIRECT); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use CGI::Cookie (); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Apache2::AuthAny::DB (); |
10
|
|
|
|
|
|
|
our $aaDB; |
11
|
|
|
|
|
|
|
our $VERSION = '0.201'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub goToGATE { |
14
|
|
|
|
|
|
|
my $r = shift; |
15
|
|
|
|
|
|
|
my $reason = shift; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $subReason = shift; |
18
|
|
|
|
|
|
|
my $request = uri_escape($r->unparsed_uri); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# prevent redirect loops |
21
|
|
|
|
|
|
|
$request =~ s/aalogin/aadisabled/g; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $dumped_subReason = $subReason ? ", subReason => " . Data::Dumper::Dumper($subReason) : ''; |
24
|
|
|
|
|
|
|
$r->log->info("Apache2::AuthAny::AuthUtil: Going to gate with request => '$request'" . |
25
|
|
|
|
|
|
|
"reason => '$reason' $dumped_subReason" ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $cf = Apache2::Module::get_config('Apache2::AuthAny', $r->server, $r->per_dir_config) || {}; |
28
|
|
|
|
|
|
|
my $gateURL = $cf->{AuthAnyGateURL}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $gate = "$gateURL?req=$request"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
if ($reason) { |
33
|
|
|
|
|
|
|
$gate .= "&reason=$reason"; |
34
|
|
|
|
|
|
|
if ($reason eq 'unknown') { |
35
|
|
|
|
|
|
|
$gate .= "&authProvider=$ENV{AA_PROVIDER}&authId=$ENV{AA_USER}"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
if ($reason eq 'authz') { |
38
|
|
|
|
|
|
|
$gate .= "&username=$ENV{REMOTE_USER}"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
if ($subReason && $subReason->{req_roles}) { |
41
|
|
|
|
|
|
|
$gate .= "&req_roles=$subReason->{req_roles}"; |
42
|
|
|
|
|
|
|
$gate .= "&user_roles=$subReason->{user_roles}"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
if ($subReason && $subReason->{msg}) { |
45
|
|
|
|
|
|
|
$gate .= "&msg=$subReason->{msg}"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$r->headers_out->set(Location => $gate); |
50
|
|
|
|
|
|
|
return Apache2::Const::REDIRECT; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub logout { |
54
|
|
|
|
|
|
|
my $r = shift; |
55
|
|
|
|
|
|
|
my $pid = shift; |
56
|
|
|
|
|
|
|
my $aaDB = Apache2::AuthAny::DB->new() unless $aaDB; |
57
|
|
|
|
|
|
|
unless ($aaDB->logoutPCookie($pid)) { |
58
|
|
|
|
|
|
|
die "logout failed"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $request = $r->unparsed_uri; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# prevent redirect loops |
64
|
|
|
|
|
|
|
$request =~ s/aalogout/aadisabled/g; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$r->headers_out->set(Location => $request); |
67
|
|
|
|
|
|
|
return Apache2::Const::REDIRECT; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub login { |
71
|
|
|
|
|
|
|
my $r = shift; |
72
|
|
|
|
|
|
|
my $pid = shift; |
73
|
|
|
|
|
|
|
my $aaDB = Apache2::AuthAny::DB->new() unless $aaDB; |
74
|
|
|
|
|
|
|
unless ($aaDB->logoutPCookie($pid)) { |
75
|
|
|
|
|
|
|
die "logout failed"; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $request = $r->unparsed_uri; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# prevent redirect loops |
81
|
|
|
|
|
|
|
$request =~ s/aalogout/aadisabled/g; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$r->headers_out->set(Location => $request); |
84
|
|
|
|
|
|
|
return Apache2::Const::REDIRECT; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|