Debian Codegraph @

lemonldap-ng-manager/lib/Lemonldap/NG/Manager/2ndFA.pm

raw
1 package Lemonldap::NG::Manager::2ndFA;
2
3 use strict;
4 use utf8;
5 use Mouse;
6
7 use Lemonldap::NG::Common::Session;
8 use Lemonldap::NG::Common::Conf::Constants;
9 use Lemonldap::NG::Common::PSGI::Constants;
10 use Lemonldap::NG::Common::Conf::ReConstants;
11
12 extends qw(
13 Lemonldap::NG::Manager::Plugin
14 Lemonldap::NG::Common::Session::REST
15 Lemonldap::NG::Common::Conf::AccessLib
16 );
17
18 our $VERSION = '2.18.0';
19
20 #############################
21 # I. INITIALIZATION METHODS #
22 #############################
23
24 use constant defaultRoute => '2ndfa.html';
25 use constant icon => 'wrench';
26
27 sub init {
28 my ( $self, $conf ) = @_;
29
30 # Remote Procedure are defined in Lemonldap::NG::Common::Session::REST
31 # HTML template
32 $self->addRoute( '2ndfa.html', 'sfaView', ['GET'] )
33
34 ->addRoute(
35 sfa => { ':sessionType' => 'sfa' },
36 ['GET']
37 )
38
39 # DELETE 2FA DEVICE
40 ->addRoute(
41 sfa => { ':sessionType' => { ':sessionId' => 'del2F' } },
42 ['DELETE']
43 );
44
45 $self->setTypes($conf);
46 $self->{multiValuesSeparator} ||= '; ';
47 $self->{hiddenAttributes} //= "_password";
48 $self->{hiddenAttributes} .= ' _session_id'
49 unless $conf->{displaySessionId};
50
51 $self->{regSfaTypes} = [ (
52 sort map { s/^Yubikey$/UBK/r } split /[\s,]+/,
53 $conf->{available2FSelfRegistration}
54 ),
55 keys %{ $conf->{sfExtra} || {} },
56 ];
57 return 1;
58 }
59
60 ###################
61 # II. 2FA METHODS #
62 ###################
63
64 sub del2F {
65
66 my ( $self, $req, $session, $skey ) = @_;
67
68 my $mod = $self->getMod($req)
69 or return $self->sendError( $req, 'Bad mode', 400 );
70
71 my $params = $req->parameters();
72 my $type = $params->{type}
73 or return $self->sendError( $req, 'Missing "type" parameter', 400 );
74 my $epoch = $params->{epoch}
75 or return $self->sendError( $req, 'Missing "epoch" parameter', 400 );
76
77 $self->logger->debug(
78 "Call procedure delete2F with type=$type and epoch=$epoch");
79 return $self->delete2F( $req, $session, $skey );
80 }
81
82 ########################
83 # III. DISPLAY METHODS #
84 ########################
85
86 sub sfa {
87 my ( $self, $req, $session, $skey ) = @_;
88
89 my $mod = $self->getMod($req)
90 or return $self->sendError( $req, 'Bad mode', 400 );
91
92 $self->logger->debug("Call procedure get2F");
93 return $self->get2F( $req, $session, $skey );
94 }
95
96 sub sfaView {
97 my ( $self, $req ) = @_;
98 return $self->p->sendHtml(
99 $req, "2ndfa",
100 params => {
101 SFATYPES => [ map { { SFATYPE => $_ } } @{ $self->{regSfaTypes} } ],
102 }
103 );
104 }
105
106 1;