« blib/lib/Lemonldap/NG/Portal/Main/Init.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Issuer/OpenID.pm »
| 1 | ## @file | ||||||||||||||||||||||||||||
| 2 | # Demo userDB mechanism | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | ## @class | ||||||||||||||||||||||||||||
| 5 | # Demo userDB mechanism class | ||||||||||||||||||||||||||||
| 6 | package Lemonldap::NG::Portal::UserDB::Demo; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 321 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 321 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 321 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | PE_OK | ||||||||||||||||||||||||||||
| 12 | PE_USERNOTFOUND | ||||||||||||||||||||||||||||
| 13 | PE_BADCREDENTIALS | ||||||||||||||||||||||||||||
| 14 | 321 | ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 321 | extends 'Lemonldap::NG::Portal::Main::UserDB'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 321 | our $VERSION = '2.19.0'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Sample accounts from Doctor Who characters | ||||||||||||||||||||||||||||
| 21 | 321 | our %demoAccounts = ( | |||||||||||||||||||||||||||
| 22 | 'dwho' => { | ||||||||||||||||||||||||||||
| 23 | uid => 'dwho', | ||||||||||||||||||||||||||||
| 24 | cn => 'Doctor Who', | ||||||||||||||||||||||||||||
| 25 | mail => 'dwho@badwolf.org', | ||||||||||||||||||||||||||||
| 26 | }, | ||||||||||||||||||||||||||||
| 27 | 'rtyler' => { | ||||||||||||||||||||||||||||
| 28 | uid => 'rtyler', | ||||||||||||||||||||||||||||
| 29 | cn => 'Rose Tyler', | ||||||||||||||||||||||||||||
| 30 | mail => 'rtyler@badwolf.org', | ||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | 'msmith' => { | ||||||||||||||||||||||||||||
| 33 | uid => 'msmith', | ||||||||||||||||||||||||||||
| 34 | cn => 'Mickey Smith', | ||||||||||||||||||||||||||||
| 35 | mail => 'msmith@badwolf.org', | ||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 321 | our %demoGroups = ( | |||||||||||||||||||||||||||
| 40 | 'timelords' => [qw(dwho)], | ||||||||||||||||||||||||||||
| 41 | 'earthlings' => [qw(msmith rtyler)], | ||||||||||||||||||||||||||||
| 42 | 'users' => [qw(dwho msmith rtyler)], | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # INITIALIZATION | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 688 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 688 | return 1; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # RUNNING METHODS | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | ## @apmethod int getUser() | ||||||||||||||||||||||||||||
| 54 | # Check known accounts | ||||||||||||||||||||||||||||
| 55 | # @return Lemonldap::NG::Portal constant | ||||||||||||||||||||||||||||
| 56 | 121 | ▶ | sub getUser { | ||||||||||||||||||||||||||
|
Subroutine
getUser: called CC=4 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 121 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 121 | ▶ | if ( $args{useMail} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($user) = grep { $demoAccounts{$_}->{mail} eq $req->{user} } | |||||||||||||||||||||||||||
| 61 | keys %demoAccounts; | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($user) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | $req->{user} = $user; | |||||||||||||||||||||||||||
| 64 | 0 | return PE_OK; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||
| 68 | return PE_OK | ||||||||||||||||||||||||||||
| 69 | 121 | ▶ | if ( defined $demoAccounts{ $req->user } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | return PE_BADCREDENTIALS; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | ## @apmethod int findUser() | ||||||||||||||||||||||||||||
| 78 | # Search for accounts | ||||||||||||||||||||||||||||
| 79 | # @return Lemonldap::NG::Portal constant | ||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub findUser { | ||||||||||||||||||||||||||
|
Subroutine
findUser: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, $req, %args ) = @_; | |||||||||||||||||||||||||||
| 82 | my $plugin = | ||||||||||||||||||||||||||||
| 83 | 0 | $self->p->loadedModules->{"Lemonldap::NG::Portal::Plugins::FindUser"}; | |||||||||||||||||||||||||||
| 84 | 0 | my ( $searching, $excluding ) = $plugin->retreiveFindUserParams($req); | |||||||||||||||||||||||||||
| 85 | 0 | eval { $self->p->_authentication->setSecurity($req) }; | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | return PE_OK unless scalar @$searching; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my $iswc; | |||||||||||||||||||||||||||
| 89 | 0 | my $cond = ''; | |||||||||||||||||||||||||||
| 90 | 0 | my $wildcard = $self->conf->{findUserWildcard}; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | $self->logger->info("Demo UserDB with wildcard ($wildcard)") if $wildcard; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | foreach (@$searching) { | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($wildcard) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | $iswc = $_->{value} =~ s/\Q$wildcard\E+//g; | |||||||||||||||||||||||||||
| 95 | $cond .= | ||||||||||||||||||||||||||||
| 96 | $iswc | ||||||||||||||||||||||||||||
| 97 | ? '($' . $_->{key} . " =~ /\Q$_->{value}\E/) && " | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | : '$' . $_->{key} . " eq '$_->{value}' && "; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||||||||||
| 101 | 0 | $cond .= '$' . $_->{key} . " eq '$_->{value}' && "; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 0 | $cond .= '$' . $_->{key} . " ne '$_->{value}' && " foreach (@$excluding); | |||||||||||||||||||||||||||
| 105 | 0 | $cond =~ s/&&\s$//; | |||||||||||||||||||||||||||
| 106 | 0 | $self->logger->debug("Demo UserDB built condition: $cond"); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | my @results = map { | ||||||||||||||||||||||||||||
| 109 | 0 | my $uid = $demoAccounts{$_}->{uid}; | |||||||||||||||||||||||||||
| 110 | 0 | my $cn = $demoAccounts{$_}->{cn}; | |||||||||||||||||||||||||||
| 111 | 0 | my $mail = $demoAccounts{$_}->{mail}; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | my $guy = $demoAccounts{$_}->{guy} // 'good'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"guy"} // "good"
MC/DC0%0/1
$Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"guy"} // "good"
$Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"guy"}
Truth table0%0/2
A
A= $Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"guy"}
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $type = $demoAccounts{$_}->{type} // 'character'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"type"} // "character"
MC/DC0%0/1
$Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"type"} // "character"
$Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"type"}
Truth table0%0/2
A
A= $Lemonldap::NG::Portal::UserDB::Demo::demoAccounts{$_}{"type"}
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | eval "($cond)" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | ? $_ | ||||||||||||||||||||||||||||
| 116 | : (); | ||||||||||||||||||||||||||||
| 117 | } keys %demoAccounts; | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | $self->logger->debug( | |||||||||||||||||||||||||||
| 120 | 'Demo UserDB number of result(s): ' . scalar @results ); | ||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( scalar @results ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 0 | my $rank = int( rand( scalar @results ) ); | |||||||||||||||||||||||||||
| 123 | 0 | $self->logger->debug("Demo UserDB random rank: $rank"); | |||||||||||||||||||||||||||
| 124 | 0 | $self->userLogger->info( | |||||||||||||||||||||||||||
| 125 | "FindUser: Demo UserDB returns $results[$rank]"); | ||||||||||||||||||||||||||||
| 126 | 0 | $req->data->{findUser} = $results[$rank]; | |||||||||||||||||||||||||||
| 127 | 0 | $req->data->{findUserAll} = \@results; | |||||||||||||||||||||||||||
| 128 | 0 | return PE_OK; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | return PE_USERNOTFOUND; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | ## @apmethod int setSessionInfo() | ||||||||||||||||||||||||||||
| 135 | # Get sample data | ||||||||||||||||||||||||||||
| 136 | # @return Lemonldap::NG::Portal constant | ||||||||||||||||||||||||||||
| 137 | 116 | ▶ | sub setSessionInfo { | ||||||||||||||||||||||||||
|
Subroutine
setSessionInfo: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 138 | 116 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | my %vars = ( | ||||||||||||||||||||||||||||
| 141 | 116 | %{ $self->conf->{exportedVars} }, | |||||||||||||||||||||||||||
| 142 | 116 | %{ $self->conf->{demoExportedVars} } | |||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||
| 144 | 116 | ▶ | while ( my ( $k, $v ) = each %vars ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 358 | $req->{sessionInfo}->{$k} = $demoAccounts{ $req->{user} }->{$v}; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 116 | return PE_OK; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | ## @apmethod int setGroups() | ||||||||||||||||||||||||||||
| 152 | # Do nothing | ||||||||||||||||||||||||||||
| 153 | # @return Lemonldap::NG::Portal constant | ||||||||||||||||||||||||||||
| 154 | 116 | ▶ | sub setGroups { | ||||||||||||||||||||||||||
|
Subroutine
setGroups: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | 116 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||
| 156 | 116 | my $user = $req->user; | |||||||||||||||||||||||||||
| 157 | 116 | ▶ | my $groups = $req->sessionInfo->{groups} || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$req->sessionInfo->{'groups'} || ''
MC/DC100%1/1
$req->sessionInfo->{'groups'} || ''
$req->sessionInfo->{'groups'}
Truth table100%2/2
A
A= $req->sessionInfo->{'groups'}
| |||||||||||||||||||||||||||||
| 158 | 116 | ▶ | my $hGroups = $req->sessionInfo->{hGroups} || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$req->sessionInfo->{'hGroups'} || {}
MC/DC100%1/1
$req->sessionInfo->{'hGroups'} || {}
$req->sessionInfo->{'hGroups'}
Truth table100%2/2
A
A= $req->sessionInfo->{'hGroups'}
| |||||||||||||||||||||||||||||
| 159 | 116 | for my $grp ( keys %demoGroups ) { | |||||||||||||||||||||||||||
| 160 | 348 | ▶ | if ( grep { $user && $user eq $_ } @{ $demoGroups{$grp} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$user && $user eq $_
MC/DC50%1/2
$user && $user eq $_
$user
$user eq $_
Truth table66%2/3
A && B
A= $userB= $user eq $_
| |||||||||||||||||||||||||||||
| 161 | 232 | $hGroups->{$grp} = { 'name' => $grp }; | |||||||||||||||||||||||||||
| 162 | $groups = | ||||||||||||||||||||||||||||
| 163 | ($groups) | ||||||||||||||||||||||||||||
| 164 | 232 | ▶ | ? $groups . $self->conf->{multiValuesSeparator} . $grp | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | : $grp; | ||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 116 | $req->sessionInfo->{groups} = $groups; | |||||||||||||||||||||||||||
| 169 | 116 | $req->sessionInfo->{hGroups} = $hGroups; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 116 | return PE_OK; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 321 | 1; | |||||||||||||||||||||||||||