« blib/lib/Lemonldap/NG/Portal/Plugins/History.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Register/LDAP.pm »
| 1 | # Base package for simple issuers plugins | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Issuer should just implement a run() method that will be called only for | ||||||||||||||||||||||||||||
| 4 | # authenticated users when PATH_INFO starts with issuerDBXXPath | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # run() should just return a Lemonldap::NG::Portal::Main::Constants value. It | ||||||||||||||||||||||||||||
| 7 | # is called using process() method (Lemonldap::NG::Portal::Main::Process) | ||||||||||||||||||||||||||||
| 8 | package Lemonldap::NG::Portal::Main::Issuer; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 33 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 33 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 33 | ▶ | use IO::String; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 33 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 33 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 33 | ▶ | use Lemonldap::NG::Common::FormEncode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 33 | use Lemonldap::NG::Portal::Main::Constants qw( | |||||||||||||||||||||||||||
| 18 | PE_OK | ||||||||||||||||||||||||||||
| 19 | PE_RENEWSESSION | ||||||||||||||||||||||||||||
| 20 | PE_UPGRADESESSION | ||||||||||||||||||||||||||||
| 21 | PE_ISSUERTIMEOUT | ||||||||||||||||||||||||||||
| 22 | 33 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 33 | extends 'Lemonldap::NG::Portal::Main::Plugin'; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 33 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # PROPERTIES | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 33 | has type => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 31 | 33 | has path => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 32 | 33 | has ipath => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 33 | has _ott => ( | ||||||||||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||
| 36 | default => sub { | ||||||||||||||||||||||||||||
| 37 | 9 | ▶ | my $ott = $_[0]->{p}->loadModule('::Lib::OneTimeToken'); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||
| 38 | my $timeout = $_[0]->{conf}->{issuersTimeout} | ||||||||||||||||||||||||||||
| 39 | 9 | ▶ | // $_[0]->{conf}->{formTimeout}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$_[0]{"conf"}{"issuersTimeout"} // $_[0]{"conf"}{"formTimeout"}
MC/DC0%0/2
$_[0]{"conf"}{"issuersTimeout"} // $_[0]{"conf"}{"formTimeout"}
$_[0]{"conf"}{"issuersTimeout"}
$_[0]{"conf"}{"formTimeout"}
Truth table33%1/3
A // B
A= $_[0]{"conf"}{"issuersTimeout"}B= $_[0]{"conf"}{"formTimeout"}
| |||||||||||||||||||||||||||||
| 40 | 9 | $ott->timeout($timeout); | |||||||||||||||||||||||||||
| 41 | 9 | return $ott; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 33 | ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # INTERFACE | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Only logout is called in normal use. Issuer that inherits from this | ||||||||||||||||||||||||||||
| 48 | # package are called only by their path | ||||||||||||||||||||||||||||
| 49 | 110 | ▶ | sub beforeLogout { 'logout' } | ||||||||||||||||||||||||||
|
Subroutine
beforeLogout: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # INITIALIZATION | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub init { | ||||||||||||||||||||||||||||
| 54 | 110 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 110 | ▶ | if ( $self->conf->{forceGlobalStorageIssuerOTT} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $self->logger->debug( | |||||||||||||||||||||||||||
| 57 | "-> Issuer tokens will be stored into global storage"); | ||||||||||||||||||||||||||||
| 58 | 0 | $self->_ott->cache(undef); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 110 | my $type = ref( $_[0] ); | |||||||||||||||||||||||||||
| 62 | 110 | $type =~ s/.*:://; | |||||||||||||||||||||||||||
| 63 | 110 | $self->type($type); | |||||||||||||||||||||||||||
| 64 | 110 | ▶ | if ( my $path = $self->conf->{"issuerDB${type}Path"} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 110 | $path =~ s/^.*?(\w+).*?$/$1/; | |||||||||||||||||||||||||||
| 66 | 110 | $self->path($path); | |||||||||||||||||||||||||||
| 67 | 110 | $self->addUnauthRoute( | |||||||||||||||||||||||||||
| 68 | $path => { '*' => '_redirect' }, | ||||||||||||||||||||||||||||
| 69 | [ 'GET', 'POST' ] | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | 110 | $self->addAuthRoute( | |||||||||||||||||||||||||||
| 72 | $path => { '*' => "_forAuthUser" }, | ||||||||||||||||||||||||||||
| 73 | [ 'GET', 'POST' ] | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||
| 77 | 0 | $self->logger->debug("No path declared for issuer $type. Skipping"); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 110 | $self->ipath( 'issuerRequest' . $self->path ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # RUNNING METHODS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # Case 1: Unauthentified users are redirected to the main portal | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub _redirect { | ||||||||||||||||||||||||||||
| 87 | 19 | ▶ | my ( $self, $req, @path ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_redirect: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||
| 88 | 19 | ▶ | if ( $req->pdata->{issuerTs} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$req->pdata->{"issuerTs"} and $req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
MC/DC0%0/2
$req->pdata->{"issuerTs"} and $req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
$req->pdata->{"issuerTs"}
$req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
Truth table66%2/3
A and B
A= $req->pdata->{"issuerTs"}B= $req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
| |||||||||||||||||||||||||||||
| 89 | and $req->pdata->{issuerTs} + $self->conf->{issuersTimeout} < time ) | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 0 | $self->cleanAllPdata($req); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 19 | my $restore; | |||||||||||||||||||||||||||
| 94 | my $ir; | ||||||||||||||||||||||||||||
| 95 | 19 | ▶ | unless ( $self->can('ssoMatch') and not $self->ssoMatch($req) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->can("ssoMatch") and not $self->ssoMatch($req)
MC/DC0%0/2
$self->can("ssoMatch") and not $self->ssoMatch($req)
$self->can("ssoMatch")
not $self->ssoMatch($req)
Truth table66%2/3
A and not(B)
A= $self->can("ssoMatch")B= not $self->ssoMatch($req)
| |||||||||||||||||||||||||||||
| 96 | 19 | $self->logger->debug("Unauth request to $self->{path} issuer"); | |||||||||||||||||||||||||||
| 97 | 19 | $restore = 1; | |||||||||||||||||||||||||||
| 98 | 19 | $self->logger->debug('Processing _redirect'); | |||||||||||||||||||||||||||
| 99 | 19 | ▶ | if ( !$req->param("inProgress") ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 16 | $req->pdata->{ $self->ipath } = $self->storeRequest($req); | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 19 | $self->p->setHiddenFormValue( $req, "inProgress", 1, '', 0 ); | |||||||||||||||||||||||||||
| 103 | 19 | $ir = $req->pdata->{ $self->ipath }; | |||||||||||||||||||||||||||
| 104 | 19 | $req->pdata->{ $self->ipath . 'Path' } = \@path; | |||||||||||||||||||||||||||
| 105 | 19 | $self->logger->debug( | |||||||||||||||||||||||||||
| 106 | 'Add ' . $self->ipath . ', ' . $self->ipath . 'Path in keepPdata' ); | ||||||||||||||||||||||||||||
| 107 | 19 | push @{ $req->pdata->{keepPdata} }, $self->ipath, $self->ipath . 'Path'; | |||||||||||||||||||||||||||
| 108 | 19 | $req->{urldc} = $self->p->buildUrl( $req->portal, $self->path ); | |||||||||||||||||||||||||||
| 109 | 19 | $req->pdata->{_url} = encode_base64( $req->urldc, '' ); | |||||||||||||||||||||||||||
| 110 | 19 | $req->pdata->{issuerTs} = time; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | else { | ||||||||||||||||||||||||||||
| 113 | 0 | $self->logger->debug('Not seen as Issuer request, skipping'); | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # TODO: launch normal process with 'run' at the end | ||||||||||||||||||||||||||||
| 117 | return $self->p->do( | ||||||||||||||||||||||||||||
| 118 | $req, | ||||||||||||||||||||||||||||
| 119 | [ | ||||||||||||||||||||||||||||
| 120 | 'controlUrl', | ||||||||||||||||||||||||||||
| 121 | 19 | @{ $self->p->beforeAuth }, | |||||||||||||||||||||||||||
| 122 | $self->p->authProcess, | ||||||||||||||||||||||||||||
| 123 | 19 | @{ $self->p->betweenAuthAndData }, | |||||||||||||||||||||||||||
| 124 | $self->p->sessionData, | ||||||||||||||||||||||||||||
| 125 | 19 | @{ $self->p->afterData }, | |||||||||||||||||||||||||||
| 126 | $self->p->validSession, | ||||||||||||||||||||||||||||
| 127 | 19 | ▶ | @{ $self->p->endAuth }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | ( | ||||||||||||||||||||||||||||
| 129 | $restore | ||||||||||||||||||||||||||||
| 130 | ? ( | ||||||||||||||||||||||||||||
| 131 | # Restore urldc if auth doesn't need to dial with browser | ||||||||||||||||||||||||||||
| 132 | [ ref($self) . "::resumeProcess", $ir, @path ], | ||||||||||||||||||||||||||||
| 133 | ) | ||||||||||||||||||||||||||||
| 134 | : () | ||||||||||||||||||||||||||||
| 135 | ) | ||||||||||||||||||||||||||||
| 136 | ] | ||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | sub resumeProcess { | ||||||||||||||||||||||||||||
| 141 | 6 | ▶ | my ( $self, $req, $ir, @path ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
resumeProcess: called CC=2 SCAR=7.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 6 | $self->p->clearHiddenFormValue( $req, ['inProgress'] ); | |||||||||||||||||||||||||||
| 144 | 6 | $self->cleanPdata($req); | |||||||||||||||||||||||||||
| 145 | 6 | ▶ | if ($ir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 6 | $self->restoreRequest( $req, $ir ); | |||||||||||||||||||||||||||
| 147 | 6 | return $self->run( $req, @path ); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||
| 150 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 151 | "Could not restore issuer context, redirecting to portal"); | ||||||||||||||||||||||||||||
| 152 | 0 | $req->menuError(PE_ISSUERTIMEOUT); | |||||||||||||||||||||||||||
| 153 | 0 | return PE_ISSUERTIMEOUT; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | # Case 3: authentified user, launch | ||||||||||||||||||||||||||||
| 158 | sub _forAuthUser { | ||||||||||||||||||||||||||||
| 159 | 46 | ▶ | my ( $self, $req, @path ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_forAuthUser: called CC=9 SCAR=31.0
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 46 | my $restore_failed; | |||||||||||||||||||||||||||
| 162 | 46 | ▶ | if ( $req->pdata->{issuerTs} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$req->pdata->{"issuerTs"} and $req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
MC/DC0%0/2
$req->pdata->{"issuerTs"} and $req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
$req->pdata->{"issuerTs"}
$req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
Truth table33%1/3
A and B
A= $req->pdata->{"issuerTs"}B= $req->pdata->{"issuerTs"} + $self->conf->{"issuersTimeout"} < &CORE::GLOBAL::time()
| |||||||||||||||||||||||||||||
| 163 | and $req->pdata->{issuerTs} + $self->conf->{issuersTimeout} < time ) | ||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | 0 | $restore_failed = 1; | |||||||||||||||||||||||||||
| 166 | 0 | $self->cleanAllPdata($req); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 46 | $self->logger->debug('Processing _forAuthUser'); | |||||||||||||||||||||||||||
| 170 | 46 | ▶ | if ( my $r = $req->pdata->{ $self->ipath } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 0 | $self->logger->debug("Restoring request to $self->{path} issuer"); | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( $self->restoreRequest( $req, $r ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | @path = @{ $req->pdata->{ $self->ipath . 'Path' } } | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ( $req->pdata->{ $self->ipath . 'Path' } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # In case a confirm form is shown, we need it to POST on the | ||||||||||||||||||||||||||||
| 177 | # current Path | ||||||||||||||||||||||||||||
| 178 | 0 | $req->data->{confirmFormAction} = URI->new( $req->uri )->path; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||
| 181 | 0 | $restore_failed = 1; | |||||||||||||||||||||||||||
| 182 | 0 | $self->cleanAllPdata($req); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 46 | ▶ | if ( $restore_failed and !@path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$restore_failed and not @path
MC/DC0%0/2
$restore_failed and not @path
$restore_failed
not @path
Truth table33%1/3
A and not(B)
A= $restore_failedB= not @path
| |||||||||||||||||||||||||||||
| 187 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 188 | "Could not restore issuer context, redirecting to portal"); | ||||||||||||||||||||||||||||
| 189 | 0 | $req->menuError(PE_ISSUERTIMEOUT); | |||||||||||||||||||||||||||
| 190 | 0 | return $self->p->doPE( $req, PE_ISSUERTIMEOUT ); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # Clean pdata: keepPdata has been set, so pdata must be cleaned here | ||||||||||||||||||||||||||||
| 194 | 46 | $self->logger->debug('Cleaning pdata'); | |||||||||||||||||||||||||||
| 195 | 46 | $self->cleanPdata($req); | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 46 | ▶ | $req->maybeNotBase64(1) if ( ref($self) =~ /::CAS$/ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 46 | $req->mustRedirect(1); | |||||||||||||||||||||||||||
| 199 | return $self->p->do( | ||||||||||||||||||||||||||||
| 200 | $req, | ||||||||||||||||||||||||||||
| 201 | [ | ||||||||||||||||||||||||||||
| 202 | 'importHandlerData', 'controlUrl', | ||||||||||||||||||||||||||||
| 203 | 46 | @{ $self->p->forAuthUser }, [ ref($self) . "::run", @path ], | |||||||||||||||||||||||||||
| 204 | ] | ||||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | sub cleanAllPdata { | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my ( $self, $req ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
cleanAllPdata: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 210 | 0 | foreach my $k ( keys %{ $req->pdata } ) { | |||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ( exists $req->pdata->{ $k . 'Path' } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | $self->cleanPdata( $req, $k ); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | sub cleanPdata { | ||||||||||||||||||||||||||||
| 218 | 52 | ▶ | my ( $self, $req, $path ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
cleanPdata: called CC=10 SCAR=23.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 219 | 52 | ▶ | $path ||= $self->ipath; | ||||||||||||||||||||||||||
|
Condition33%1/3
$path ||= $self->ipath
MC/DC0%0/2
$path ||= $self->ipath
$path
$self->ipath
Truth table33%1/3
A ||= B
A= $pathB= $self->ipath
| |||||||||||||||||||||||||||||
| 220 | 52 | for my $s ( $path, $path . 'Path' ) { | |||||||||||||||||||||||||||
| 221 | 104 | ▶ | if ( $req->pdata->{$s} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 12 | $self->logger->debug("Removing $s key from pdata"); | |||||||||||||||||||||||||||
| 223 | 12 | delete $req->pdata->{$s}; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | 52 | ▶ | if ( $req->pdata->{keepPdata} and ref $req->pdata->{keepPdata} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$req->pdata->{"keepPdata"} and ref $req->pdata->{"keepPdata"}
MC/DC50%1/2
$req->pdata->{"keepPdata"} and ref $req->pdata->{"keepPdata"}
$req->pdata->{"keepPdata"}
ref $req->pdata->{"keepPdata"}
Truth table66%2/3
A and B
A= $req->pdata->{"keepPdata"}B= ref $req->pdata->{"keepPdata"}
| |||||||||||||||||||||||||||||
| 227 | 6 | @{ $req->pdata->{keepPdata} } = | |||||||||||||||||||||||||||
| 228 | grep { | ||||||||||||||||||||||||||||
| 229 | 18 | ▶ | $_ ne $path | ||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$self->logger->debug("Removing $_ from keepPdata") and 0
MC/DC0%0/1
$self->logger->debug("Removing $_ from keepPdata") and 0
$self->logger->debug("Removing $_ from keepPdata")
Truth table50%1/2
A
A= $self->logger->debug("Removing $_ from keepPdata")
| |||||||||||||||||||||||||||||
| 230 | and $_ ne $path . 'Path' | ||||||||||||||||||||||||||||
| 231 | ? 1 | ||||||||||||||||||||||||||||
| 232 | : ( $self->logger->debug("Removing $_ from keepPdata") and 0 ) | ||||||||||||||||||||||||||||
| 233 | 6 | } @{ $req->pdata->{keepPdata} }; | |||||||||||||||||||||||||||
| 234 | delete $req->pdata->{keepPdata} | ||||||||||||||||||||||||||||
| 235 | 6 | ▶ | unless ( @{ $req->pdata->{keepPdata} } ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | sub storeRequest { | ||||||||||||||||||||||||||||
| 240 | 16 | ▶ | my ( $self, $req ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
storeRequest: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 241 | 16 | my $info = {}; | |||||||||||||||||||||||||||
| 242 | 16 | $info->{content} = $req->content; | |||||||||||||||||||||||||||
| 243 | 16 | foreach ( keys %{ $req->env } ) { | |||||||||||||||||||||||||||
| 244 | 322 | ▶ | next if $_ eq "psgi.errors"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | 322 | ▶ | next if $_ eq "psgi.input"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | 319 | ▶ | $info->{$_} = $req->env->{$_} unless ( ref $req->env->{$_} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | 16 | my $token = $self->_ott->createToken($info); | |||||||||||||||||||||||||||
| 249 | 16 | $self->logger->debug("Store issuer request as $token"); | |||||||||||||||||||||||||||
| 250 | 16 | return $token; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | sub restoreRequest { | ||||||||||||||||||||||||||||
| 254 | 6 | ▶ | my ( $self, $req, $token ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
restoreRequest: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 255 | 6 | $self->logger->debug("Restore issuer request from $token"); | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 6 | my $result = 0; | |||||||||||||||||||||||||||
| 258 | 6 | my $env = $self->_ott->getToken($token); | |||||||||||||||||||||||||||
| 259 | 6 | ▶ | if ($env) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 6 | $result = 1; | |||||||||||||||||||||||||||
| 261 | 6 | $self->logger->debug("Restoring request from $token"); | |||||||||||||||||||||||||||
| 262 | 6 | ▶ | if ( my $c = delete $env->{content} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 3 | $env->{'psgix.input.buffered'} = 0; | |||||||||||||||||||||||||||
| 264 | 3 | $env->{'psgi.input'} = IO::String->new($c); | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | 6 | $req->{env} = {}; | |||||||||||||||||||||||||||
| 267 | 6 | foreach ( keys %$env ) { | |||||||||||||||||||||||||||
| 268 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 269 | 123 | ▶ | "Restore $_" . ( ref $env->{$_} ? '' : "\t" . $env->{$_} ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 123 | ▶ | $req->env->{$_} = $env->{$_} unless /^plack/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | 6 | $req->{uri} = uri_unescape( $req->env->{REQUEST_URI} ); | |||||||||||||||||||||||||||
| 274 | 6 | $req->{uri} =~ s|^//+|/|g; | |||||||||||||||||||||||||||
| 275 | 6 | return $result; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | sub reAuth { | ||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my ( $self, $req ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
reAuth: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 280 | 0 | my $cacheTag = $self->p->cacheTag; | |||||||||||||||||||||||||||
| 281 | $req->data->{customScript} = | ||||||||||||||||||||||||||||
| 282 | qq'<script type="text/javascript" src="$self->{p}->{staticPrefix}/common/js/autoRenew.min.js?v=$cacheTag"></script>' | ||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if ( $self->conf->{skipRenewConfirmation} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 0 | my $portal_without_slash = $req->portal =~ s/\/+$//r; | |||||||||||||||||||||||||||
| 286 | $req->data->{_url} = | ||||||||||||||||||||||||||||
| 287 | 0 | encode_base64( $portal_without_slash . $req->path_info, '' ); | |||||||||||||||||||||||||||
| 288 | 0 | $req->pdata->{ $self->ipath } = $self->storeRequest($req); | |||||||||||||||||||||||||||
| 289 | 0 | push @{ $req->pdata->{keepPdata} }, $self->ipath, $self->ipath . 'Path'; | |||||||||||||||||||||||||||
| 290 | 0 | $req->pdata->{issuerTs} = time; | |||||||||||||||||||||||||||
| 291 | 0 | return PE_RENEWSESSION; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | sub upgradeAuth { | ||||||||||||||||||||||||||||
| 295 | 0 | ▶ | my ( $self, $req ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
upgradeAuth: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 296 | 0 | my $cacheTag = $self->p->cacheTag; | |||||||||||||||||||||||||||
| 297 | $req->data->{customScript} = | ||||||||||||||||||||||||||||
| 298 | qq'<script type="text/javascript" src="$self->{p}->{staticPrefix}/common/js/autoRenew.min.js?v=$cacheTag"></script>' | ||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if ( $self->conf->{skipUpgradeConfirmation} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 0 | my $portal_without_slash = $req->portal =~ s/\/+$//r; | |||||||||||||||||||||||||||
| 301 | $req->data->{_url} = | ||||||||||||||||||||||||||||
| 302 | 0 | encode_base64( $portal_without_slash . $req->path_info, '' ); | |||||||||||||||||||||||||||
| 303 | 0 | $req->pdata->{ $self->ipath } = $self->storeRequest($req); | |||||||||||||||||||||||||||
| 304 | 0 | push @{ $req->pdata->{keepPdata} }, $self->ipath, $self->ipath . 'Path'; | |||||||||||||||||||||||||||
| 305 | 0 | $req->pdata->{issuerTs} = time; | |||||||||||||||||||||||||||
| 306 | 0 | return PE_UPGRADESESSION; | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 33 | 1; | |||||||||||||||||||||||||||
| 310 | __END__ | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =pod | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | =encoding utf8 | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | =head1 NAME | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | Lemonldap::NG::Portal::Main::Issuer - Base class for identity providers. | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | package Lemonldap::NG::Portal::Issuer::My; | ||||||||||||||||||||||||||||
| 323 | use strict; | ||||||||||||||||||||||||||||
| 324 | use Mouse; | ||||||||||||||||||||||||||||
| 325 | extends 'Lemonldap::NG::Portal::Main::Issuer'; | ||||||||||||||||||||||||||||
| 326 | use Lemonldap::NG::Portal::Main::Constants qw(PE_OK); | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | # Required: URL root path | ||||||||||||||||||||||||||||
| 329 | use constant path => 'saml'; | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | # Optional initialization method | ||||||||||||||||||||||||||||
| 332 | sub init { | ||||||||||||||||||||||||||||
| 333 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 334 | ... | ||||||||||||||||||||||||||||
| 335 | # Must return 1 (succeed) or 0 (failure) | ||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # Required methods are run() and logout(), they are launched only for | ||||||||||||||||||||||||||||
| 339 | # authenticated users | ||||||||||||||||||||||||||||
| 340 | # $req is a Lemonldap::NG::Portal::Main::Request object | ||||||||||||||||||||||||||||
| 341 | # They must return a Lemonldap::NG::Portal::Main::Constants constant | ||||||||||||||||||||||||||||
| 342 | sub run { | ||||||||||||||||||||||||||||
| 343 | my ( $self, $req ) = @_ | ||||||||||||||||||||||||||||
| 344 | ... | ||||||||||||||||||||||||||||
| 345 | return PE_OK | ||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | sub logout { | ||||||||||||||||||||||||||||
| 349 | my ( $self, $req ) = @_ | ||||||||||||||||||||||||||||
| 350 | ... | ||||||||||||||||||||||||||||
| 351 | return PE_OK | ||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | 1; | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | Lemonldap::NG::Portal::Main::Issuer is a base class to write identity providers | ||||||||||||||||||||||||||||
| 358 | for Lemonldap::NG web-SSO system. It provide several methods to write easily | ||||||||||||||||||||||||||||
| 359 | an IdP and manage authentication if the identity request comes before | ||||||||||||||||||||||||||||
| 360 | authentication. | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | =head1 WRITING AN IDENTITY PROVIDER | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | To write a classic identity provider, you just have to inherit this class and | ||||||||||||||||||||||||||||
| 365 | write run() and logout() methods. These methods must return a | ||||||||||||||||||||||||||||
| 366 | Lemonldap::NG::Portal::Main::Constants constant. | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | A classic identity provider needs a "issuerDBE<gt>XXXE<lt>Path" parameter in | ||||||||||||||||||||||||||||
| 369 | LLNG configuration to declare its base URI path (see | ||||||||||||||||||||||||||||
| 370 | L<Lemonldap::NG::Manager::Build>). Example: /saml/. All requests that starts | ||||||||||||||||||||||||||||
| 371 | with /saml/ will call run() after authentication if needed, and no one else. | ||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | The logout() function is called when user asks for logout on this server. If | ||||||||||||||||||||||||||||
| 374 | you want to write an identity provider, you must implement a single logout | ||||||||||||||||||||||||||||
| 375 | system. | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | =head2 managing other URI path | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | Lemonldap::NG::Portal::Main::Issuer provides methods to bind a method to an | ||||||||||||||||||||||||||||
| 380 | URI path: | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | =over | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | =item addAuthRoute() for authenticated users | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | =item addUnauthRoute() for unauthenticated users | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | =back | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | They must be called during initialization process (so you must write the | ||||||||||||||||||||||||||||
| 391 | optional init() sub). | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | Be careful with C<add*authRoute()>: you can't catch here your root path (= | ||||||||||||||||||||||||||||
| 394 | path declared in C<$self-E<gt>path>) because it is caught by this module, | ||||||||||||||||||||||||||||
| 395 | but you can catch sub-routes (ie C</path/something>). | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | Example: | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | sub init { | ||||||||||||||||||||||||||||
| 400 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 401 | ... | ||||||||||||||||||||||||||||
| 402 | $self->addUnauthRoute( saml => { soap => 'soapServer' }, [ 'POST' ] ); | ||||||||||||||||||||||||||||
| 403 | return 1; | ||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | sub soapServer { | ||||||||||||||||||||||||||||
| 406 | my ( $self, $req ) = @_; | ||||||||||||||||||||||||||||
| 407 | ... | ||||||||||||||||||||||||||||
| 408 | # You must return a valid PSGI response | ||||||||||||||||||||||||||||
| 409 | return [ 200, [ 'Content-Type' => 'application/xml' ], [] ]; | ||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | =head2 avoid conflicts in path | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | If you share base URI path with another plugin (a C<Auth::*> module for | ||||||||||||||||||||||||||||
| 415 | example), it is recommended to write a C<ssoMatch> function that returns true | ||||||||||||||||||||||||||||
| 416 | if C<$req-E<gt>uri> has to be handled by Issuer module. See C<Issuer::SAML> | ||||||||||||||||||||||||||||
| 417 | or C<Issuer::OpenIDConnect> to have some examples. | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | L<http://lemonldap-ng.org/> | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | =over | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | =item LemonLDAP::NG team L<http://lemonldap-ng.org/team> | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | =back | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | =head1 BUG REPORT | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | Use OW2 system to report bug or ask for features: | ||||||||||||||||||||||||||||
| 434 | L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues> | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | =head1 DOWNLOAD | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | Lemonldap::NG is available at | ||||||||||||||||||||||||||||
| 439 | L<https://lemonldap-ng.org/download> | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | See COPYING file for details. | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 446 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 447 | the Free Software Foundation; either version 2, or (at your option) | ||||||||||||||||||||||||||||
| 448 | any later version. | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 451 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 452 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 453 | GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 456 | along with this program. If not, see L<http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | =cut | ||||||||||||||||||||||||||||