« 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 | 315 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 315 | ▶ | use Mouse; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 315 | use Lemonldap::NG::Portal::Main::Constants qw( | |||||||||||||
| 11 | PE_OK | ||||||||||||||
| 12 | PE_USERNOTFOUND | ||||||||||||||
| 13 | PE_BADCREDENTIALS | ||||||||||||||
| 14 | 315 | ▶ | ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 315 | extends 'Lemonldap::NG::Portal::Main::UserDB'; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 315 | our $VERSION = '2.19.0'; | |||||||||||||
| 19 | |||||||||||||||
| 20 | # Sample accounts from Doctor Who characters | ||||||||||||||
| 21 | 315 | 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 | 315 | our %demoGroups = ( | |||||||||||||
| 40 | 'timelords' => [qw(dwho)], | ||||||||||||||
| 41 | 'earthlings' => [qw(msmith rtyler)], | ||||||||||||||
| 42 | 'users' => [qw(dwho msmith rtyler)], | ||||||||||||||
| 43 | ); | ||||||||||||||
| 44 | |||||||||||||||
| 45 | # INITIALIZATION | ||||||||||||||
| 46 | |||||||||||||||
| 47 | sub init { | ||||||||||||||
| 48 | 681 | ▶ | return 1; | ||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | # RUNNING METHODS | ||||||||||||||
| 52 | |||||||||||||||
| 53 | ## @apmethod int getUser() | ||||||||||||||
| 54 | # Check known accounts | ||||||||||||||
| 55 | # @return Lemonldap::NG::Portal constant | ||||||||||||||
| 56 | sub getUser { | ||||||||||||||
| 57 | 119 | ▶ | my ( $self, $req, %args ) = @_; | ||||||||||||
|
Subroutine
getUser: called CC=4 SCAR=17.3
Pod
undocumented
| |||||||||||||||
| 58 | |||||||||||||||
| 59 | 119 | ▶ | 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 | 119 | ▶ | 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 | sub findUser { | ||||||||||||||
| 81 | 0 | ▶ | my ( $self, $req, %args ) = @_; | ||||||||||||
|
Subroutine
findUser: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||
| 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 | sub setSessionInfo { | ||||||||||||||
| 138 | 114 | ▶ | my ( $self, $req ) = @_; | ||||||||||||
|
Subroutine
setSessionInfo: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 139 | |||||||||||||||
| 140 | my %vars = ( | ||||||||||||||
| 141 | 114 | %{ $self->conf->{exportedVars} }, | |||||||||||||
| 142 | 114 | %{ $self->conf->{demoExportedVars} } | |||||||||||||
| 143 | ); | ||||||||||||||
| 144 | 114 | ▶ | while ( my ( $k, $v ) = each %vars ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 145 | 352 | $req->{sessionInfo}->{$k} = $demoAccounts{ $req->{user} }->{$v}; | |||||||||||||
| 146 | } | ||||||||||||||
| 147 | |||||||||||||||
| 148 | 114 | return PE_OK; | |||||||||||||
| 149 | } | ||||||||||||||
| 150 | |||||||||||||||
| 151 | ## @apmethod int setGroups() | ||||||||||||||
| 152 | # Do nothing | ||||||||||||||
| 153 | # @return Lemonldap::NG::Portal constant | ||||||||||||||
| 154 | sub setGroups { | ||||||||||||||
| 155 | 114 | ▶ | my ( $self, $req ) = @_; | ||||||||||||
|
Subroutine
setGroups: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||
| 156 | 114 | my $user = $req->user; | |||||||||||||
| 157 | 114 | ▶ | 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 | 114 | ▶ | 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 | 114 | for my $grp ( keys %demoGroups ) { | |||||||||||||
| 160 | 342 | ▶ | if ( grep { $user && $user eq $_ } @{ $demoGroups{$grp} } ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 161 | 228 | $hGroups->{$grp} = { 'name' => $grp }; | |||||||||||||
| 162 | $groups = | ||||||||||||||
| 163 | ($groups) | ||||||||||||||
| 164 | 228 | ▶ | ? $groups . $self->conf->{multiValuesSeparator} . $grp | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 165 | : $grp; | ||||||||||||||
| 166 | } | ||||||||||||||
| 167 | } | ||||||||||||||
| 168 | 114 | $req->sessionInfo->{groups} = $groups; | |||||||||||||
| 169 | 114 | $req->sessionInfo->{hGroups} = $hGroups; | |||||||||||||
| 170 | |||||||||||||||
| 171 | 114 | return PE_OK; | |||||||||||||
| 172 | } | ||||||||||||||
| 173 | |||||||||||||||
| 174 | 315 | 1; | |||||||||||||