« blib/lib/Lemonldap/NG/Portal/2F/Register/Yubikey.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Captcha/ReCaptcha.pm »
| 1 | package Lemonldap::NG::Portal::2F::REST; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use Mouse; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | PE_BADOTP | ||||||||||||
| 7 | PE_ERROR | ||||||||||||
| 8 | PE_FORMEMPTY | ||||||||||||
| 9 | PE_OK | ||||||||||||
| 10 | PE_SENDRESPONSE | ||||||||||||
| 11 | 4 | ); | |||||||||||
| 12 | |||||||||||||
| 13 | 4 | our $VERSION = '2.23.0'; | |||||||||||
| 14 | |||||||||||||
| 15 | 4 | extends qw( | |||||||||||
| 16 | Lemonldap::NG::Portal::Lib::Code2F | ||||||||||||
| 17 | Lemonldap::NG::Portal::Lib::REST | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | |||||||||||||
| 20 | # INITIALIZATION | ||||||||||||
| 21 | |||||||||||||
| 22 | # Prefix can overriden by sfExtra and is used for routes | ||||||||||||
| 23 | 4 | has prefix => ( is => 'rw', default => 'rest' ); | |||||||||||
| 24 | |||||||||||||
| 25 | # Used to lookup config | ||||||||||||
| 26 | 4 | has conf_type => ( is => 'ro', default => 'rest' ); | |||||||||||
| 27 | |||||||||||||
| 28 | 4 | has legend => ( is => 'rw', default => 'enterRest2fCode' ); | |||||||||||
| 29 | |||||||||||||
| 30 | 4 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=4 SCAR=15.5
Pod
undocumented
| |||||||||||||
| 31 | 4 | my ($self) = @_; | |||||||||||
| 32 | |||||||||||||
| 33 | 4 | my $init_result = $self->initNamedCallFromConf( 'rest2fInit', 'init' ); | |||||||||||
| 34 | 4 | my $verify_result = $self->initNamedCallFromConf( 'rest2fVerify', 'vrfy' ); | |||||||||||
| 35 | |||||||||||||
| 36 | 4 | ▶ | if ( $self->code_activation ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 2 | ▶ | unless ($init_result) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 0 | $self->logger->error( | |||||||||||
| 39 | $self->prefix . '2f: missing intialization URL' ); | ||||||||||||
| 40 | 0 | return 0; | |||||||||||
| 41 | } | ||||||||||||
| 42 | } | ||||||||||||
| 43 | else { | ||||||||||||
| 44 | 2 | ▶ | unless ($verify_result) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | $self->logger->error( | |||||||||||
| 46 | $self->prefix . '2f: missing verification URL' ); | ||||||||||||
| 47 | 0 | return 0; | |||||||||||
| 48 | } | ||||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | 4 | return $self->SUPER::init(); | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | 0 | ▶ | sub sendCode { | ||||||||||
|
Subroutine
sendCode: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 55 | 0 | my ( $self, $req, $sessionInfo, $code ) = @_; | |||||||||||
| 56 | |||||||||||||
| 57 | 0 | ▶ | if ( $self->conf->{rest2fInitUrl} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | |||||||||||||
| 59 | # Prepare args | ||||||||||||
| 60 | my $args = { | ||||||||||||
| 61 | user => $sessionInfo->{ $self->conf->{whatToTrace} }, | ||||||||||||
| 62 | 0 | ▶ | ( $code ? ( code => $code ) : () ), | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | }; | ||||||||||||
| 64 | |||||||||||||
| 65 | # Launch REST request | ||||||||||||
| 66 | 0 | $self->logger->debug( $self->prefix . '2f: call init URL' ); | |||||||||||
| 67 | my $res = | ||||||||||||
| 68 | 0 | eval { $self->restNamedCall( $req, 'init', $args, $sessionInfo ); }; | |||||||||||
| 69 | 0 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 0 | $self->logger->error( $self->prefix . "2f: error ($@)" ); | |||||||||||
| 71 | 0 | return PE_ERROR; | |||||||||||
| 72 | } | ||||||||||||
| 73 | 0 | ▶ | unless ( $res->{result} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | 0 | $self->logger->error( $self->prefix . '2f: initialization failed' ); | |||||||||||
| 75 | 0 | return PE_ERROR; | |||||||||||
| 76 | } | ||||||||||||
| 77 | } | ||||||||||||
| 78 | else { | ||||||||||||
| 79 | 0 | $self->logger->debug( | |||||||||||
| 80 | $self->prefix . '2f: no init URL, skipping initialization' ); | ||||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 0 | return 1; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 0 | ▶ | sub verify_external { | ||||||||||
|
Subroutine
verify_external: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 87 | 0 | my ( $self, $req, $session, $code ) = @_; | |||||||||||
| 88 | |||||||||||||
| 89 | # Prepare args | ||||||||||||
| 90 | my $args = { | ||||||||||||
| 91 | user => $session->{ $self->conf->{whatToTrace} }, | ||||||||||||
| 92 | 0 | code => $code | |||||||||||
| 93 | }; | ||||||||||||
| 94 | |||||||||||||
| 95 | # in older versions, code was not automatically defined | ||||||||||||
| 96 | # if admins defined it explicitly, do not treat it as a session | ||||||||||||
| 97 | # attribute | ||||||||||||
| 98 | 0 | ▶ | my $session_data = { %{ $session || {} }, code => $code }; | ||||||||||
|
Condition0%0/2
$session || {}
MC/DC0%0/1
$session || {}
$session
Truth table0%0/2
A
A= $session
| |||||||||||||
| 99 | |||||||||||||
| 100 | # Launch REST request | ||||||||||||
| 101 | 0 | $self->logger->debug( $self->prefix . '2f: call verify URL' ); | |||||||||||
| 102 | my $res = | ||||||||||||
| 103 | 0 | eval { $self->restNamedCall( $req, 'vrfy', $args, $session_data ) }; | |||||||||||
| 104 | 0 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 105 | 0 | $self->logger->error( $self->prefix . "2f: error ($@)" ); | |||||||||||
| 106 | 0 | return PE_ERROR; | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | # Result | ||||||||||||
| 110 | 0 | ▶ | unless ( $res->{result} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 111 | $self->userLogger->warn( $self->prefix | ||||||||||||
| 112 | . '2f: failed for ' | ||||||||||||
| 113 | 0 | . $session->{ $self->conf->{whatToTrace} } ); | |||||||||||
| 114 | 0 | return PE_BADOTP; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | $self->logger->debug( | ||||||||||||
| 118 | 0 | $self->prefix . '2f: credentials accepted by server' ); | |||||||||||
| 119 | 0 | return PE_OK; | |||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | 4 | 1; | |||||||||||