New process skeleton
This commit is contained in:
parent
ce0f0d09c4
commit
055e4a7f0e
|
@ -10,9 +10,7 @@ use Mouse;
|
||||||
|
|
||||||
our $VERSION = '2.0.0';
|
our $VERSION = '2.0.0';
|
||||||
|
|
||||||
sub AuthnLevel {
|
extends Lemonldap::NG::Portal::Main::Auth;
|
||||||
return $_[0]->https ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
## @apmethod int authInit()
|
## @apmethod int authInit()
|
||||||
# Does nothing.
|
# Does nothing.
|
||||||
|
|
12
lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Auth.pm
Normal file
12
lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Auth.pm
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package Lemonldap::NG::Portal::Main::Auth;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Mouse;
|
||||||
|
|
||||||
|
our $VERSION = '2.0.0';
|
||||||
|
|
||||||
|
extends 'Lemonldap::NG::Portal::Main::Module';
|
||||||
|
|
||||||
|
has authnLevel => (is => 'rw');
|
||||||
|
|
||||||
|
1;
|
|
@ -27,17 +27,17 @@ has _authentication => ( is => 'rw' );
|
||||||
has _userDB => ( is => 'rw' );
|
has _userDB => ( is => 'rw' );
|
||||||
|
|
||||||
# Lists to store plugins entry-points
|
# Lists to store plugins entry-points
|
||||||
has beforeAuthProcess => (
|
has beforeAuth => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef',
|
isa => 'ArrayRef',
|
||||||
default => sub { [] }
|
default => sub { [] }
|
||||||
);
|
);
|
||||||
has addSessionData => (
|
has betweenAuthAndDatas => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef',
|
isa => 'ArrayRef',
|
||||||
default => sub { [] }
|
default => sub { [] }
|
||||||
);
|
);
|
||||||
has afterAuthProcess => (
|
has afterDatas => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'ArrayRef',
|
isa => 'ArrayRef',
|
||||||
default => sub { [] }
|
default => sub { [] }
|
||||||
|
@ -129,6 +129,8 @@ sub reloadConf {
|
||||||
unless ( $self->{"_$type"} = $self->loadModule($module)
|
unless ( $self->{"_$type"} = $self->loadModule($module)
|
||||||
and $self->{"_$type"}->init );
|
and $self->{"_$type"}->init );
|
||||||
}
|
}
|
||||||
|
$self->_authentication->authnLevel(
|
||||||
|
$self->conf->{ $self->conf->authentication . "AuthnLevel" } );
|
||||||
|
|
||||||
# Initialize trusted domain list
|
# Initialize trusted domain list
|
||||||
$self->conf->{trustedDomains} ||= "";
|
$self->conf->{trustedDomains} ||= "";
|
||||||
|
|
|
@ -49,6 +49,8 @@ sub enabledPlugins {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO: Password
|
||||||
|
|
||||||
# Check if custom plugins are required
|
# Check if custom plugins are required
|
||||||
if ( $self->conf->{plugins} ) {
|
if ( $self->conf->{plugins} ) {
|
||||||
$self->lmLog( 'Custom plugins: ' . $self->conf->{plugins}, 'debug' );
|
$self->lmLog( 'Custom plugins: ' . $self->conf->{plugins}, 'debug' );
|
||||||
|
|
|
@ -5,4 +5,11 @@ use Mouse;
|
||||||
|
|
||||||
extends 'Lemonldap::NG::Common::PSGI::Request';
|
extends 'Lemonldap::NG::Common::PSGI::Request';
|
||||||
|
|
||||||
|
has steps => ( is => 'rw' );
|
||||||
|
has error => ( is => 'rw' );
|
||||||
|
|
||||||
|
sub wantJSON {
|
||||||
|
return $_[0]->accept =~ m#(?:application|text)/json# ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -14,6 +14,7 @@ package Lemonldap::NG::Portal::Main::Run;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use Mouse;
|
use Mouse;
|
||||||
|
use Lemonldap::NG::Portal::Main::Constants;
|
||||||
use Lemonldap::NG::Portal::Main::Request;
|
use Lemonldap::NG::Portal::Main::Request;
|
||||||
|
|
||||||
our $VERSION = '2.0.0';
|
our $VERSION = '2.0.0';
|
||||||
|
@ -44,30 +45,76 @@ sub pleaseAuth {
|
||||||
|
|
||||||
# MAIN ENTRY POINTS
|
# MAIN ENTRY POINTS
|
||||||
|
|
||||||
|
# List constants
|
||||||
|
sub authProcess { qw(extractFormInfo getUser authenticate) }
|
||||||
|
|
||||||
|
sub sessionDatas {
|
||||||
|
qw(setAuthSessionInfo setSessionInfo setMacros setGroups
|
||||||
|
setPersistentSessionInfo setLocalGroups grantSession store
|
||||||
|
buildCookie);
|
||||||
|
}
|
||||||
|
|
||||||
sub login {
|
sub login {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
return $self->process(
|
return $req->do($req,
|
||||||
'rememberArgs', @{ $self->beforeAuthProcess },
|
[
|
||||||
@authProcess, @{ $self->addSessionData },
|
'rememberArgs', @{ $self->beforeAuth },
|
||||||
@sessionDatas, @{ $self->afterAuthProcess }
|
&authProcess, @{ $self->betweenAuthAndDatas },
|
||||||
|
&sessionDatas, @{ $self->afterdatas },
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub postLogin {
|
sub postLogin {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
return $self->process(
|
return $req->do($req,
|
||||||
@{ $self->beforeAuthProcess },
|
[
|
||||||
@authProcess, @{ $self->addSessionData },
|
'restoreArgs', @{ $self->beforeAuth },
|
||||||
@sessionDatas, @{ $self->afterAuthProcess }
|
&authProcess, @{ $self->betweenAuthAndDatas },
|
||||||
|
&sessionDatas, @{ $self->afterdatas },
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub authenticatedRequest {
|
sub authenticatedRequest {
|
||||||
|
my ( $self, $req ) = @_;
|
||||||
|
return $req->do($req, $self->forAuthUser );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub do {
|
||||||
|
my ($self,$req,$steps) = @_;
|
||||||
|
$req->steps($steps);
|
||||||
|
my $err = $self->process($req);
|
||||||
|
# TODO: updateStatus
|
||||||
|
if ( !$self->conf->{noAjaxHook} and $req->wantJSON ) {
|
||||||
|
if ( $err > 0 ) {
|
||||||
|
return [ 401, ['WWW-Authenticate' => "SSO ".$self->conf->{portal},'Access-Control-Allow-Origin' => '*'],[]];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $self->senfJSONresponse({result=>1,message=>'Authenticated'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if($err) {
|
||||||
|
return $self->sendHtml($req,'login.tpl');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $self->autoRedirect($req);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub process {
|
||||||
|
my ( $self, $req ) = @_;
|
||||||
|
#$req->error(PE_OK);
|
||||||
|
my $err = PE_OK;
|
||||||
|
while(my $sub = shift @{$req->steps}) {
|
||||||
|
last if($err = $self->$sub($req);
|
||||||
|
}
|
||||||
|
return $err;
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO in run
|
# TODO in run
|
||||||
# - mustRedirect
|
# - mustRedirect
|
||||||
# - store AuthnLevel in session (setSessionInfo)
|
|
||||||
# $self->{sessionInfo}->{authenticationLevel} = $self->_authentication->AuthnLevel
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user