| 1 | package Catalyst::Plugin::Authentication::CDBI::Basic; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use NEXT; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | Catalyst::Plugin::Authentication::CDBI::Basic - (DEPRECATED) Basic Authorization with Catalyst | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | use Catalyst qw/Session::FastMmap Authentication::CDBI Authentication::CDBI::Basic/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | __PACKAGE__->config( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | authentication => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # Configure Autentication::CDBI | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | basic => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | realm => 'Require Authorization', # Basic realm | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | no_session => 1, # disable auth caching (optional) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # auto error responsing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # use View::TT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | template => '401.tt', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | view => 'MyApp::V::TT', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # or plain text | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | error_msg => 'Authentication Failed !', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | =head1 DEPRECATION NOTICE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | This module has been deprecated. The use of a new Authentication style is recommended. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | See L<Catalyst::Plugin::Authetnication> for detail. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | This plugin privide Basic Authorization mechanism for Catalyst Application. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | This plugin is required C::P::Authentication::CDBI, for users info. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | And also use Session Plugin for authorization caching (optional but recommanded). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =item prepare | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub prepare { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $c = $c->NEXT::prepare(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $auth_header = $c->req->header('Authorization') || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->req->header('Authorization') || ''
MC/DC0%0/1
$c->req->header('Authorization') || ''
$c->req->header('Authorization')
Truth table0%0/2
A
A= $c->req->header('Authorization')
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | $c->log->debug("Authorization: $auth_header") if $auth_header; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($auth_header =~ /^Basic (.+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my ( $username, $password ) = split q{:}, decode_base64($1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $c->log->debug("username: $username"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $c->log->debug("password: $password"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ( $c->can('session_login') and !$c->config->{authentication}->{basic}->{no_session} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | ? $c->session_login($username, $password) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$username and $password
$c->can("session_login") and not $c->config->{"authentication"}{"basic"}{"no_session"}
MC/DC0%0/2
$username and $password
$username
$password
MC/DC0%0/2
$c->can("session_login") and not $c->config->{"authentication"}{"basic"}{"no_session"}
$c->can("session_login")
not $c->config->{"authentication"}{"basic"}{"no_session"}
Truth table0%0/3
A and B
A= $usernameB= $password
Truth table0%0/3
A and not(B)
A= $c->can("session_login")B= not $c->config->{"authentication"}{"basic"}{"no_session"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | : $c->login($username, $password) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | if $username and $password; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | unless ( $c->req->{user} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | $c->res->header('WWW-Authenticate' => q[Basic realm="] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | . ( $c->config->{authentication}->{basic}->{realm} || 'Require Authorization' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$c->config->{'authentication'}{'basic'}{'realm'} || 'Require Authorization'
MC/DC0%0/1
$c->config->{'authentication'}{'basic'}{'realm'} || 'Require Authorization'
$c->config->{'authentication'}{'basic'}{'realm'}
Truth table0%0/2
A
A= $c->config->{'authentication'}{'basic'}{'realm'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | . q["] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( $c->config->{authentication}->{basic}->{error_msg} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$c->config->{"authentication"}{"basic"}{"error_msg"} or $c->config->{"authentication"}{"basic"}{"view"} & $c->config->{"authentication"}{"basic"}{"template"}
MC/DC0%0/2
$c->config->{"authentication"}{"basic"}{"error_msg"} or $c->config->{"authentication"}{"basic"}{"view"} & $c->config->{"authentication"}{"basic"}{"template"}
$c->config->{"authentication"}{"basic"}{"error_msg"}
$c->config->{"authentication"}{"basic"}{"view"} & $c->config->{"authentication"}{"basic"}{"template"}
Truth table0%0/3
A or B
A= $c->config->{"authentication"}{"basic"}{"error_msg"}B= $c->config->{"authentication"}{"basic"}{"view"} & $c->config->{"authentication"}{"basic"}{"template"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | or $c->config->{authentication}->{basic}->{view} & $c->config->{authentication}->{basic}->{template} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $c->res->status(401); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $c->config->{authentication}->{basic}->{error_msg} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $c->res->body( $c->config->{authentication}->{basic}->{error_msg} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $c->stash->{template} = $c->config->{authentication}->{basic}->{template}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $c->forward( $c->config->{authentication}->{basic}->{view} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | Daisuke Murase E<lt>typester@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | The full text of the license can be found in the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | LICENSE file included with this module. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | L<Catalyst::Plugin::Authentication::CDBI> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||