| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Authentication::Basic::Remote; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
3691
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
95
|
|
|
4
|
2
|
|
|
2
|
|
12
|
use base qw/Class::Accessor::Fast/; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
2650
|
|
|
5
|
2
|
|
|
2
|
|
16948
|
use NEXT; |
|
|
2
|
|
|
|
|
8059
|
|
|
|
2
|
|
|
|
|
68
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
5335
|
use LWP::UserAgent; |
|
|
2
|
|
|
|
|
178139
|
|
|
|
2
|
|
|
|
|
74
|
|
|
8
|
2
|
|
|
2
|
|
2660
|
use MIME::Base64; |
|
|
2
|
|
|
|
|
3343
|
|
|
|
2
|
|
|
|
|
2314
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/_login/); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Catalyst::Plugin::Authentication::Basic::Remote - (DEPRECATED) Basic authentication via remote host. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Catalyst; |
|
21
|
|
|
|
|
|
|
MyApp->setup(qw/Authentication::Basic::Remote Session::FastMmap/); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
MyApp->config( |
|
24
|
|
|
|
|
|
|
authentication => { |
|
25
|
|
|
|
|
|
|
auth_url => 'http://example.com/', |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Use Template when unauthorized. (option) |
|
28
|
|
|
|
|
|
|
view_tt => 'MyApp::V::TT', |
|
29
|
|
|
|
|
|
|
template => '401.tt', |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# text in Authentication dialog (default="Require Authorization") |
|
32
|
|
|
|
|
|
|
auth_name => 'Require Authorization', |
|
33
|
|
|
|
|
|
|
}, |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DEPRECATION NOTICE |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This module has been deprecated. The use of a new Authentication style is recommended. |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
See L<Catalyst::Plugin::Authetnication> for detail. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Catalyst authentication plugin that use remote host's Basic authentication. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
It is only first time that plugin request to remote host for authentication. |
|
47
|
|
|
|
|
|
|
After that, user infomation keeps in sessions. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=over 4 |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item prepare |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub prepare { |
|
58
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$c = $c->NEXT::prepare(@_); |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
0
|
|
|
|
if ( $c->session->{user} and $c->session->{password} ) { |
|
63
|
0
|
|
|
|
|
|
$c->log->debug("Auth info found in Session:"); |
|
64
|
0
|
|
|
|
|
|
$c->log->debug("user: ".$c->session->{user}); |
|
65
|
0
|
|
|
|
|
|
$c->log->debug("pass: ".$c->session->{password}); |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$c->req->{user} = $c->session->{user}; |
|
68
|
0
|
|
|
|
|
|
$c->req->{password} = $c->session->{password}; |
|
69
|
0
|
|
|
|
|
|
return $c; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
if ( $c->config->{authentication}->{auth_url} ) { |
|
73
|
0
|
0
|
0
|
|
|
|
if ( $c->req->header('Authorization') and my ($tokens) = ( $c->req->header('Authorization') =~ /^Basic (.+)$/) ) { |
|
74
|
0
|
|
|
|
|
|
my ( $username, $password ) = split /:/, decode_base64($tokens); |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$c->log->debug("Authentication via ". $c->config->{authentication}->{auth_url} ); |
|
77
|
0
|
|
|
|
|
|
$c->log->debug("user: $username"); |
|
78
|
0
|
|
|
|
|
|
$c->log->debug("pass: $password"); |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
81
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( HEAD => $c->config->{authentication}->{auth_url} ); |
|
82
|
0
|
|
|
|
|
|
$req->header( 'Authorization' => $c->req->header('Authorization') ); |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ( $res->code ne '401' ) { |
|
87
|
0
|
|
|
|
|
|
$c->log->debug("Authorization successful."); |
|
88
|
0
|
|
|
|
|
|
$c->req->{user} = $username; |
|
89
|
0
|
|
|
|
|
|
$c->session->{user} = $username; |
|
90
|
0
|
|
|
|
|
|
$c->req->{password} = $password; |
|
91
|
0
|
|
|
|
|
|
$c->session->{password} = $password; |
|
92
|
0
|
|
|
|
|
|
$c->_login(1); |
|
93
|
|
|
|
|
|
|
} else { |
|
94
|
0
|
|
|
|
|
|
$c->log->debug("Authorization failed."); |
|
95
|
0
|
|
|
|
|
|
$c->log->debug("Remote status line: " . $res->status_line); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
unless ( $c->req->{user} ) { |
|
100
|
0
|
|
|
|
|
|
$c->log->debug("return 401 Unauthorized."); |
|
101
|
0
|
|
|
|
|
|
$c->res->status(401); |
|
102
|
0
|
|
|
|
|
|
$c->res->header( 'WWW-Authenticate' => |
|
103
|
0
|
|
0
|
|
|
|
qq!Basic realm="@{[ $c->config->{authentication}->{auth_name} || 'Require Authorization' ]}"! |
|
104
|
|
|
|
|
|
|
); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $c; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item dispatch |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub dispatch { |
|
116
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if ( $c->config->{authentication}->{template} ) { |
|
119
|
0
|
|
0
|
|
|
|
my $view = $c->config->{authentication}->{view_tt} || $c->config->{name}; |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
0
|
0
|
|
|
|
if ($view and $c->res->status eq '401') { |
|
122
|
0
|
|
|
|
|
|
$c->stash->{template} = $c->config->{authentication}->{template}; |
|
123
|
0
|
|
|
|
|
|
$c->forward($view); |
|
124
|
0
|
|
|
|
|
|
return; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return $c->NEXT::dispatch(@_); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item login |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub login { |
|
136
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
return unless $c->session->{user}; |
|
139
|
0
|
0
|
|
|
|
|
return if ($c->_login); |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
if ($c->config->{authentication}->{auth_url}) { |
|
142
|
0
|
|
|
|
|
|
$c->log->debug("Login method called"); |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
delete $c->session->{user} if $c->session->{user}; |
|
145
|
0
|
0
|
|
|
|
|
delete $c->session->{password} if $c->session->{password}; |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$c->res->status(401); |
|
148
|
0
|
|
|
|
|
|
$c->res->header( 'WWW-Authenticate' => |
|
149
|
0
|
|
0
|
|
|
|
qq!Basic realm="@{[ $c->config->{authentication}->{auth_name} || 'Require Authorization' ]}"! |
|
150
|
|
|
|
|
|
|
); |
|
151
|
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return 1; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
return; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item logout |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub logout { |
|
163
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
164
|
|
|
|
|
|
|
|
|
165
|
0
|
0
|
|
|
|
|
return unless $c->config->{authentication}->{auth_url}; |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
0
|
|
|
|
|
delete $c->session->{user} if $c->session->{user}; |
|
168
|
0
|
0
|
|
|
|
|
delete $c->session->{password} if $c->session->{password}; |
|
169
|
|
|
|
|
|
|
|
|
170
|
0
|
0
|
|
|
|
|
delete $c->req->{user} if $c->req->{user}; |
|
171
|
0
|
0
|
|
|
|
|
delete $c->req->{password} if $c->req->{password}; |
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
|
1; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=back |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L<Catalyst> |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 AUTHOR |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Daisuke Murase, E<lt>typester@cpan.orgE<gt> |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Copyright (C) 2005 by Daisuke Murase |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
191
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; |