| 1 | package Catalyst::Plugin::Authentication; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use MRO::Compat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Catalyst::Authentication::Realm; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | with 'MooseX::Emulate::Class::Accessor::Fast'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | __PACKAGE__->mk_accessors(qw/_user/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | our $VERSION = '0.10029'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 20 | ▶ | sub set_authenticated { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_authenticated: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 20 | my ( $c, $user, $realmname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 20 | $c->user($user); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 20 | $c->request->{user} = $user; # compatibility kludge | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 20 | ▶ | if (!$realmname) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | $realmname = 'default'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 20 | my $realm = $c->get_auth_realm($realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 20 | ▶ | if (!$realm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | Catalyst::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | "set_authenticated called with nonexistant realm: '$realmname'."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 20 | $user->auth_realm($realm->name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 20 | $c->persist_user(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | $c->maybe::next::method($user, $realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 75 | ▶ | sub user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
user: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 75 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 75 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 28 | return $c->_user(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 47 | ▶ | if ( defined($c->_user) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 38 | return $c->_user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 9 | return $c->auth_restore_user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # change this to allow specification of a realm - to verify the user is part of that realm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # in addition to verifying that they exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 20 | ▶ | sub user_exists { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
user_exists: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 20 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | ▶ | return defined($c->_user) || defined($c->find_realm_for_persisted_user); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $c->_user || defined $c->find_realm_for_persisted_user
MC/DC0%0/2
defined $c->_user || defined $c->find_realm_for_persisted_user
defined $c->_user
defined $c->find_realm_for_persisted_user
Truth table33%1/3
A || B
A= defined $c->_userB= defined $c->find_realm_for_persisted_user
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # works like user_exists - except only returns true if user | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # exists AND is in the realm requested. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 11 | ▶ | sub user_in_realm { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
user_in_realm: called CC=3 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 11 | my ($c, $realmname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 11 | ▶ | if (defined($c->_user)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 11 | return ($c->_user->auth_realm eq $realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $realm = $c->find_realm_for_persisted_user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($realm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return ($realm->name eq $realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub __old_save_user_in_session { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__old_save_user_in_session: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my ( $c, $user, $realmname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $c->session->{__user_realm} = $realmname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # we want to ask the store for a user prepared for the session. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # but older modules split this functionality between the user and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # store. We try the store first. If not, we use the old method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $realm = $c->get_auth_realm($realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($realm->{'store'}->can('for_session')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $c->session->{__user} = $realm->{'store'}->for_session($c, $user); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $c->session->{__user} = $user->for_session; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 20 | ▶ | sub persist_user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
persist_user: called CC=5 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 20 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 20 | ▶ | if ($c->user_exists) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ## if we have a valid session handler - we store the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ## realm in the session. If not - we have to hope that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ## the realm can recognize its frozen user somehow. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 20 | ▶ | if ($c->can('session') && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$c->can("session") and $c->config->{"Plugin::Authentication"}{"use_session"} and $c->session_is_valid
$c->can("session") and $c->config->{"Plugin::Authentication"}{"use_session"}
MC/DC0%0/3
$c->can("session") and $c->config->{"Plugin::Authentication"}{"use_session"} and $c->session_is_valid
$c->can("session")
$c->config->{"Plugin::Authentication"}{"use_session"}
$c->session_is_valid
Truth table25%1/4
A and B and C
A= $c->can("session")B= $c->config->{"Plugin::Authentication"}{"use_session"}C= $c->session_is_valid
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | $c->config->{'Plugin::Authentication'}{'use_session'} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | $c->session_is_valid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $c->session->{'__user_realm'} = $c->_user->auth_realm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 20 | my $realm = $c->get_auth_realm($c->_user->auth_realm); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # used to call $realm->save_user_in_session | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 20 | $realm->persist_user($c, $c->user); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ## this was a short lived method to update user information - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | ## you should use persist_user instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub update_user_in_session { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_user_in_session: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return $c->persist_user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | ▶ | sub logout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logout: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | $c->user(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | my $realm = $c->find_realm_for_persisted_user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 8 | ▶ | if ($realm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $realm->remove_persisted_user($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | $c->maybe::next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 7 | ▶ | sub find_user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_user: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 7 | my ( $c, $userinfo, $realmname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 7 | ▶ | $realmname ||= 'default'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$realmname ||= "default"
MC/DC0%0/1
$realmname ||= "default"
$realmname
Truth table50%1/2
A
A= $realmname
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | my $realm = $c->get_auth_realm($realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | ▶ | if (!$realm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | Catalyst::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | "find_user called with nonexistant realm: '$realmname'."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | return $realm->find_user($userinfo, $c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ## Consider making this a public method. - would make certain things easier when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ## dealing with things pre-auth restore. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 17 | ▶ | sub find_realm_for_persisted_user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_realm_for_persisted_user: called CC=9 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 17 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 17 | my $realm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 17 | ▶ | if ($c->can('session') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$c->can("session") and $c->config->{"Plugin::Authentication"}{"use_session"} and $c->session_is_valid and exists $c->session->{"__user_realm"}
$c->can("session") and $c->config->{"Plugin::Authentication"}{"use_session"} and $c->session_is_valid
$c->can("session") and $c->config->{"Plugin::Authentication"}{"use_session"}
MC/DC0%0/4
$c->can("session") and $c->config->{"Plugin::Authentication"}{"use_session"} and $c->session_is_valid and exists $c->session->{"__user_realm"}
$c->can("session")
$c->config->{"Plugin::Authentication"}{"use_session"}
$c->session_is_valid
exists $c->session->{"__user_realm"}
Truth table20%1/5
A and B and C and D
A= $c->can("session")B= $c->config->{"Plugin::Authentication"}{"use_session"}C= $c->session_is_validD= exists $c->session->{"__user_realm"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | and $c->config->{'Plugin::Authentication'}{'use_session'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | and $c->session_is_valid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | and exists($c->session->{'__user_realm'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $realm = $c->auth_realms->{$c->session->{'__user_realm'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if ($realm->user_is_restorable($c)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $realm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | ## we have no choice but to ask each realm whether it has a persisted user. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 17 | foreach my $realmname (@{$c->_auth_realm_restore_order}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 24 | ▶ | my $realm = $c->auth_realms->{$realmname} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$c->auth_realms->{$realmname} || 'Catalyst::Exception'->throw("Could not find authentication realm '${realmname}'")
MC/DC0%0/2
$c->auth_realms->{$realmname} || 'Catalyst::Exception'->throw("Could not find authentication realm '${realmname}'")
$c->auth_realms->{$realmname}
'Catalyst::Exception'->throw("Could not find authentication realm '${realmname}'")
Truth table33%1/3
A || B
A= $c->auth_realms->{$realmname}B= 'Catalyst::Exception'->throw("Could not find authentication realm '${realmname}'")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | || Catalyst::Exception->throw("Could not find authentication realm '$realmname'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 24 | ▶ | return $realm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | if $realm->user_is_restorable($c); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 17 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 9 | ▶ | sub auth_restore_user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auth_restore_user: called CC=4 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 9 | my ( $c, $frozen_user, $realmname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 9 | my $realm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | ▶ | if (defined($realmname)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $realm = $c->get_auth_realm($realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 9 | $realm = $c->find_realm_for_persisted_user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | ▶ | return undef unless $realm; # FIXME die unless? This is an internal inconsistency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $c->_user( my $user = $realm->restore_user( $c, $frozen_user ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # this sets the realm the user originated in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $user->auth_realm($realm->name) if $user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # we can't actually do our setup in setup because the model has not yet been loaded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # So we have to trigger off of setup_finished. :-( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | ▶ | sub setup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | my $app = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | $app->_authentication_initialize(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | $app->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | ## the actual initialization routine. whee. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 133 | ▶ | sub _authentication_initialize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_authentication_initialize: called CC=19 SCAR=34.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 133 | my $app = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ## let's avoid recreating / configuring everything if we have already done it, eh? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 133 | ▶ | if ($app->can('_auth_realms')) { return }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | ## make classdata where it is used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 6 | $app->mk_classdata( '_auth_realms' => {}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ## the order to attempt restore in - If we don't have session - we have | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ## no way to be sure where a frozen user came from - so we have to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ## ask each realm if it can restore the user. Unfortunately it is possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | ## that multiple realms could restore the user from the data we have - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | ## So we have to determine at setup time what order to ask the realms in. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ## The default is to use the user_restore_priority values defined in the realm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | ## config. if they are not defined - we go by alphabetical order. Note that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ## the 'default' realm always gets first chance at it unless it is explicitly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ## placed elsewhere by user_restore_priority. Remember this only comes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | ## into play if session is disabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 6 | $app->mk_classdata( '_auth_realm_restore_order' => []); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | my $cfg = $app->config->{'Plugin::Authentication'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | my $realmshash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | ▶ | if (!defined($cfg)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if (exists($app->config->{'authentication'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $cfg = $app->config->{'authentication'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $app->config->{'Plugin::Authentication'} = $app->config->{'authentication'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $cfg = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | # the realmshash contains the various configured realms. By default this is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # the main $app->config->{'Plugin::Authentication'} hash - but if that is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # not defined, or there is a subkey {'realms'} then we use that. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 6 | $realmshash = $cfg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ## If we have a sub-key of {'realms'} then we use that for realm configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 6 | ▶ | if (exists($cfg->{'realms'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | $realmshash = $cfg->{'realms'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # old default was to force use_session on. This must remain for that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # reason - but if use_session is already in the config, we respect its setting. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 6 | ▶ | if (!exists($cfg->{'use_session'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 6 | $cfg->{'use_session'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ## if we have a realms hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 6 | ▶ | if (ref($realmshash) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | my %auth_restore_order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 6 | my $authcount = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | my $defaultrealm = 'default'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 6 | foreach my $realm (sort keys %{$realmshash}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 14 | ▶ | if (ref($realmshash->{$realm}) eq 'HASH' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
ref $realmshash->{$realm} eq "HASH" and exists $realmshash->{$realm}{"credential"} || exists $realmshash->{$realm}{"class"}
exists $realmshash->{$realm}{"credential"} or exists $realmshash->{$realm}{"class"}
MC/DC100%3/3
ref $realmshash->{$realm} eq "HASH" and exists $realmshash->{$realm}{"credential"} || exists $realmshash->{$realm}{"class"}
ref $realmshash->{$realm} eq "HASH"
exists $realmshash->{$realm}{"credential"}
exists $realmshash->{$realm}{"class"}
Truth table100%4/4
A and B or C
A= ref $realmshash->{$realm} eq "HASH"B= exists $realmshash->{$realm}{"credential"}C= exists $realmshash->{$realm}{"class"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | (exists($realmshash->{$realm}{credential}) || exists($realmshash->{$realm}{class}))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 8 | $app->setup_auth_realm($realm, $realmshash->{$realm}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 8 | ▶ | if (exists($realmshash->{$realm}{'user_restore_priority'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $auth_restore_order{$realm} = $realmshash->{$realm}{'user_restore_priority'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 8 | $auth_restore_order{$realm} = $authcount++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # if we have a 'default_realm' in the config hash and we don't already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # have a realm called 'default', we point default at the realm specified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 6 | ▶ | if (exists($cfg->{'default_realm'}) && !$app->get_auth_realm('default')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $cfg->{"default_realm"} and not $app->get_auth_realm("default")
MC/DC50%1/2
exists $cfg->{"default_realm"} and not $app->get_auth_realm("default")
exists $cfg->{"default_realm"}
not $app->get_auth_realm("default")
Truth table66%2/3
A and not(B)
A= exists $cfg->{"default_realm"}B= not $app->get_auth_realm("default")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 5 | ▶ | if ($app->_set_default_auth_realm($cfg->{'default_realm'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | $defaultrealm = $cfg->{'default_realm'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | $auth_restore_order{'default'} = $auth_restore_order{$cfg->{'default_realm'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 5 | delete($auth_restore_order{$cfg->{'default_realm'}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | ## if the default realm did not have a defined priority in its config - we put it at the front. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 6 | ▶ | if (!exists($realmshash->{$defaultrealm}{'user_restore_priority'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 6 | $auth_restore_order{'default'} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 6 | @{$app->_auth_realm_restore_order} = sort { $auth_restore_order{$a} <=> $auth_restore_order{$b} } keys %auth_restore_order; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | ## BACKWARDS COMPATIBILITY - if realms is not defined - then we are probably dealing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ## with an old-school config. The only caveat here is that we must add a classname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ## also - we have to treat {store} as {stores}{default} - because | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | ## while it is not a clear as a valid config in the docs, it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | ## is functional with the old api. Whee! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if (exists($cfg->{'store'}) && !exists($cfg->{'stores'}{'default'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $cfg->{"store"} and not exists $cfg->{"stores"}{"default"}
MC/DC0%0/2
exists $cfg->{"store"} and not exists $cfg->{"stores"}{"default"}
exists $cfg->{"store"}
not exists $cfg->{"stores"}{"default"}
Truth table0%0/3
A and not(B)
A= exists $cfg->{"store"}B= not exists $cfg->{"stores"}{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $cfg->{'stores'}{'default'} = $cfg->{'store'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | push @{$app->_auth_realm_restore_order}, 'default'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | foreach my $storename (keys %{$cfg->{'stores'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | my $realmcfg = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | store => { class => $cfg->{'stores'}{$storename} }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $app->setup_auth_realm($storename, $realmcfg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # set up realmname. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 9 | ▶ | sub setup_auth_realm { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup_auth_realm: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 9 | my ($app, $realmname, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 9 | my $realmclass = $config->{class}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 9 | ▶ | if( !$realmclass ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 7 | $realmclass = 'Catalyst::Authentication::Realm'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } elsif ($realmclass !~ /^\+(.*)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | $realmclass = "Catalyst::Authentication::Realm::${realmclass}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | $realmclass = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 9 | Catalyst::Utils::ensure_class_loaded( $realmclass ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 9 | my $realm = $realmclass->new($realmname, $config, $app); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 9 | ▶ | if ($realm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 9 | $app->auth_realms->{$realmname} = $realm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $app->log->debug("realm initialization for '$realmname' failed."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 9 | return $realm; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 127 | ▶ | sub auth_realms { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auth_realms: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 127 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 127 | $self->_authentication_initialize(); # Ensure _auth_realms created! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 127 | return($self->_auth_realms); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 79 | ▶ | sub get_auth_realm { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_auth_realm: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 79 | my ($app, $realmname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 79 | return $app->auth_realms->{$realmname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # Very internal method. Vital Valuable Urgent, Do not touch on pain of death. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # Using this method just assigns the default realm to be the value associated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # with the realmname provided. It WILL overwrite any real realm called 'default' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # so can be very confusing if used improperly. It's used properly already. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | # Translation: don't use it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 5 | ▶ | sub _set_default_auth_realm { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_default_auth_realm: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | my ($app, $realmname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 5 | ▶ | if (exists($app->auth_realms->{$realmname})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 5 | $app->auth_realms->{'default'} = $app->auth_realms->{$realmname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | return $app->get_auth_realm('default'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 17 | ▶ | sub authenticate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
authenticate: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 17 | my ($app, $userinfo, $realmname) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 17 | ▶ | if (!$realmname) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 13 | $realmname = 'default'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 17 | my $realm = $app->get_auth_realm($realmname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | ## note to self - make authenticate throw an exception if realm is invalid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 17 | ▶ | if ($realm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 17 | return $realm->authenticate($app, $userinfo); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | Catalyst::Exception->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | "authenticate called with nonexistant realm: '$realmname'."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | ## BACKWARDS COMPATIBILITY -- Warning: Here be monsters! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | # What follows are backwards compatibility routines - for use with Stores and Credentials | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # that have not been updated to work with C::P::Authentication v0.10. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | # These are here so as to not break people's existing installations, but will go away | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # in a future version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # The old style of configuration only supports a single store, as each store module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # sets itself as the default store upon being loaded. This is the only supported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # 'compatibility' mode. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 7 | ▶ | sub get_user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_user: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 7 | my ( $c, $uid, @rest ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 7 | return $c->find_user( {'id' => $uid, 'rest'=>\@rest }, 'default' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | ## this should only be called when using old-style authentication plugins. IF this gets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ## called in a new-style config - it will OVERWRITE the store of your default realm. Don't do it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | ## also - this is a partial setup - because no credential is instantiated... in other words it ONLY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ## works with old-style auth plugins and C::P::Authentication in compatibility mode. Trying to combine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | ## this with a realm-type config will probably crash your app. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | ▶ | sub default_auth_store { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_auth_store: called CC=5 SCAR=19.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | my $realm = $self->get_auth_realm('default'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | ▶ | if (!$realm) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 1 | $realm = $self->setup_auth_realm('default', { class => 'Compatibility' }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | ▶ | if ( my $new = shift ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | $realm->store($new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | my $storeclass; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | ▶ | if (ref($new)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | $storeclass = ref($new); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $storeclass = $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | # BACKWARDS COMPATIBILITY - if the store class does not define find_user, we define it in terms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # of get_user and add it to the class. this is because the auth routines use find_user, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | # and rely on it being present. (this avoids per-call checks) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | ▶ | if (!$storeclass->can('find_user')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 7 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | *{"${storeclass}::find_user"} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my ($self, $info) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | my @rest = @{$info->{rest}} if exists($info->{rest}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | $self->get_user($info->{id}, @rest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | return $self->get_auth_realm('default')->store; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | ## BACKWARDS COMPATIBILITY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | ## this only ever returns a hash containing 'default' - as that is the only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | ## supported mode of calling this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | sub auth_store_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auth_store_names: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my %hash = ( $self->get_auth_realm('default')->store => 'default' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | sub get_auth_store { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_auth_store: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | if ($name ne 'default') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | Carp::croak "get_auth_store called on non-default realm '$name'. Only default supported in compatibility mode"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $self->default_auth_store(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | sub get_auth_store_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_auth_store_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | my ( $self, $store ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | return 'default'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | # sub auth_stores is only used internally - here for completeness | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | sub auth_stores { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auth_stores: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my %hash = ( 'default' => $self->get_auth_realm('default')->store); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 7 | __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||