« blib/lib/Lemonldap/NG/Portal/Plugins/CDA.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/AutoSignin.pm »
| 1 | package Lemonldap::NG::Portal::Main::Request; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Developpers, be careful: new() is never called so default values will not be | ||||||||||||||||||||||||||||
| 4 | # taken in account (see Portal::Run::handler()): set default values in init() | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 454 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 454 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 454 | ▶ | use Lemonldap::NG::Portal::Main::Constants ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 454 | our $VERSION = '2.19.0'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 454 | extends 'Lemonldap::NG::Common::PSGI::Request'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # List of methods to call | ||||||||||||||||||||||||||||
| 15 | 454 | has steps => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # Authentication result | ||||||||||||||||||||||||||||
| 18 | 454 | has authResult => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Session data when created | ||||||||||||||||||||||||||||
| 21 | 454 | has id => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 22 | 454 | has sessionInfo => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 23 | 454 | has user => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # Persistent data (stored in cookie during auth, erased when auth is ready) | ||||||||||||||||||||||||||||
| 26 | 454 | has pdata => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Response cookies (list of strings built by cookie()) | ||||||||||||||||||||||||||||
| 29 | 454 | has respCookies => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # Embedded response | ||||||||||||||||||||||||||||
| 32 | 454 | has response => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Template to display (if not defined, login or menu) | ||||||||||||||||||||||||||||
| 35 | 454 | has template => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # Custom template parameters | ||||||||||||||||||||||||||||
| 38 | 454 | has customParameters => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Boolean to indicate that response must be a redirection | ||||||||||||||||||||||||||||
| 41 | 454 | has mustRedirect => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Boolean to indicate that login form must not be displayed (used to reset | ||||||||||||||||||||||||||||
| 44 | # authentication) | ||||||||||||||||||||||||||||
| 45 | 454 | has noLoginDisplay => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Portal URL, can be dynamic | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 454 | has portal => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Store URL for redirections | ||||||||||||||||||||||||||||
| 52 | 454 | has urldc => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 53 | 454 | has postUrl => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 54 | 454 | has postFields => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 55 | 454 | has portalHiddenFormValues => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Flag that permit to a auth module to return PE_OK without setting $user | ||||||||||||||||||||||||||||
| 58 | 454 | has continue => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # "check logins "flag" | ||||||||||||||||||||||||||||
| 61 | 454 | has checkLogins => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # Boolean to indicate that url isn't Base64 encoded | ||||||||||||||||||||||||||||
| 64 | 454 | has urlNotBase64 => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 65 | 454 | has maybeNotBase64 => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Menu error | ||||||||||||||||||||||||||||
| 68 | 454 | has menuError => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Frame flag (used by Run to not send Content-Security-Policy header) | ||||||||||||||||||||||||||||
| 71 | 454 | has frame => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Refresh flag to avoid double cookies sessions to be renewed | ||||||||||||||||||||||||||||
| 74 | 454 | has refresh => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # Scalar to display lock time | ||||||||||||||||||||||||||||
| 77 | 454 | has lockTime => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Security | ||||||||||||||||||||||||||||
| 80 | # | ||||||||||||||||||||||||||||
| 81 | # Captcha HTML code to display in forms | ||||||||||||||||||||||||||||
| 82 | 454 | has captchaHtml => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # DEPRECATED: 2.0 captcha compatibility | ||||||||||||||||||||||||||||
| 85 | 454 | has captcha => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # Token | ||||||||||||||||||||||||||||
| 88 | 454 | has token => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # Whether or not to include a HTML render of the error message | ||||||||||||||||||||||||||||
| 91 | # in error responses | ||||||||||||||||||||||||||||
| 92 | 454 | has wantErrorRender => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # Error type | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 397 | ▶ | sub error_role { | ||||||||||||||||||||||||||
|
Subroutine
error_role: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | 397 | my $req = shift; | |||||||||||||||||||||||||||
| 98 | 397 | ▶ | return $req->error_type(@_) eq 'negative' ? 'alert' : 'status'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 797 | ▶ | sub error_type { | ||||||||||||||||||||||||||
|
Subroutine
error_type: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 797 | my $req = shift; | |||||||||||||||||||||||||||
| 103 | 797 | ▶ | my $code = shift || $req->error; | ||||||||||||||||||||||||||
|
Condition100%3/3
shift() || $req->error
MC/DC100%2/2
shift() || $req->error
shift()
$req->error
Truth table100%3/3
A || B
A= shift()B= $req->error
| |||||||||||||||||||||||||||||
| 104 | 797 | $req->error($code); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # Positive errors | ||||||||||||||||||||||||||||
| 107 | return "positive" | ||||||||||||||||||||||||||||
| 108 | if ( | ||||||||||||||||||||||||||||
| 109 | scalar( | ||||||||||||||||||||||||||||
| 110 | 797 | ▶ | grep { /^$code$/ } ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | PE_REDIRECT, PE_DONE, | ||||||||||||||||||||||||||||
| 112 | PE_OK, PE_PASSWORD_OK, | ||||||||||||||||||||||||||||
| 113 | PE_MAILOK, PE_LOGOUT_OK, | ||||||||||||||||||||||||||||
| 114 | PE_MAILFIRSTACCESS, PE_PASSWORDFIRSTACCESS, | ||||||||||||||||||||||||||||
| 115 | PE_MAILCONFIRMOK, PE_REGISTERFIRSTACCESS, | ||||||||||||||||||||||||||||
| 116 | PE_RESETCERTIFICATE_FIRSTACCESS, | ||||||||||||||||||||||||||||
| 117 | ) | ||||||||||||||||||||||||||||
| 118 | ) | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # Warning errors | ||||||||||||||||||||||||||||
| 122 | return "warning" | ||||||||||||||||||||||||||||
| 123 | if ( | ||||||||||||||||||||||||||||
| 124 | scalar( | ||||||||||||||||||||||||||||
| 125 | 630 | ▶ | grep { /^$code$/ } ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | PE_INFO, | ||||||||||||||||||||||||||||
| 127 | PE_SESSIONEXPIRED, | ||||||||||||||||||||||||||||
| 128 | PE_FORMEMPTY, | ||||||||||||||||||||||||||||
| 129 | PE_FIRSTACCESS, | ||||||||||||||||||||||||||||
| 130 | PE_PP_GRACE, | ||||||||||||||||||||||||||||
| 131 | PE_PP_EXP_WARNING, | ||||||||||||||||||||||||||||
| 132 | PE_NOTIFICATION, | ||||||||||||||||||||||||||||
| 133 | PE_BADURL, | ||||||||||||||||||||||||||||
| 134 | PE_CONFIRM, | ||||||||||||||||||||||||||||
| 135 | PE_MAILFORMEMPTY, | ||||||||||||||||||||||||||||
| 136 | PE_MAILCONFIRMATION_ALREADY_SENT, | ||||||||||||||||||||||||||||
| 137 | PE_PASSWORDFORMEMPTY, | ||||||||||||||||||||||||||||
| 138 | PE_CAPTCHAEMPTY, | ||||||||||||||||||||||||||||
| 139 | PE_REGISTERFORMEMPTY, | ||||||||||||||||||||||||||||
| 140 | PE_PP_CHANGE_AFTER_RESET, | ||||||||||||||||||||||||||||
| 141 | PE_RESETCERTIFICATE_FORMEMPTY, | ||||||||||||||||||||||||||||
| 142 | PE_RETRY_2FA, | ||||||||||||||||||||||||||||
| 143 | ) | ||||||||||||||||||||||||||||
| 144 | ) | ||||||||||||||||||||||||||||
| 145 | ); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # Negative errors (default) | ||||||||||||||||||||||||||||
| 148 | 537 | return "negative"; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | #TODO | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 3197 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 154 | 3197 | my ( $self, $conf ) = @_; | |||||||||||||||||||||||||||
| 155 | 3197 | $self->{$_} = {} foreach (qw(data customParameters sessionInfo pdata)); | |||||||||||||||||||||||||||
| 156 | 3197 | $self->{$_} = [] foreach (qw(respCookies)); | |||||||||||||||||||||||||||
| 157 | 3197 | ▶ | if ( $conf->{whatToTrace} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$conf->{"whatToTrace"} and my $tmp = $self->userData->{$conf->{"whatToTrace"}}
MC/DC100%2/2
$conf->{"whatToTrace"} and my $tmp = $self->userData->{$conf->{"whatToTrace"}}
$conf->{"whatToTrace"}
my $tmp = $self->userData->{$conf->{"whatToTrace"}}
Truth table100%3/3
A and B
A= $conf->{"whatToTrace"}B= my $tmp = $self->userData->{$conf->{"whatToTrace"}}
| |||||||||||||||||||||||||||||
| 158 | and my $tmp = $self->userData->{ $conf->{whatToTrace} } ) | ||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | 118 | $self->user($tmp); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub errorString { | ||||||||||||||||||||||||||
|
Subroutine
errorString: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 165 | 0 | print STDERR "TODO Request::errorString()\n"; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub loginInfo { | ||||||||||||||||||||||||||
|
Subroutine
loginInfo: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | print STDERR "TODO Request::loginInfo()\n"; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub setInfo { | ||||||||||||||||||||||||||
|
Subroutine
setInfo: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | 0 | my ( $self, $info ) = @_; | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | $self->data->{_info} = $info if ( defined $info ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | return $self->data->{_info}; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 1763 | ▶ | sub info { | ||||||||||||||||||||||||||
|
Subroutine
info: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | 1763 | my ( $self, $info ) = @_; | |||||||||||||||||||||||||||
| 180 | 1763 | ▶ | $self->data->{_info} .= $info if ( defined $info ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 1763 | return $self->data->{_info}; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 291 | ▶ | sub addCookie { | ||||||||||||||||||||||||||
|
Subroutine
addCookie: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 185 | 291 | my ( $self, $cookie ) = @_; | |||||||||||||||||||||||||||
| 186 | 291 | push @{ $self->respHeaders }, 'Set-Cookie' => $cookie; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub delCookie { | ||||||||||||||||||||||||||
|
Subroutine
delCookie: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 190 | 0 | my ( $self, $cookieName ) = @_; | |||||||||||||||||||||||||||
| 191 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 192 | 0 | @{ $self->respHeaders } = map { | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # Look for a Set-Cookie header | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ( $_ =~ /^Set-Cookie$/i ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 196 | 0 | $i = 1; | |||||||||||||||||||||||||||
| 197 | 0 | return (); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | elsif ($i) { | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # Keep other cookies | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | unless (/^$cookieName\s*=/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | $i = 0; | |||||||||||||||||||||||||||
| 204 | 0 | return ( 'Set-Cookie' => $_ ); | |||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | #Value is hidden here | ||||||||||||||||||||||||||||
| 208 | 0 | return (); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 0 | return $_; | |||||||||||||||||||||||||||
| 211 | 0 | } @{ $self->respHeaders }; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # TODO: oldpassword | ||||||||||||||||||||||||||||
| 215 | 454 | 1; | |||||||||||||||||||||||||||
| 216 | __END__ | ||||||||||||||||||||||||||||