lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Auth/SSL.pm

85 lines
2.0 KiB
Perl
Raw Normal View History

2016-08-05 13:56:16 +02:00
package Lemonldap::NG::Portal::Auth::SSL;
use strict;
use Mouse;
2017-04-11 21:19:59 +02:00
use Lemonldap::NG::Portal::Main::Constants qw(
2019-02-05 23:12:17 +01:00
PE_BADCERTIFICATE
PE_CERTIFICATEREQUIRED
PE_FIRSTACCESS
PE_OK
2017-04-11 21:19:59 +02:00
);
2016-08-05 13:56:16 +02:00
2019-02-12 18:21:38 +01:00
our $VERSION = '2.1.0';
2016-08-05 13:56:16 +02:00
2018-02-19 22:11:43 +01:00
extends 'Lemonldap::NG::Portal::Main::Auth';
2016-08-05 13:56:16 +02:00
# INITIALIZATION
2019-07-02 20:12:11 +02:00
has Name => ( is => 'ro', default => 'SSL' );
2019-02-02 17:34:44 +01:00
2016-08-05 13:56:16 +02:00
sub init {
2019-02-02 17:34:44 +01:00
my ($self) = @_;
2017-01-30 22:00:54 +01:00
return 1;
2016-08-05 13:56:16 +02:00
}
# Read username in SSL environment variables, or return an error
# @return Lemonldap::NG::Portal constant
sub extractFormInfo {
my ( $self, $req ) = @_;
my $field = $self->conf->{SSLVar};
2020-01-31 17:43:49 +01:00
if ( $req->env->{SSL_CLIENT_I_DN} ) {
$self->logger->debug(
2020-01-31 17:48:21 +01:00
'Received SSL issuer ' . $req->env->{SSL_CLIENT_I_DN} );
2020-01-31 17:43:49 +01:00
if ( my $tmp =
$self->conf->{SSLVarIf}->{ $req->env->{SSL_CLIENT_I_DN} } )
{
$field = $tmp;
}
2017-02-24 07:29:50 +01:00
}
2020-01-31 17:43:49 +01:00
$self->logger->debug("Using SSL environment variable $field");
2017-04-11 21:19:59 +02:00
if ( $req->user( $req->env->{$field} ) ) {
2019-02-05 23:12:17 +01:00
$self->userLogger->notice( "GoodSSL authentication for " . $req->user );
2017-04-11 21:19:59 +02:00
return PE_OK;
}
elsif ( $req->env->{SSL_CLIENT_S_DN} ) {
2017-02-24 07:29:50 +01:00
$self->userLogger->warn("$field was not found in user certificate");
2016-08-05 13:56:16 +02:00
return PE_BADCERTIFICATE;
}
2017-04-11 21:19:59 +02:00
elsif ( $self->conf->{sslByAjax} and not $req->param('nossl') ) {
$req->data->{waitingMessage} = 1;
2017-04-11 21:19:59 +02:00
return PE_FIRSTACCESS;
}
2016-08-05 13:56:16 +02:00
else {
if ( $self->conf->{sslByAjax} ) {
2019-02-05 23:12:17 +01:00
$self->logger->debug( 'Append ' . $self->{Name} . ' init/script' );
$self->logger->debug(
"Send init/script -> " . $req->data->{customScript} );
}
2017-04-11 21:19:59 +02:00
$self->userLogger->warn('No certificate found');
2016-08-05 13:56:16 +02:00
return PE_CERTIFICATEREQUIRED;
}
}
sub authenticate {
PE_OK;
}
2016-12-01 23:25:05 +01:00
sub setAuthSessionInfo {
my ( $self, $req ) = @_;
2019-04-05 22:58:48 +02:00
$req->sessionInfo->{authenticationLevel} = $self->conf->{SSLAuthnLevel};
2016-12-01 23:25:05 +01:00
PE_OK;
}
2019-03-19 05:56:36 +01:00
sub getForm {
2019-07-02 20:12:11 +02:00
my ( $self, $req ) = @_;
2019-03-19 05:56:36 +01:00
$req->tplParams->{SSLHOST} = $self->conf->{sslHost};
return "sslform";
2016-08-05 13:56:16 +02:00
}
sub authLogout {
PE_OK;
}
2016-08-05 13:56:16 +02:00
1;