| 1 | package Catalyst::Authentication::Store::DBI::ButMaintained; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Storable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use MooseX::Types::LoadableClass qw/ClassName/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | has 'config' => ( | |||||||||||||||||||||||||||
| 13 | isa => 'HashRef' | ||||||||||||||||||||||||||||
| 14 | , is => 'ro' | ||||||||||||||||||||||||||||
| 15 | , required => 1 | ||||||||||||||||||||||||||||
| 16 | , traits => ['Hash'] | ||||||||||||||||||||||||||||
| 17 | , handles => { | ||||||||||||||||||||||||||||
| 18 | get_config => 'get' | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | has 'store_user_class' => ( | ||||||||||||||||||||||||||||
| 23 | isa => ClassName | ||||||||||||||||||||||||||||
| 24 | , is => 'ro' | ||||||||||||||||||||||||||||
| 25 | , coerce => 1 | ||||||||||||||||||||||||||||
| 26 | , lazy => 1 | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | , default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 28 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | defined $self->get_config('store_user_class') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | ? $self->get_config('store_user_class') | ||||||||||||||||||||||||||||
| 31 | : 'Catalyst::Authentication::Store::DBI::ButMaintained::User' | ||||||||||||||||||||||||||||
| 32 | ; | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 2 | ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # locates a user using data contained in the hashref | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub find_user { | ||||||||||||||||||||||||||
|
Subroutine
find_user: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 0 | my ($self, $authinfo, $c) = @_; | |||||||||||||||||||||||||||
| 39 | 0 | my $dbh = $c->model('DBI')->dbh; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | my @col = sort keys %$authinfo; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | my $abs_user_dest = $self->_safe_escape( | ||||||||||||||||||||||||||||
| 44 | $dbh | ||||||||||||||||||||||||||||
| 45 | 0 | , {map { $_ => $self->get_config("user_$_") } qw/database schema table/} | |||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $sql = "SELECT * FROM $abs_user_dest WHERE " | |||||||||||||||||||||||||||
| 49 | . join( ' AND ', map $dbh->quote_identifier($_) . " = ?", @col ) | ||||||||||||||||||||||||||||
| 50 | ; | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $sth = $dbh->prepare($sql) or die($dbh->errstr()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $sth->execute(@$authinfo{@col}) or die($dbh->errstr()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my %user; | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | $sth->bind_columns(\( @user{ @{ $sth->{'NAME_lc'} } } )) or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | die($dbh->errstr()); | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | unless ($sth->fetch()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | $sth->finish(); | |||||||||||||||||||||||||||
| 60 | 0 | return undef; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 0 | $sth->finish(); | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | ## Fail silently clause | ||||||||||||||||||||||||||||
| 65 | return undef | ||||||||||||||||||||||||||||
| 66 | unless exists $user{$self->get_config('user_key')} | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | && length $user{$self->get_config('user_key')} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $user{$self->get_config("user_key")} and length $user{$self->get_config("user_key")}
MC/DC0%0/2
exists $user{$self->get_config("user_key")} and length $user{$self->get_config("user_key")}
exists $user{$self->get_config("user_key")}
length $user{$self->get_config("user_key")}
Truth table0%0/3
A and B
A= exists $user{$self->get_config("user_key")}B= length $user{$self->get_config("user_key")}
| |||||||||||||||||||||||||||||
| 68 | ; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my $class = $self->store_user_class; | |||||||||||||||||||||||||||
| 71 | 0 | return $class->new({ | |||||||||||||||||||||||||||
| 72 | store => $self | ||||||||||||||||||||||||||||
| 73 | , user => \%user | ||||||||||||||||||||||||||||
| 74 | , authinfo => $authinfo | ||||||||||||||||||||||||||||
| 75 | , dbi_model => $c->model('DBI') | ||||||||||||||||||||||||||||
| 76 | }); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub _safe_escape { | ||||||||||||||||||||||||||
|
Subroutine
_safe_escape: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 81 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 82 | 0 | my ( $dbh, $unescaped ) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | join '.' | ||||||||||||||||||||||||||||
| 85 | , map $dbh->quote_identifier( $unescaped->{$_} ) | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | , grep exists $unescaped->{$_} && defined $unescaped->{$_} | ||||||||||||||||||||||||||
|
Condition0%0/3
exists $unescaped->{$_} && defined $unescaped->{$_}
MC/DC0%0/2
exists $unescaped->{$_} && defined $unescaped->{$_}
exists $unescaped->{$_}
defined $unescaped->{$_}
Truth table0%0/3
A && B
A= exists $unescaped->{$_}B= defined $unescaped->{$_}
| |||||||||||||||||||||||||||||
| 87 | , qw/database schema table column/ | ||||||||||||||||||||||||||||
| 88 | ; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | ## Not sure how for_session would work with ACCEPT_CONTEXT in the Model::DBI | ||||||||||||||||||||||||||||
| 94 | ## If you don't have the same context in the DBI you could presumably get a | ||||||||||||||||||||||||||||
| 95 | ## different user | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub for_session { | ||||||||||||||||||||||||||
|
Subroutine
for_session: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 0 | my ( $c, $user) = @_; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | ## TODO: Freeze whole user, this should just be fallback | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $self->config->{"user_key"} and $user->get($self->get_config("user_key"))
MC/DC0%0/2
exists $self->config->{"user_key"} and $user->get($self->get_config("user_key"))
exists $self->config->{"user_key"}
$user->get($self->get_config("user_key"))
Truth table0%0/3
A and B
A= exists $self->config->{"user_key"}B= $user->get($self->get_config("user_key"))
| |||||||||||||||||||||||||||||
| 102 | exists $self->config->{user_key} | ||||||||||||||||||||||||||||
| 103 | && $user->get( $self->get_config('user_key') ) | ||||||||||||||||||||||||||||
| 104 | ) { | ||||||||||||||||||||||||||||
| 105 | 0 | my $k = $self->get_config('user_key'); | |||||||||||||||||||||||||||
| 106 | 0 | my $uid = $user->get( $k ); | |||||||||||||||||||||||||||
| 107 | 0 | return Storable::nfreeze({ $k => $uid }); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | ## Support users with composite key | ||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||
| 111 | 0 | return Storable::nfreeze( $user->authinfo ); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub from_session { | ||||||||||||||||||||||||||
|
Subroutine
from_session: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 0 | my ( $c, $frozen ) = @_; | |||||||||||||||||||||||||||
| 119 | 0 | $self->find_user( Storable::thaw($frozen), $c ); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub user_supports { | ||||||||||||||||||||||||||
|
Subroutine
user_supports: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 0 | return; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 128 | 0 | my ( $config, $app, $realm ) = @_; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | scalar @_ == 1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | ? $class->SUPER::BUILDARGS(@_) | ||||||||||||||||||||||||||||
| 132 | : { config => $config, app => $app, realm => $realm } | ||||||||||||||||||||||||||||
| 133 | ; | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2 | 1; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | __END__ | ||||||||||||||||||||||||||||