« blib/lib/Lemonldap/NG/Portal/Issuer/OpenID.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Lib/OpenIDConnect.pm »
| 1 | # Base package for Password modules | ||||||||||||||||||||||||||||
| 2 | package Lemonldap::NG::Portal::Password::Base; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 105 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 105 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 105 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | PE_OK | ||||||||||||||||||||||||||||
| 8 | PE_PASSWORD_OK | ||||||||||||||||||||||||||||
| 9 | PE_BADOLDPASSWORD | ||||||||||||||||||||||||||||
| 10 | PE_PASSWORD_MISMATCH | ||||||||||||||||||||||||||||
| 11 | PE_PP_PASSWORD_TOO_SHORT | ||||||||||||||||||||||||||||
| 12 | PE_PP_NOT_ALLOWED_CHARACTER | ||||||||||||||||||||||||||||
| 13 | PE_PP_NOT_ALLOWED_CHARACTERS | ||||||||||||||||||||||||||||
| 14 | PE_PP_MUST_SUPPLY_OLD_PASSWORD | ||||||||||||||||||||||||||||
| 15 | PE_PP_INSUFFICIENT_PASSWORD_QUALITY | ||||||||||||||||||||||||||||
| 16 | 105 | ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 105 | extends | |||||||||||||||||||||||||||
| 19 | qw/Lemonldap::NG::Portal::Main::Plugin Lemonldap::NG::Portal::Lib::SMTP/; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 105 | our $VERSION = '2.20.0'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # INITIALIZATION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 105 | has requireOldPwdRule => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 26 | 105 | has ott => ( is => 'rw' ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 17 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 17 | my ($self) = shift; | |||||||||||||||||||||||||||
| 30 | $self->requireOldPwdRule( | ||||||||||||||||||||||||||||
| 31 | $self->p->buildRule( | ||||||||||||||||||||||||||||
| 32 | $self->conf->{portalRequireOldPassword}, | ||||||||||||||||||||||||||||
| 33 | 17 | 'portalRequireOldPassword' | |||||||||||||||||||||||||||
| 34 | ) | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | 17 | ▶ | return 0 unless $self->requireOldPwdRule; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 17 | ▶ | $self->ott( $self->p->loadModule('::Lib::OneTimeToken') ) or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 17 | $self->ott->timeout( $self->conf->{formTimeout} ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 17 | $self->p->{_passwordDB} = $self; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # INTERFACE | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 105 | ▶ | use constant forAuthUser => '_modifyPassword'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # RUNNING METHODS | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 79 | ▶ | sub _modifyPassword { | ||||||||||||||||||||||||||
|
Subroutine
_modifyPassword: called CC=22 SCAR=42.8
| |||||||||||||||||||||||||||||
| 51 | 79 | my ( $self, $req, $requireOldPwd ) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Exit if no password change requested | ||||||||||||||||||||||||||||
| 54 | return PE_OK | ||||||||||||||||||||||||||||
| 55 | 79 | ▶ | unless ( $req->data->{newpassword} = $req->param('newpassword') ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # Verify that old password is good | ||||||||||||||||||||||||||||
| 58 | return PE_PASSWORD_MISMATCH | ||||||||||||||||||||||||||||
| 59 | 2 | ▶ | unless ( $req->data->{newpassword} eq $req->param('confirmpassword') ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | my $oldPwdRule = $self->p->HANDLER->buildSub( | ||||||||||||||||||||||||||||
| 62 | $self->p->HANDLER->substitute( | ||||||||||||||||||||||||||||
| 63 | $self->conf->{portalRequireOldPassword} | ||||||||||||||||||||||||||||
| 64 | ) | ||||||||||||||||||||||||||||
| 65 | 2 | ); | |||||||||||||||||||||||||||
| 66 | 2 | ▶ | unless ($oldPwdRule) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | my $error = | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $self->p->HANDLER->tsv->{jail}->error || 'Unable to compile rule'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->p->HANDLER->tsv->{'jail'}->error || 'Unable to compile rule'
MC/DC0%0/1
$self->p->HANDLER->tsv->{'jail'}->error || 'Unable to compile rule'
$self->p->HANDLER->tsv->{'jail'}->error
Truth table0%0/2
A
A= $self->p->HANDLER->tsv->{'jail'}->error
| |||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Check if portal require old password | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | if ( $oldPwdRule->( $req, $req->userData ) or $requireOldPwd ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
&$oldPwdRule($req, $req->userData) or $requireOldPwd
MC/DC0%0/2
&$oldPwdRule($req, $req->userData) or $requireOldPwd
&$oldPwdRule($req, $req->userData)
$requireOldPwd
Truth table33%1/3
A or B
A= &$oldPwdRule($req, $req->userData)B= $requireOldPwd
| |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | unless ( $req->param('oldpassword') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | $self->logger->warn('Portal require old password'); | |||||||||||||||||||||||||||
| 75 | 0 | return PE_PP_MUST_SUPPLY_OLD_PASSWORD; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | 2 | my $token; | |||||||||||||||||||||||||||
| 78 | $token = $self->ott->getToken( $req->param('oldpassword') ) | ||||||||||||||||||||||||||||
| 79 | 2 | ▶ | if $self->conf->{hideOldPassword} && $requireOldPwd; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->conf->{"hideOldPassword"} and $requireOldPwd
MC/DC0%0/2
$self->conf->{"hideOldPassword"} and $requireOldPwd
$self->conf->{"hideOldPassword"}
$requireOldPwd
Truth table33%1/3
A and B
A= $self->conf->{"hideOldPassword"}B= $requireOldPwd
| |||||||||||||||||||||||||||||
| 80 | $req->data->{oldpassword} = | ||||||||||||||||||||||||||||
| 81 | $token | ||||||||||||||||||||||||||||
| 82 | ? $self->conf->{cipher}->decrypt( $token->{oldpassword} ) | ||||||||||||||||||||||||||||
| 83 | 2 | ▶ | : $req->param('oldpassword'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # Verify old password | ||||||||||||||||||||||||||||
| 86 | return PE_BADOLDPASSWORD | ||||||||||||||||||||||||||||
| 87 | 2 | ▶ | unless $self->confirm( $req, $req->data->{oldpassword} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | my $hook_result = $self->p->processHook( | ||||||||||||||||||||||||||||
| 91 | $req, 'passwordBeforeChange', $req->user, | ||||||||||||||||||||||||||||
| 92 | $req->data->{newpassword}, | ||||||||||||||||||||||||||||
| 93 | $req->data->{oldpassword} | ||||||||||||||||||||||||||||
| 94 | 2 | ); | |||||||||||||||||||||||||||
| 95 | 2 | ▶ | return $hook_result if ( $hook_result != PE_OK ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # Call password package | ||||||||||||||||||||||||||||
| 98 | 2 | my $res = $self->modifyPassword( $req, $req->data->{newpassword} ); | |||||||||||||||||||||||||||
| 99 | 2 | ▶ | if ( $res == PE_PASSWORD_OK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | my $hook_result = $self->p->processHook( | ||||||||||||||||||||||||||||
| 102 | $req, 'passwordAfterChange', $req->user, | ||||||||||||||||||||||||||||
| 103 | $req->data->{newpassword}, | ||||||||||||||||||||||||||||
| 104 | $req->data->{oldpassword} | ||||||||||||||||||||||||||||
| 105 | 2 | ); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 2 | $self->logger->debug( 'Update password in session for ' . $req->user ); | |||||||||||||||||||||||||||
| 108 | 2 | my $userlog = $req->sessionInfo->{ $self->conf->{whatToTrace} }; | |||||||||||||||||||||||||||
| 109 | 2 | my $iplog = $req->sessionInfo->{ipAddr}; | |||||||||||||||||||||||||||
| 110 | 2 | ▶ | $self->userLogger->notice("Password changed for $userlog ($iplog)") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $userlog and $iplog
MC/DC0%0/2
defined $userlog and $iplog
defined $userlog
$iplog
Truth table33%1/3
A and B
A= defined $userlogB= $iplog
| |||||||||||||||||||||||||||||
| 111 | if ( defined $userlog and $iplog ); | ||||||||||||||||||||||||||||
| 112 | 2 | my $infos; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # Store new password if asked | ||||||||||||||||||||||||||||
| 115 | 2 | ▶ | if ( $self->conf->{storePassword} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | my $passwordToStore = $req->data->{'newpassword'}; | |||||||||||||||||||||||||||
| 117 | $self->p->updateSession( | ||||||||||||||||||||||||||||
| 118 | $req, | ||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||
| 120 | _passwordDB => $self->p->getModule( $req, 'password' ), | ||||||||||||||||||||||||||||
| 121 | _password => $self->conf->{storePasswordEncrypted} | ||||||||||||||||||||||||||||
| 122 | ? $self->p->HANDLER->tsv->{cipher} | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | ->encrypt($passwordToStore) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | : $passwordToStore | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | else { | ||||||||||||||||||||||||||||
| 129 | 2 | $self->p->updateSession( $req, | |||||||||||||||||||||||||||
| 130 | { _passwordDB => $self->p->getModule( $req, 'password' ) } ); | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 2 | ▶ | if ( $self->conf->{mailOnPasswordChange} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # Send mail containing the new password | ||||||||||||||||||||||||||||
| 136 | $req->data->{mailAddress} ||= | ||||||||||||||||||||||||||||
| 137 | $self->p->getFirstValue( | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $req->{sessionInfo}->{ $self->conf->{mailSessionKey} } ); | ||||||||||||||||||||||||||
|
Condition0%0/3
$req->data->{"mailAddress"} ||= $self->p->getFirstValue($req->{"sessionInfo"}{$self->conf->{"mailSessionKey"}})
MC/DC0%0/2
$req->data->{"mailAddress"} ||= $self->p->getFirstValue($req->{"sessionInfo"}{$self->conf->{"mailSessionKey"}})
$req->data->{"mailAddress"}
$self->p->getFirstValue($req->{"sessionInfo"}{$self->conf->{"mailSessionKey"}})
Truth table0%0/3
A ||= B
A= $req->data->{"mailAddress"}B= $self->p->getFirstValue($req->{"sessionInfo"}{$self->conf->{"mailSessionKey"}})
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my $password = $req->data->{newpassword}; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # Send mail | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | unless ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | $self->sendEmail( | ||||||||||||||||||||||||||||
| 145 | $req, | ||||||||||||||||||||||||||||
| 146 | subject => $self->conf->{mailSubject}, | ||||||||||||||||||||||||||||
| 147 | subject_trmsg => 'mailSubject', | ||||||||||||||||||||||||||||
| 148 | body => $self->conf->{mailBody}, | ||||||||||||||||||||||||||||
| 149 | body_template => 'mail_password', | ||||||||||||||||||||||||||||
| 150 | dest => $req->data->{mailAddress}, | ||||||||||||||||||||||||||||
| 151 | params => { | ||||||||||||||||||||||||||||
| 152 | password => $password, | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | ) | ||||||||||||||||||||||||||||
| 155 | ) | ||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||
| 157 | $self->logger->warn( "Unable to send password changed mail to " | ||||||||||||||||||||||||||||
| 158 | 0 | . $req->data->{mailAddress} ); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # Continue process if password change is ok | ||||||||||||||||||||||||||||
| 163 | 2 | ▶ | return ( $hook_result != PE_OK ) ? $hook_result : PE_PASSWORD_OK; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | 0 | return $res; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # This method should be called when resetting the password | ||||||||||||||||||||||||||||
| 169 | # in order to call the password hook | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | sub setNewPassword { | ||||||||||||||||||||||||||
|
Subroutine
setNewPassword: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 171 | 0 | my ( $self, $req, $pwd, $useMail ) = @_; | |||||||||||||||||||||||||||
| 172 | 0 | my %args; | |||||||||||||||||||||||||||
| 173 | 0 | my $hook_result = | |||||||||||||||||||||||||||
| 174 | $self->p->processHook( $req, 'passwordBeforeChange', $req->user, $pwd ); | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | return $hook_result if ( $hook_result != PE_OK ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # Delegate to subclass | ||||||||||||||||||||||||||||
| 178 | 0 | $args{useMail} = $useMail; | |||||||||||||||||||||||||||
| 179 | 0 | $args{passwordReset} = 1; | |||||||||||||||||||||||||||
| 180 | 0 | my $mod_result = $self->modifyPassword( $req, $pwd, %args ); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ( $mod_result == PE_PASSWORD_OK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 0 | $hook_result = | |||||||||||||||||||||||||||
| 184 | $self->p->processHook( $req, 'passwordAfterChange', $req->user, | ||||||||||||||||||||||||||||
| 185 | $pwd ); | ||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return ( $hook_result != PE_OK ) ? $hook_result : PE_PASSWORD_OK; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | else { | ||||||||||||||||||||||||||||
| 189 | 0 | return $mod_result; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 105 | 1; | |||||||||||||||||||||||||||