2018-05-15 21:20:31 +02:00
|
|
|
# Check state plugin
|
|
|
|
#
|
|
|
|
# test if portal is well loaded. If user/pasword parameters are set, it tests
|
|
|
|
# also login process
|
|
|
|
|
|
|
|
package Lemonldap::NG::Portal::Plugins::CheckState;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2021-11-23 12:01:06 +01:00
|
|
|
use Lemonldap::NG::Portal;
|
2018-05-15 21:20:31 +02:00
|
|
|
|
2022-02-01 16:33:08 +01:00
|
|
|
our $VERSION = '2.0.14';
|
2018-05-15 21:20:31 +02:00
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Main::Plugin';
|
|
|
|
|
|
|
|
# INITIALIZATION
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
my ($self) = @_;
|
|
|
|
unless ( $self->conf->{checkStateSecret} ) {
|
|
|
|
$self->logger->error(
|
|
|
|
'checkStateSecret is required for "check state" plugin');
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-09 22:26:00 +02:00
|
|
|
$self->addUnauthRoute( checkstate => 'check', ['GET'] )
|
|
|
|
->addAuthRoute( checkstate => 'check', ['GET'] );
|
2020-12-09 18:01:02 +01:00
|
|
|
|
2018-05-15 21:20:31 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub check {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
my @rep;
|
2020-02-25 22:01:04 +01:00
|
|
|
return $self->p->sendError( $req, 'Bad secret' )
|
|
|
|
unless ( $req->param('secret')
|
|
|
|
and $req->param('secret') eq $self->conf->{checkStateSecret} );
|
2018-05-15 21:20:31 +02:00
|
|
|
$req->steps( [ 'controlUrl', @{ $self->p->beforeAuth } ] );
|
|
|
|
my $res = $self->p->process($req);
|
2020-12-11 00:10:22 +01:00
|
|
|
if ( $res && $res > 0 ) {
|
2018-05-15 21:20:31 +02:00
|
|
|
push @rep, "Bad result before auth: $res";
|
|
|
|
}
|
2020-05-24 00:04:33 +02:00
|
|
|
|
2018-05-15 21:20:31 +02:00
|
|
|
if ( my $user = $req->param('user') and my $pwd = $req->param('password') )
|
|
|
|
{
|
2021-09-10 12:27:01 +02:00
|
|
|
$req->parameters->{user} = ($user);
|
|
|
|
$req->parameters->{password} = $pwd;
|
|
|
|
$req->data->{skipToken} = 1;
|
|
|
|
|
|
|
|
# This makes Auth::Choice use authChoiceAuthBasic if defined
|
|
|
|
$req->data->{_pwdCheck} = 1;
|
2018-05-15 22:05:23 +02:00
|
|
|
|
2018-05-15 22:06:51 +02:00
|
|
|
# Not launched methods:
|
2018-05-15 22:05:23 +02:00
|
|
|
# - "buildCookie" useless here
|
2019-02-07 09:27:56 +01:00
|
|
|
$req->steps( [
|
2021-09-10 12:27:01 +02:00
|
|
|
@{ $self->p->beforeAuth },
|
|
|
|
$self->p->authProcess,
|
|
|
|
@{ $self->p->betweenAuthAndData },
|
|
|
|
$self->p->sessionData,
|
|
|
|
@{ $self->p->afterData },
|
|
|
|
'storeHistory',
|
2018-09-05 09:19:01 +02:00
|
|
|
@{ $self->p->endAuth }
|
2018-05-15 21:20:31 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
if ( $res = $self->p->process( $req, ) ) {
|
|
|
|
push @rep, "Bad result during auth: $res";
|
|
|
|
}
|
|
|
|
$self->p->deleteSession($req);
|
|
|
|
}
|
2020-02-25 22:01:04 +01:00
|
|
|
|
|
|
|
return $self->p->sendError( $req, join( ",\n", @rep ), 500 ) if (@rep);
|
2021-11-23 12:01:06 +01:00
|
|
|
return $self->p->sendJSONresponse( $req,
|
|
|
|
{ result => 1, version => $Lemonldap::NG::Portal::VERSION } );
|
2018-05-15 21:20:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|