« blib/lib/Lemonldap/NG/Portal/Lib/_tokenRule.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Auth/Null.pm »
| 1 | package Lemonldap::NG::Portal::Main::SecondFactor; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 52 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 52 | ▶ | use Mouse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 52 | use Lemonldap::NG::Portal::Main::Constants qw( | |||||||||||||||||||
| 6 | PE_OK | ||||||||||||||||||||
| 7 | PE_ERROR | ||||||||||||||||||||
| 8 | PE_NOTOKEN | ||||||||||||||||||||
| 9 | PE_SENDRESPONSE | ||||||||||||||||||||
| 10 | PE_TOKENEXPIRED | ||||||||||||||||||||
| 11 | PE_BADCREDENTIALS | ||||||||||||||||||||
| 12 | 52 | ▶ | ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 52 | our $VERSION = '2.20.0'; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 52 | extends qw( | |||||||||||||||||||
| 17 | Lemonldap::NG::Portal::Main::Plugin | ||||||||||||||||||||
| 18 | Lemonldap::NG::Portal::Auth::_WebForm | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | # INITIALIZATION | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | has ott => ( | ||||||||||||||||||||
| 24 | is => 'rw', | ||||||||||||||||||||
| 25 | lazy => 1, | ||||||||||||||||||||
| 26 | default => sub { | ||||||||||||||||||||
| 27 | my $ott = | ||||||||||||||||||||
| 28 | 35 | ▶ | $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken'); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 29 | $ott->timeout( $_[0]->{conf}->{sfLoginTimeout} | ||||||||||||||||||||
| 30 | 35 | ▶ | || $_[0]->{conf}->{formTimeout} ); | ||||||||||||||||||
|
Condition66%2/3
$_[0]{'conf'}{'sfLoginTimeout'} || $_[0]{'conf'}{'formTimeout'}
MC/DC0%0/2
$_[0]{'conf'}{'sfLoginTimeout'} || $_[0]{'conf'}{'formTimeout'}
$_[0]{'conf'}{'sfLoginTimeout'}
$_[0]{'conf'}{'formTimeout'}
Truth table66%2/3
A || B
A= $_[0]{'conf'}{'sfLoginTimeout'}B= $_[0]{'conf'}{'formTimeout'}
| |||||||||||||||||||||
| 31 | 35 | return $ott; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | 52 | ); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 52 | has prefix => ( is => 'rw' ); | |||||||||||||||||||
| 36 | 52 | has logo => ( is => 'rw', default => '2f.png' ); | |||||||||||||||||||
| 37 | 52 | has label => ( is => 'rw' ); | |||||||||||||||||||
| 38 | 52 | has noRoute => ( is => 'ro' ); | |||||||||||||||||||
| 39 | has authnLevel => ( | ||||||||||||||||||||
| 40 | is => 'rw', | ||||||||||||||||||||
| 41 | lazy => 1, | ||||||||||||||||||||
| 42 | default => sub { | ||||||||||||||||||||
| 43 | 1 | ▶ | return $_[0]->conf->{ $_[0]->prefix . '2fAuthnLevel' }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | 52 | ); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | has rule => ( | ||||||||||||||||||||
| 48 | is => 'rw', | ||||||||||||||||||||
| 49 | lazy => 1, | ||||||||||||||||||||
| 50 | default => sub { | ||||||||||||||||||||
| 51 | 64 | ▶ | return $_[0]->conf->{ $_[0]->prefix . '2fActivation' }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | 52 | ); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | # 'type' field of stored _2fDevices | ||||||||||||||||||||
| 56 | # Defaults to the last component of the package name | ||||||||||||||||||||
| 57 | # But can be overriden by sfExtra | ||||||||||||||||||||
| 58 | has type => ( | ||||||||||||||||||||
| 59 | is => 'rw', | ||||||||||||||||||||
| 60 | default => sub { | ||||||||||||||||||||
| 61 | 70 | ▶ | ( split( '::', ref( $_[0] ) ) )[-1]; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 52 | ); | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | sub init { | ||||||||||||||||||||
| 66 | 70 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # Set logo if overridden | ||||||||||||||||||||
| 69 | $self->logo( $self->conf->{ $self->prefix . '2fLogo' } ) | ||||||||||||||||||||
| 70 | 70 | ▶ | if $self->conf->{ $self->prefix . '2fLogo' }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | # Set label if provided, translation files will be used otherwise | ||||||||||||||||||||
| 73 | $self->label( $self->conf->{ $self->prefix . '2fLabel' } ) | ||||||||||||||||||||
| 74 | 70 | ▶ | if $self->conf->{ $self->prefix . '2fLabel' }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 70 | return 1; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub get2fTplParams { | ||||||||||||||||||||
| 80 | 2 | ▶ | my ( $self, $req ) = @_; | ||||||||||||||||||
|
Subroutine
get2fTplParams: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 2 | return $self->p->_sfEngine->get2fTplParams( $req, $self ); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | 52 | 1; | |||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =pod | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =encoding utf8 | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 NAME | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | Lemonldap::NG::Portal::Main::SecondFactor - Base class for | ||||||||||||||||||||
| 94 | L<Lemonldap::NG::Portal> second factor plugins. | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 SYNOPSIS | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | package Lemonldap::NG::Portal::2F::MySecondFactor; | ||||||||||||||||||||
| 99 | use Mouse; | ||||||||||||||||||||
| 100 | # Import used constants | ||||||||||||||||||||
| 101 | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||
| 102 | PE_OK | ||||||||||||||||||||
| 103 | PE_BADCREDENTIALS | ||||||||||||||||||||
| 104 | PE_SENDRESPONSE | ||||||||||||||||||||
| 105 | ); | ||||||||||||||||||||
| 106 | extends 'Lemonldap::NG::Portal::Main::SecondFactor'; | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | # INITIALIZATION | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | # Prefix that will be used in parameter names. The form used to enter the | ||||||||||||||||||||
| 111 | # second factor must post its result to "/my2fcheck" (if "my" is the prefix). | ||||||||||||||||||||
| 112 | has prefix => ( is => 'ro', default => 'my' ); | ||||||||||||||||||||
| 113 | # Optional logo | ||||||||||||||||||||
| 114 | has logo => ( is => 'rw', default => 'mylogo.png' ); | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | # Required init method | ||||||||||||||||||||
| 117 | sub init { | ||||||||||||||||||||
| 118 | my ($self) = @_; | ||||||||||||||||||||
| 119 | # Insert here initialization process | ||||||||||||||||||||
| 120 | # | ||||||||||||||||||||
| 121 | # If self registration is enabled and "activation" is set to "enabled", | ||||||||||||||||||||
| 122 | # replace the rule to detect if user has registered a device key. | ||||||||||||||||||||
| 123 | # The rule must be like this : | ||||||||||||||||||||
| 124 | # By example : | ||||||||||||||||||||
| 125 | $self->conf->{totp2fActivation} = '$_2fDevices =~ /"type":\s*"TOTP"/s' | ||||||||||||||||||||
| 126 | # Optionally, the rule can be : '$_2fDevices and $_2fDevices =~ /"type":\s*"TOTP"/s' | ||||||||||||||||||||
| 127 | # to avoid warning due to undef variable | ||||||||||||||||||||
| 128 | # | ||||||||||||||||||||
| 129 | # Required call: | ||||||||||||||||||||
| 130 | return $self->SUPER::init(); | ||||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | # RUNNING METHODS | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | # Required 2nd factor send method | ||||||||||||||||||||
| 136 | sub run { | ||||||||||||||||||||
| 137 | my ( $self, $req, $token ) = @_; | ||||||||||||||||||||
| 138 | # $token must be inserted in a hidden input in your form with the name | ||||||||||||||||||||
| 139 | # "token" | ||||||||||||||||||||
| 140 | ... | ||||||||||||||||||||
| 141 | # A LLNG constant must be returned. Example: | ||||||||||||||||||||
| 142 | $req->response($my_psgi_response); | ||||||||||||||||||||
| 143 | return PE_SENDRESPONSE; | ||||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | # Required 2nd factor verify method | ||||||||||||||||||||
| 146 | sub verify { | ||||||||||||||||||||
| 147 | my ( $self, $req, $session ) = @_; | ||||||||||||||||||||
| 148 | # Use $req->param('field') to get POST responses | ||||||||||||||||||||
| 149 | ... | ||||||||||||||||||||
| 150 | if ($result eq $goodResult) { | ||||||||||||||||||||
| 151 | return PE_OK; | ||||||||||||||||||||
| 152 | } | ||||||||||||||||||||
| 153 | else { | ||||||||||||||||||||
| 154 | return PE_BADCREDENTIALS; | ||||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | 1; | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | Enable your plugin in lemonldap-ng.ini, section [portal]: | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =over | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =item <prefix>2fActivation (required): 1, 0 or a rule | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | =item <prefix>2fAuthnLevel (optional): change authentication level for users | ||||||||||||||||||||
| 166 | authenticated by this plugin | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =back | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | Example: | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | [portal] | ||||||||||||||||||||
| 173 | customPlugins = Lemonldap::NG::Portal::2F::MyPlugin | ||||||||||||||||||||
| 174 | my2fActivation = 1 | ||||||||||||||||||||
| 175 | my2fAuthnLevel = 4 | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | =head1 DESCRIPTION | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | Lemonldap::NG::Portal::Main::SecondFactor provides a simple framework to build | ||||||||||||||||||||
| 180 | Lemonldap::NG second authentication factor plugin. | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | See Lemonldap::NG::Portal::Plugins::2F::* packages for examples. | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =head1 SEE ALSO | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | L<http://lemonldap-ng.org> | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | =head2 OTHER POD FILES | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | =over | ||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | =item Writing an authentication module: L<Lemonldap::NG::Portal::Auth> | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | =item Writing a UserDB module: L<Lemonldap::NG::Portal::UserDB> | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | =item Writing a second factor module: L<Lemonldap::NG::Portal::Main::SecondFactor> | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | =item Writing an issuer module: L<Lemonldap::NG::Portal::Main::Issuer> | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =item Writing another plugin: L<Lemonldap::NG::Portal::Main::Plugin> | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =item Request object: L<Lemonldap::NG::Portal::Main::Request> | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | =item Adding parameters in the manager: L<Lemonldap::NG::Manager::Build> | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | =back | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | =head1 AUTHORS | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | =over | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | =item LemonLDAP::NG team L<http://lemonldap-ng.org/team> | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | =back | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | =head1 BUG REPORT | ||||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | Use OW2 system to report bug or ask for features: | ||||||||||||||||||||
| 219 | L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues> | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | =head1 DOWNLOAD | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | Lemonldap::NG is available at | ||||||||||||||||||||
| 224 | L<https://lemonldap-ng.org/download> | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | See COPYING file for details. | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||
| 231 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 232 | the Free Software Foundation; either version 2, or (at your option) | ||||||||||||||||||||
| 233 | any later version. | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 236 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 237 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 238 | GNU General Public License for more details. | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 241 | along with this program. If not, see L<http://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | =cut | ||||||||||||||||||||