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;
|
|
|
|
|
2020-10-09 22:26:00 +02:00
|
|
|
our $VERSION = '2.0.10';
|
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') )
|
|
|
|
{
|
|
|
|
$req->user($user);
|
2018-07-05 22:56:16 +02:00
|
|
|
$req->data->{password} = $pwd;
|
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
|
|
|
# - "extractFormInfo" due to "token"
|
|
|
|
# - "buildCookie" useless here
|
2019-02-07 09:27:56 +01:00
|
|
|
$req->steps( [
|
2019-12-16 23:21:43 +01:00
|
|
|
'getUser', 'authenticate',
|
2020-12-09 18:01:02 +01:00
|
|
|
@{ $self->p->betweenAuthAndData }, $self->p->sessionData,
|
2019-12-16 23:21:43 +01:00
|
|
|
@{ $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);
|
|
|
|
return $self->p->sendJSONresponse( $req, { result => 1 } );
|
2018-05-15 21:20:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|