« blib/lib/Lemonldap/NG/Portal/Plugins/SamlFederation.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Password/AD.pm »
| 1 | package Lemonldap::NG::Portal::UserDB::DBI; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 18 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 18 | ▶ | use Mouse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 18 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | PE_OK | ||||||||||||||||||||
| 7 | PE_ERROR | ||||||||||||||||||||
| 8 | PE_USERNOTFOUND | ||||||||||||||||||||
| 9 | PE_BADCREDENTIALS | ||||||||||||||||||||
| 10 | 18 | ); | |||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 18 | extends qw( | |||||||||||||||||||
| 13 | Lemonldap::NG::Portal::Main::UserDB | ||||||||||||||||||||
| 14 | Lemonldap::NG::Portal::Lib::DBI | ||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 18 | our $VERSION = '2.23.0'; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | # PROPERTIES | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | has exportedVars => ( | ||||||||||||||||||||
| 22 | is => 'rw', | ||||||||||||||||||||
| 23 | lazy => 1, | ||||||||||||||||||||
| 24 | 17 | ▶ | builder => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 17 | my $conf = $_[0]->{conf}; | |||||||||||||||||||
| 26 | 17 | return { %{ $conf->{exportedVars} }, %{ $conf->{dbiExportedVars} } }; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | 18 | ); | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | # RUNNING METHODS | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 39 | ▶ | sub getUser { | ||||||||||||||||||
|
Subroutine
getUser: called CC=5 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||
| 33 | 39 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||
| 34 | 39 | my $table = $self->table; | |||||||||||||||||||
| 35 | 39 | ▶ | my $pivot = $args{useMail} ? $self->mailField : $self->pivot; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 39 | my $user = $req->{user}; | |||||||||||||||||||
| 37 | 39 | my $sth; | |||||||||||||||||||
| 38 | 39 | eval { | |||||||||||||||||||
| 39 | 39 | $sth = $self->dbh->prepare("SELECT * FROM $table WHERE $pivot=?"); | |||||||||||||||||||
| 40 | 39 | $sth->execute($user); | |||||||||||||||||||
| 41 | }; | ||||||||||||||||||||
| 42 | 39 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # If connection isn't available, error is displayed by dbh() | ||||||||||||||||||||
| 45 | 0 | ▶ | $self->logger->error("DBI error: $@") if ( $self->_dbh ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||||||||
| 47 | 0 | return PE_ERROR; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | 39 | ▶ | unless ( $req->data->{dbientry} = $sth->fetchrow_hashref() ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 14 | $self->userLogger->warn("User $user not found"); | |||||||||||||||||||
| 51 | 14 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||||||||
| 52 | 14 | return PE_BADCREDENTIALS; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 25 | return PE_OK; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | sub findUser { | ||||||||||||||||||
|
Subroutine
findUser: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||
| 59 | 0 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||
| 60 | my $plugin = | ||||||||||||||||||||
| 61 | 0 | $self->p->loadedModules->{"Lemonldap::NG::Portal::Plugins::FindUser"}; | |||||||||||||||||||
| 62 | 0 | my ( $searching, $excluding ) = $plugin->retreiveFindUserParams($req); | |||||||||||||||||||
| 63 | 0 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||||||||
| 64 | 0 | ▶ | return PE_OK unless scalar @$searching; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | my $table = $self->table; | |||||||||||||||||||
| 67 | 0 | ▶ | my $pivot = $args{useMail} ? $self->mailField : $self->pivot; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | my @args; | |||||||||||||||||||
| 69 | 0 | my $request = "SELECT $pivot FROM $table WHERE "; | |||||||||||||||||||
| 70 | 0 | my ( $iswc, $sth ); | |||||||||||||||||||
| 71 | 0 | my $wildcard = $self->conf->{findUserWildcard}; | |||||||||||||||||||
| 72 | 0 | ▶ | $self->logger->info("DBI UserDB with wildcard ($wildcard)") if $wildcard; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 0 | foreach (@$searching) { | |||||||||||||||||||
| 74 | 0 | ▶ | $iswc = $_->{value} =~ s/\Q$wildcard\E+/%/g if $wildcard; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | 0 | ▶ | $request .= $iswc ? "$_->{key} LIKE ? AND " : "$_->{key} = ? AND "; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | push @args, $_->{value}; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | 0 | foreach (@$excluding) { | |||||||||||||||||||
| 79 | 0 | $request .= "$_->{key} != ? AND "; | |||||||||||||||||||
| 80 | 0 | push @args, $_->{value}; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | 0 | $request =~ s/AND\s$//; | |||||||||||||||||||
| 83 | 0 | $self->logger->debug("DBI UserDB built condition: $request"); | |||||||||||||||||||
| 84 | 0 | $self->logger->debug( "DBI UserDB built args: " . join '|', @args ); | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | eval { | |||||||||||||||||||
| 87 | 0 | $sth = $self->dbh->prepare($request); | |||||||||||||||||||
| 88 | 0 | $sth->execute(@args); | |||||||||||||||||||
| 89 | }; | ||||||||||||||||||||
| 90 | 0 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | # If connection isn't available, error is displayed by dbh() | ||||||||||||||||||||
| 93 | 0 | ▶ | $self->logger->error("DBI error: $@") if ( $self->_dbh ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | return PE_ERROR; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | my $results = $sth->fetchall_arrayref(); | |||||||||||||||||||
| 98 | 0 | ▶ | if ( $results->[0]->[0] ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | 0 | my $rank = int( rand( scalar @$results ) ); | |||||||||||||||||||
| 100 | 0 | $self->logger->debug( | |||||||||||||||||||
| 101 | 'DBI UserDB number of result(s): ' . scalar @$results ); | ||||||||||||||||||||
| 102 | 0 | $self->logger->debug("Demo UserDB random rank: $rank"); | |||||||||||||||||||
| 103 | 0 | $self->userLogger->info( | |||||||||||||||||||
| 104 | "FindUser: DBI UserDB returns $results->[$rank]->[0]"); | ||||||||||||||||||||
| 105 | 0 | $req->data->{findUser} = $results->[$rank]->[0]; | |||||||||||||||||||
| 106 | 0 | $req->data->{findUserAll} = map { $_->[0] } @$results; | |||||||||||||||||||
| 107 | 0 | return PE_OK; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | return PE_USERNOTFOUND; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 24 | ▶ | sub setSessionInfo { | ||||||||||||||||||
|
Subroutine
setSessionInfo: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||
| 114 | 24 | my ( $self, $req ) = @_; | |||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | # Set _user unless already defined | ||||||||||||||||||||
| 117 | 24 | ▶ | $req->{sessionInfo}->{_user} ||= $req->user; | ||||||||||||||||||
|
Condition33%1/3
$req->{"sessionInfo"}{"_user"} ||= $req->user
MC/DC0%0/2
$req->{"sessionInfo"}{"_user"} ||= $req->user
$req->{"sessionInfo"}{"_user"}
$req->user
Truth table33%1/3
A ||= B
A= $req->{"sessionInfo"}{"_user"}B= $req->user
| |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 24 | foreach my $var ( keys %{ $self->exportedVars } ) { | |||||||||||||||||||
| 120 | 87 | my $attr = $self->exportedVars->{$var}; | |||||||||||||||||||
| 121 | 87 | ▶ | if ( defined( my $value = $req->data->{dbientry}->{$attr} ) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | # Drop Unicode flag if DBD set it | ||||||||||||||||||||
| 124 | 15 | ▶ | utf8::encode($value) if utf8::is_utf8($value); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | 15 | $req->{sessionInfo}->{$var} = $value; | |||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | 24 | return PE_OK; | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 18 | 1; | |||||||||||||||||||